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

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

"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.
size(Y)
ans =
1 1
size(networkOutputs)
ans =
2 1
How do I fix this?

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

 채택된 답변

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

@Walter Roberson Ok, networkOutputs is 2x1 and predict returns a 1x1.
Any idea how to fix this? I'm following this tutorial.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 2월 3일

편집:

2021년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by