How to specify toolbox for function call
14 ビュー (過去 30 日間)
古いコメントを表示
In a scenario where Matlab has functions with the same name in multiple toolboxes, how do I specify the specific toolbox I want it to use?
Here are the details of my specific problem: I have implemented an LSTM Neural Network and am using it to perform classification. The neural network toolbox includes a classify() function which I am trying to use. Unfortunately, the statistics and machine learning toolbox also has a classify() function, but which takes different arguments. I have both of these toolboxes installed. As a result, I am getting the following error:
K>> predictedY = classify(lstmModel, X);
Error using classify (line 123)
Requires at least three arguments.
In the above snippet, lstmModel is a trained neural network I have loaded from a mat file and X is the data I wish to classify. The neural network toolbox version of classify() does specify that it should work with these two arguments.
From what I can tell, Matalb is calling the classify function from the wrong toolbox. How do I specify the specific toolbox I want it to use?
2 件のコメント
Greg
2018 年 3 月 22 日
Typically, TheMathWorks is pretty good about shadowing, and it knows how to call the correct one based on the class of the input variable. The documentation for classify in Neural Network says input 1 must be a SeriesNetwork or DAGNetwork object, are you certain your lstmModel input is of that class?
回答 (1 件)
Maksym Tymchenko
2023 年 11 月 2 日
This is a very good question that can be generalized to many similar situations.
First of all, you can check all the versions of the "classify" function that can be found on your MATLAB path by executing the following command:
which -all classify
As you can see there are several options.
You can check the syntax for each option by using "help", for example:
help("/MATLAB/toolbox/nnet/cnn/@DAGNetwork/classify.m")
MATLAB is smart enough to call the correct version of classify by looking at the class of the input.
For example, if the variable "net" is of class "DAGNetwork", then the DAGNetwork method version of classify should be called:
net = shufflenet;
class(net)
inputSize = net.Layers(1).InputSize;
X = 100*ones(inputSize);
classify(net, X)
You can see that the DAGNetwork version of classify has been called successfully.
Alternatively, because the DAGNetwork version of classify is a class method, you can also enforce it to be called by using the method syntax:
net.classify(X)
If after following these steps you still encounter the same error, this is probably because the DAGNetwork version of classify is not on your MATLAB path. To fix this, make sure that the Deep Learning Toolbox is installed and try executing "rehash toolboxcache".
1 件のコメント
Steven Lord
2023 年 11 月 2 日
In addition, if you call the which function with a function call as the "name" to display information about, MATLAB will take the variables you pass into that call into account when determining which overload of the function is called.
For example, a few classes define their own version of the sine function sin.
which -all sin
If I create a sym object I can confirm that when I call sin on that object the method in toolbox/symbolic/symbolic/@sym is called.
two = sym(2);
which -all sin(two)
But if I try to ask the same thing for a class that doesn't define sin it will tell me that fact.
f = figure;
class(f) % This doesn't appear in the first list above
which -all sin(f)
参考
カテゴリ
Help Center および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!