GANs Model Loss Function not running

2 visualizaciones (últimos 30 días)
Jullian Ducut
Jullian Ducut el 7 de Sept. de 2022
Respondida: Vidip Jain el 21 de Feb. de 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

Respuestas (1)

Vidip Jain
Vidip Jain el 21 de Feb. de 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”.

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by