GANs Model Loss Function not running

2 ビュー (過去 30 日間)
Jullian Ducut
Jullian Ducut 2022 年 9 月 7 日
回答済み: Vidip Jain 2023 年 2 月 21 日
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 Center および File ExchangeSequence 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