Classify requires at least 3 arguments
조회 수: 27 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Walter Roberson
2018년 11월 1일
편집: Walter Roberson
2018년 11월 5일
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
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
2023년 8월 2일
추가 답변 (4개)
Walter Roberson
2020년 6월 2일
편집: Walter Roberson
2020년 12월 6일
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:
- SeriesNetwork CNN, Deep Learning Toolbox: https://www.mathworks.com/help/deeplearning/ref/seriesnetwork.html such as alexnet; https://www.mathworks.com/help/deeplearning/ref/classify.html
- DAGNetwork CNN, Deep Learning Toolbox: https://www.mathworks.com/help/deeplearning/ref/dagnetwork.html such as googlenet or resnet50; https://www.mathworks.com/help/deeplearning/ref/classify.html
- discrete-time markov chains, Econometics toolbox: https://www.mathworks.com/help/econ/dtmc.html ; https://www.mathworks.com/help/econ/dtmc.classify.html
- Numeric arrays (for discriminent analysis) and character arrays, Statistics and Machine Learning Toolbox: https://www.mathworks.com/help/stats/classify.html . This is the function that will get invoked for inputs other than the ones mentioned above, so errors about number of arguments or about datatypes not being numeric, will typically be from this function having been accidentally invoked.
classify() is not the correct function for some other cases:
- for patternnet(), Deep Learning Toolbox, use sim(); https://www.mathworks.com/help/deeplearning/ref/sim.html
- For KNN Classification, use knnclassify() from Bioinformationcs Toolbox for old releases, https://www.mathworks.com/help/releases/R2015a/bioinfo/ref/knnclassify.html
- For KNN Classifications, create a ClassificationKNN object, Statistics and Machine Learning Toolbox for newer releases, and use predict() https://www.mathworks.com/help/stats/classificationknn.predict.html
- For SVM classificaiton, use svmclassify() from Statistics and Machine Learning Toolbox for old releases, https://www.mathworks.com/help/releases/R2015a/stats/svmclassify.html
- For SVM classification, create an SVM Classifier object, Statistics and Machine Learning Toolbox for newer releases, https://www.mathworks.com/help/stats/fitcsvm.html and use predict() https://www.mathworks.com/help/stats/classreg.learning.classif.compactclassificationsvm.predict.html
- Microarray analysis, Bioinformatics Toolbox: use KNN classifiers predict(), and classify() from the Statistics and Machine Learning Toolbox; https://www.mathworks.com/help/releases/R2015a/bioinfo/ref/classperf.html
- for cross-validated classification trees, create a classification partitioned object, https://www.mathworks.com/help/stats/classreg.learning.partition.classificationpartitionedmodel-class.html using fitctree https://www.mathworks.com/help/stats/fitctree.html#bt6cr7t-tree and use kfoldPredict https://www.mathworks.com/help/stats/classificationpartitionedmodel.kfoldpredict.html
- for other kinds of classification trees, create a ClassificationTree or CompactClassificationTree https://www.mathworks.com/help/stats/classificationtree-class.html using fitctree https://www.mathworks.com/help/stats/fitctree.html#bt6cr7t-tree and use predict https://www.mathworks.com/help/stats/compactclassificationtree.predict.html
댓글 수: 4
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
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
2019년 1월 22일
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
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
You are probably accidentally invoking https://www.mathworks.com/help/stats/classify.html instead of https://www.mathworks.com/help/deeplearning/ref/classify.html
Muhammad Suri
2020년 9월 28일
yes I am accidentally invoking stats/classify vs ref/classify. How can I change that. Thanks
hana razak
2019년 2월 19일
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
Kinjal Joshi
2019년 12월 19일
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
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()
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!