MATLAB error referring to a function output variable that doesn't exist in the function
8 次查看(过去 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 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!