GANs Model Loss Function not running

2 次查看(过去 30 天)
I tried to run the GAN programby MATLAB(https://www.mathworks.com/help/deeplearning/ug/train-generative-adversarial-network.html). I can run other programs prior to the Model Loss Function. When I tried to run the Model Loss function section, I cant click the Run button.
function [lossG,lossD,gradientsG,gradientsD,stateG,scoreG,scoreD] = ...
modelLoss(netG,netD,X,Z,flipProb)
% Calculate the predictions for real data with the discriminator network.
YReal = forward(netD,X);
% Calculate the predictions for generated data with the discriminator
% network.
[XGenerated,stateG] = forward(netG,Z);
YGenerated = forward(netD,XGenerated);
% Calculate the score of the discriminator.
scoreD = (mean(YReal) + mean(1-YGenerated)) / 2;
% Calculate the score of the generator.
scoreG = mean(YGenerated);
% Randomly flip the labels of the real images.
numObservations = size(YReal,4);
idx = rand(1,numObservations) < flipProb;
YReal(:,:,:,idx) = 1 - YReal(:,:,:,idx);
% Calculate the GAN loss.
[lossG, lossD] = ganLoss(YReal,YGenerated);
% For each network, calculate the gradients with respect to the loss.
gradientsG = dlgradient(lossG,netG.Learnables,RetainData=true);
gradientsD = dlgradient(lossD,netD.Learnables);
end

回答(1 个)

Vidip Jain
Vidip Jain 2023-2-21
Hi Jullian, I tried to reproduce the error but I was unable to run the file. Possible reason for this could be that you have not saved the file with appropriate extension or there is a program already running.
Also there was an error in line 4, you have passed incorrect number of arguments for the function name “forward”.

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by