Effacer les filtres
Effacer les filtres

MATLAB error referring to a function output variable that doesn't exist in the function

15 vues (au cours des 30 derniers jours)
I'm getting this error
Output argument "varargout{2}" (and maybe others) not assigned during call to "DAGNetwork/predict".
when accessing the function predict in the code below
function YPredCell = yolov3Predict(net,XTrain,networkOutputs,anchorBoxMask)
% Predict the output of network and extract the confidence, x, y,
% width, height, and class.
YPredictions = cell(size(networkOutputs));
[YPredictions{:}] = predict(net, XTrain);
YPredCell = extractPredictions(YPredictions, anchorBoxMask);
% Apply activation to the predicted cell array.
YPredCell = applyActivations(YPredCell);
end
Here is the function predict. It has no varargout{2}.
function varargout = predict(this, varargin)
% predict Make predictions on data with network
if this.NumInputLayers == 1
% Network has one input
X = varargin{1};
nameValuePairs = varargin(2:end);
elseif iDataForMultipleInputNetworkPassedAsOneArgument(nargin-1, varargin) && ...
iIsCombinedOrTransformedDatastore(varargin)
% Network has multiple inputs, but the inputs are passed in as one
% argument.
X = varargin{1};
nameValuePairs = varargin(2:end);
elseif iDataForMultipleInputNetworkPassedAsMultipleArguments(nargin-1, varargin, this.NumInputLayers)
% Network has multiple inputs, and the inputs are passed in as multiple
% arguments.
X = varargin(1:this.NumInputLayers);
nameValuePairs = varargin((this.NumInputLayers+1):end);
else
error( message( 'nnet_cnn:DAGNetwork:InvalidPredictDataForMultipleInputNetwork', this.NumInputLayers) );
end
[options, executionEnvironment, acceleration, returnCategorical] = ...
this.parseAndValidatePredictNameValuePairs( nameValuePairs{:} );
% Calculate predictions
try
Y = this.calculatePredict( ...
X, options, executionEnvironment, acceleration );
catch ex
throw(ex);
end
% Convert outputs to categorical if necessary
if returnCategorical
privateNetwork = this.PrivateNetwork;
numOutputs = privateNetwork.NumOutputs;
for i = 1:numOutputs
outputLayer = privateNetwork.OutputLayers{i};
if iIsClassificationOutputLayer(outputLayer)
if ~this.NetworkInfo.LayerHasSequenceOutput( ...
privateNetwork.OutputLayerIndices(i) )
Y{i} = iUndummify(Y{i}, outputLayer.Categories);
else
Y{i} = iUndummifySequence(Y{i}, outputLayer.Categories);
end
end
end
end
varargout = Y;
end
Why am I getting the mentioned error when my function doesn't have the output argument?
  2 commentaires
Stephen23
Stephen23 le 3 Fév 2021
Modifié(e) : Stephen23 le 3 Fév 2021
"It has no varargout{2}."
Actually that depends entirely on the size of Y, which so far you have not told us.
Please show us the values of:
size(networkOutputs)
size(Y) % just before the function returns.
Asim Shahzad
Asim Shahzad le 3 Fév 2021
Modifié(e) : Asim Shahzad le 3 Fév 2021
size(Y)
ans =
1 1
size(networkOutputs)
ans =
2 1
How do I fix this?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Fév 2021
YPredictions = cell(size(networkOutputs));
if network outputs passed in has size 2 or more then YPredictions will be a cell with two elements or more.
[YPredictions{:}] = predict(net, XTrain);
The left hand side is cell expansion and tells matlab that predict needs to return as many outputs as there are cell elements of YPredictions.
But your predict function only returns one output. And that is a problem if network outputs is size 2 or more.
  1 commentaire
Asim Shahzad
Asim Shahzad le 3 Fév 2021
Modifié(e) : Asim Shahzad le 3 Fév 2021
@Walter Roberson Ok, networkOutputs is 2x1 and predict returns a 1x1.
Any idea how to fix this? I'm following this tutorial.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by