MATLAB error referring to a function output variable that doesn't exist in the function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Asim Shahzad
am 3 Feb. 2021
Bearbeitet: Asim Shahzad
am 3 Feb. 2021
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Feb. 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 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!