Clear Filters
Clear Filters

GANs Model Loss Function not running

2 views (last 30 days)
Jullian Ducut
Jullian Ducut on 7 Sep 2022
Answered: Vidip Jain on 21 Feb 2023
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

Answers (1)

Vidip Jain
Vidip Jain on 21 Feb 2023
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”.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!