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

2 ビュー (過去 30 日間)
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 件のコメント
Stephen23
Stephen23 2021 年 2 月 3 日
編集済み: Stephen23 2021 年 2 月 3 日
"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 2021 年 2 月 3 日
編集済み: Asim Shahzad 2021 年 2 月 3 日
size(Y)
ans =
1 1
size(networkOutputs)
ans =
2 1
How do I fix this?

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 3 日
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 件のコメント
Asim Shahzad
Asim Shahzad 2021 年 2 月 3 日
編集済み: Asim Shahzad 2021 年 2 月 3 日
@Walter Roberson Ok, networkOutputs is 2x1 and predict returns a 1x1.
Any idea how to fix this? I'm following this tutorial.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by