Classify requires at least 3 arguments

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

 採用された回答

Walter Roberson
Walter Roberson 2018 年 11 月 1 日
編集済み: Walter Roberson 2018 年 11 月 5 日

1 投票

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.

12 件のコメント

Raphael Ruschel
Raphael Ruschel 2018 年 11 月 1 日
That was indeed the case! I can't believe I let that simple mistake pass unnoticed. Thank you so much!
xie shipley
xie shipley 2019 年 1 月 28 日
Hi Walter:
I got the same ERROR: ‘ERROR using classify, Requires at least three arguments’
while using
net =importKerasLayers(modelfile,...
'ImportWeights',true,...
'WeightsFile',weightfile,...
'OutputLayerType','Classification')
%net input size is (29,13,1)
input=zeros(29,13)
predict=classify(net, input)
Could you give me some advice?
Walter Roberson
Walter Roberson 2019 年 1 月 28 日
Keras layers are not a trained network . They are more instructions on how to train a network . You need to pass an imagestore and the layers to trainNetwork to create a net to use with classify.
Laura Alonso Gómez
Laura Alonso Gómez 2020 年 6 月 2 日
net = '/Users/mAlexNet_on_UFPR04';
[YPred, scores] = classify(net, imds);
Yimds = imds.Labels;
accuracy = sum(YPred == Yimds)/numel(Yimds)
Hi Walter:
net is the trained net and imds is the database.I dont know why it keeps me saying ‘ERROR using classify, Requires at least three arguments’
I'd apreciate some help please.
Thank you very much
Walter Roberson
Walter Roberson 2020 年 6 月 2 日
Your net variable is a character vector not a network.
Laura Alonso Gómez
Laura Alonso Gómez 2020 年 6 月 3 日
thank you!
Fatin Nasuha Bt Asrol
Fatin Nasuha Bt Asrol 2022 年 6 月 13 日
Hi Walter:
I also got the same ERROR: ‘ERROR using classify, Requires at least three arguments’ while using app designer. Could you give me some suggestions how to solve it. Thank you very much.
Walter Roberson
Walter Roberson 2022 年 6 月 13 日
You are invoking classify() with an image as the first parameter, not an object. The only classify() that accepts a numeric array as the first parameter is the one from the Statistics and Machine Learning Toolbox, which requires at least three parameters. That classify() function does not expect to be passed any neural network.
I would suggest to you that your app.net should be the first parameter, not the second parameter.
Fatin Nasuha Bt Asrol
Fatin Nasuha Bt Asrol 2022 年 6 月 14 日
編集済み: Fatin Nasuha Bt Asrol 2022 年 6 月 14 日
@Walter Roberson Thank you for reply. I already tried your suggestion but it did not worked in my case. Do you have any others suggestion?will much appreciated if you can assist me on this.Thank you.
This is my code with error:
Walter Roberson
Walter Roberson 2022 年 6 月 14 日
At the point that the error occurs what is class(app.net) and class(imgRes) ? Also what is size(imgRes) there?
Moh. Saadat
Moh. Saadat 2023 年 8 月 2 日
Hi Walter,
I was trying to figure out whether using the layerGraph() function on a DAGNetwork (trained model) removes the trained weights. So I loaded my trained model which is a DAGNetwork:
load(RESTORE_CKPT); % RESTORE_CKPT is the full path to the mat file containing my trained network
Then, I used layerGraph() function to convert the DAGNetwork to a layer graph:
net = layerGraph(net);
But then, I use classify to infer the results, it throws me this 'requires at least 3 arguments' error:
[pred,score] = classify(net,data); % data is a cell array
Does this mean the weights have been removed from net?
Walter Roberson
Walter Roberson 2023 年 8 月 2 日
At the point of the error, what shows up for
class(net)

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

その他の回答 (4 件)

Walter Roberson
Walter Roberson 2020 年 6 月 2 日
編集済み: Walter Roberson 2020 年 12 月 6 日

1 投票

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 件のコメント

Yushan Zhang
Yushan Zhang 2022 年 11 月 16 日
Hi Walter,
I have a similar error code when I am tring to use the matlab complier runtime. I have read your answers but I did not figure it out.
line 13 : load ( .mat,'trained_net')
line 14 trained_net
line 15 [labe, scores] = classify(trained_net,imagexx)
The codes ran correctly on matlab(my laptop), but the error code "Requires at least three arguments error in => line 15" poped up on the .exe (Runtime was already installed on end-user's computer).
Could you please give me some suggestions?
Thank you,
Yushan
Walter Roberson
Walter Roberson 2022 年 11 月 17 日
That problem can occur if there are only indirect references to a function, especially if a function is only called by name through a character vector. For example, in MATLAB it is legal to call
ode45('MyOde', tspan, ic)
but if you were to do that then the compiler would not recognize that you are referring to function MyOde and so would not know to compiler it in.
The work-arounds for that kind of problem:
  • avoid using functions named by character vectors, converting them to @ function handle references instead whenever possible; or
  • use the %#function pragma https://www.mathworks.com/help/compiler/function.html to tell the compiler to include a reference to the given function; or
  • tell the compiler to specifically include the functions you need
What shows up for class(trained_net) ?
Yushan Zhang
Yushan Zhang 2022 年 11 月 17 日
Hi Walter,
Thanks for your quick support.
trained_net is a DAGNetwork.
I am trying to combine my Matlab codes with Labview. At first, I tired to use NET.dll. However, compiler sdk needs to be paid extra. Then, I am trying standalone application and now I have this problem. I have codes for object detection using yolov4 and image classification, they all have similar probelms when compiling the application.
Walter Roberson
Walter Roberson 2022 年 11 月 17 日
Try
%#function DAGNetwork
as a comment in your code. The compiler will recognize it and know to include the DAGNetwork class.

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

Alaa ElDin ElHilaly
Alaa ElDin ElHilaly 2019 年 1 月 22 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2019 年 1 月 22 日
When you load() a .mat file and you assign to output, the output is not directly any of the variables saved in the .mat file. Instead the output is a struct with one field for each variable loaded from the .mat file. For example if the .mat file contained the variables 'puppy' and 'butterfly', then
net = load('mynet.mat');
is not going to directly store puppy or butterfly in net, and it is not going to store into variables named puppy and butterfly in the environment of the function. Instead net would become a struct with fields named puppy and butterfly and net.puppy would hold whatever was in the puppy variable in mynet.mat
Muhammad Suri
Muhammad Suri 2020 年 9 月 28 日
yes I am accidentally invoking stats/classify vs ref/classify. How can I change that. Thanks

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

hana razak
hana razak 2019 年 2 月 19 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2019 年 2 月 19 日
label = classify(net.detector200, picture);
hana razak
hana razak 2019 年 2 月 20 日
It didn't work. I got the same error.
Is there any other solution?
Thank you

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

Kinjal Joshi
Kinjal Joshi 2019 年 12 月 19 日

0 投票

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 件のコメント

Walter Roberson
Walter Roberson 2019 年 12 月 19 日
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()

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

カテゴリ

ヘルプ センター および File ExchangeAI for Signals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by