i have a problem with modelGradients

조회 수: 8 (최근 30일)
Hind Haboubi
Hind Haboubi 2021년 5월 4일
댓글: debojit sharma 2023년 6월 16일
When i run thus section :
for numEpoch = 1:nEpochs
reset(preprocessedTrainingData);% Reset datastore.
iteration = 0;
while hasdata(preprocessedTrainingData)
t_start = tic;
% Custom training loop.
% Read batch of data and create batch of images and
% ground truths.
outDataTable = read(preprocessedTrainingData);
XTrain = outDataTable{1,1}{1};
YTrain = outDataTable{1,2}{1};
if isempty(YTrain)
continue;
end
% Convert mini-batch of data to dlarray.
XTrain = dlarray(single(XTrain),'SSCB');
% Evaluate the model gradients and loss using dlfeval and the
% modelGradients function.
[gradients,boxLoss,objLoss,clsLoss,totalLoss,state] = dlfeval(@modelGradients, model, XTrain, YTrain,yoloLayerNumber);
I get this error :
'modelGradients' is used in Generate Synthetic Signals Using Conditional Generative Adversarial Network.
Error in deep.internal.dlfeval (line 18)
[varargout{1:nout}] = fun(x{:});
Error in dlfeval (line 41)
[varargout{1:nout}] = deep.internal.dlfeval(fun,varargin{:});
Error in nouveux (line 94)
[gradients,boxLoss,objLoss,clsLoss,totalLoss,state] = dlfeval(@modelGradients, model, XTrain,
YTrain,yoloLayerNumber);

채택된 답변

Arianna Pryor
Arianna Pryor 2021년 5월 12일
I got a similar error when trying to run the VAE example. I had to use another modelGradients function.
function [infGrad, genGrad] = modelGradients(encoderNet, decoderNet, x)
[z, zMean, zLogvar] = sampling(encoderNet, x);
xPred = sigmoid(forward(decoderNet, z));
loss = ELBOloss(x, xPred, zMean, zLogvar);
[genGrad, infGrad] = dlgradient(loss, decoderNet.Learnables, ...
encoderNet.Learnables);
end
  댓글 수: 1
debojit sharma
debojit sharma 2023년 6월 16일
I am also facing the same problem while trying to train VAE for RGB image. @Arianna Pryor Can you please kindly tell me in which part of the code have you used this modelGradients function?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mohamed Marei
Mohamed Marei 2021년 7월 26일
편집: Mohamed Marei 2021년 7월 26일
Because MATLAB sees both of these functions which share the same name on the path, it doesn't know which one to use for each example. Therefore, it may be better practice to copy the internals of this function into a different function (more appropriate for your example), i.e.
function [gradients, boxLoss, objLoss, clsLoss, totalLoss, state] = ...
yoloModelGradients(network, Xtrain, Ytrain, yoloLayerNumber)
% loss, gradients, and states definitions go here.
end
After that, replace the call to the old modelGradients function in your call to dlfeval:
% Evaluate the model gradients and loss using dlfeval and the
% yoloModelGradients function.
[gradients,boxLoss,objLoss,clsLoss,totalLoss,state] = dlfeval(@yoloModelGradients, model, XTrain, YTrain,yoloLayerNumber);
Hope you've managed to get it fixed since then!

카테고리

Help CenterFile Exchange에서 Deep Learning for Image Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by