Classify requires at least 3 arguments

130 views (last 30 days)
Hi,
I am having trouble when trying to use the "classify" function to evaluate the performance of my neural network.
I am using the following code:
net = load('mynet.mat'); %this returns my previsouly trained SeriesNetwork object
test_folder = './test_data';
test_images = imageDatastore(test_folder,'FileExtensions','.jpg');
[Y,scores] = classify(net,test_images);
But the classify function throws me an error that it requires at least 3 arguments, which means it is trying to use the classify function from the statistics package.
What can I make do force the use of the classify from the deep learning package?
Thanks,
Raphael

Accepted Answer

Walter Roberson
Walter Roberson on 1 Nov 2018
Edited: Walter Roberson on 5 Nov 2018
net = load('mynet.mat'); %this returns my previsouly trained SeriesNetwork object
Not exactly. The output of load applied to a mat file, is a struct that has one field for each variable loaded. So you would need net.net where the first net is the struct returned from load and the second is the variable loaded.
  10 Comments
Walter Roberson
Walter Roberson on 14 Jun 2022
At the point that the error occurs what is class(app.net) and class(imgRes) ? Also what is size(imgRes) there?

Sign in to comment.

More Answers (4)

Walter Roberson
Walter Roberson on 2 Jun 2020
Edited: Walter Roberson on 6 Dec 2020
There are multiple functions named classify()
Most of the classify() routines are methods of particular data type, and will only be considered to be invoked if the first input argument is an object of the proper data type.
The only classify() that accepts general input arguments (rather than objects) is classify() from the Statistics and Machine Learning Toolbox. That classify() happens to require at least 3 input arguments, so if you get an unexpected error message about classify requiring at least three input arguments, then you have accidentally invoked the classify() from the Statistics and Machine Learning Toolbox, and the cause of the problem is that your first parameter is not a proper member of the datatype that your desired function acts upon.
For example you might have accidentally provided the name of a dataset (as a character vector), or you might have accidentally provided a datastore, or you might have accidentally provided a description of a deep learning network instead of a trained instance of the network.
classify() can be used with:
classify() is not the correct function for some other cases:
  4 Comments
Walter Roberson
Walter Roberson on 17 Nov 2022
Try
%#function DAGNetwork
as a comment in your code. The compiler will recognize it and know to include the DAGNetwork class.

Sign in to comment.


Alaa ElDin ElHilaly
Alaa ElDin ElHilaly on 22 Jan 2019
I face the same problem. would you please elaborate more about your suggested solution. I have trained the network and keeps giving me (required at least 3 arguments)
  2 Comments
Muhammad Suri
Muhammad Suri on 28 Sep 2020
yes I am accidentally invoking stats/classify vs ref/classify. How can I change that. Thanks

Sign in to comment.


hana razak
hana razak on 19 Feb 2019
Hi,
Me too. I've got same ERROR when using webcam to classify the fast RCNN
camera = videoinput('winvideo', 2, 'MJPG_1024x576');
net = load('detector200.mat');
while true
picture = getsnapshot(camera);
picture = imresize(picture,[150,150]);
label = classify(net, picture);
image(picture);
title(char(label));
drawnow;
end
Here are the errors,
Error using classify (line 123)
Requires at least three arguments.
Error in webcam_object_classification (line 7)
label = classify(net, picture);
I've tried net.net as suggested in command window and it showed this,
>> net.detector200
ans =
fasterRCNNObjectDetector with properties:
ModelName: 'normal'
Network: [1×1 vision.cnn.FastRCNN]
RegionProposalNetwork: [1×1 vision.cnn.RegionProposalNetwork]
MinBoxSizes: [39 30]
BoxPyramidScale: 1.2000
NumBoxPyramidLevels: 14
ClassNames: {'normal' 'abnormal' 'Background'}
MinObjectSize: [18 18]
BUT I don't know how to use it in the code.
Any help would be greatly appreciated.
Thank you so much
  2 Comments
hana razak
hana razak on 20 Feb 2019
It didn't work. I got the same error.
Is there any other solution?
Thank you

Sign in to comment.


Kinjal Joshi
Kinjal Joshi on 19 Dec 2019
net=patternnet(10);
[net,tr]=train(net,trainoflow,op);
[ypred,scores]=classify(net,testoflow);
The above code give me error at classify function that Requires atleast three arguments. trainoflow is training features,testoflow is testdata features and op is train data labels.
  1 Comment
Walter Roberson
Walter Roberson on 19 Dec 2019
patternnet() does not support a classify() function. To invoke the network on testoflow, use it by name:
ypred = net(testoflow);
to get scores, you might want to use perform()

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!