Classification code R2016a, will not compile

I am trying to compile a simple example using bag of features with SVM. The compiler runs but the resulting executable gives the following error:
Undefined function 'predict' for input arguments of type 'single'.
Error in imageCategoryClassifier/predictImage (line 541)
Error in imageCategoryClassifier/predict (line 177)
Sample Code :
function test()
disp('This script takes a user defined image and runs it through a classifier. The output of the function is printed to screen')
x = load('model.mat');
[labelIdx,scores] = classifyListbox(x.img, x.categoryClassifier);
disp([labelIdx,scores])
function [labelIdx,scores] = classifyListbox(image,categoryClassifier)
[labelIdx, scores] = predict(categoryClassifier, image);
return

3 comentarios

Swarooph
Swarooph el 2 de Ag. de 2016
How do you generate the input to the predict function?
Looks like predict wants categoryClassifier to be of type imageCategoryClassifier . You can type the following command to see if it returns imageCategoryClassifier or single.
class(categoryClassifier)
Greg
Greg el 19 de Abr. de 2017
Editada: Greg el 19 de Abr. de 2017
I'm having a similar issue with predict and fitcnb. Even if I force mcc to include the needed toolboxes (with the -a tag) they're excluded. I haven't found a solution yet.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 2 de Ag. de 2016

0 votos

image is a built in function. You should not name your variables or dummy variables that.
Also, I fixed your formatting, but here is how you can do it yourself next time: http://www.mathworks.com/matlabcentral/answers/13205#answer_18099
Check your mccExcluded.log file to see if predict is allowed to be compiled.

2 comentarios

Michael
Michael el 3 de Ag. de 2016
Editada: Walter Roberson el 3 de Ag. de 2016
Thanks for the input. I tried the run the exe, and get errors in the imageCategoryClassifier methods:
Undefined function 'predict' for input arguments of type 'single'.
Error in imageCategoryClassifier/predictImage (line 541)
Error in imageCategoryClassifier/predict (line 177)
Error in imageCategoryClassifier/getPredictionOutputClasses (line 551)
Error in imageCategoryClassifier/predict (line 150)
Error in test_classifier (line 14)
MATLAB:UndefinedFunction
-----------------------------------------
The "mccExcluded.log" file has 4 exclusions:
The List of Excluded Files
Excluded files Exclusion Message ID Reason For Exclusion Exclusion Rule
C:/Program Files/MATLAB/R2016a-network/toolbox/local/+matlab/+internal/+toolboxes/addInstalledToolboxesToPath.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. [Cc]:/Program Files/MATLAB/R2016a-network/toolbox/local/[+]matlab/[+]internal/[+]toolboxes/addInstalledToolboxesToPath[.]m
C:/Program Files/MATLAB/R2016a-network/toolbox/local/+matlab/+internal/+zipAddOns/addInstalledZipAddOnsToPath.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. [Cc]:/Program Files/MATLAB/R2016a-network/toolbox/local/[+]matlab/[+]internal/[+]zipAddOns/addInstalledZipAddOnsToPath[.]m
C:/Program Files/MATLAB/R2016a-network/toolbox/local/pathdef.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. [Cc]:/Program Files/MATLAB/R2016a-network/toolbox/local/pathdef[.]m
C:/Program Files/MATLAB/R2016a-network/toolbox/matlab/codetools/initdesktoputils.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. [Cc]:/Program Files/MATLAB/R2016a-network/toolbox/matlab/codetools
Mike
Image Analyst
Image Analyst el 3 de Ag. de 2016
Well it looks like it's excluding things. I don't know why. It would be worth asking the Mathworks.

Iniciar sesión para comentar.

Steven Lord
Steven Lord el 4 de Ag. de 2016

0 votos

There's nothing in your code that MATLAB Compiler can statically analyze and determine it needs to include the imageCategoryClassifier class (in particular its constructor and its predict method) from Computer Vision System Toolbox in your application.
I believe "helping" MATLAB Compiler by telling it that it needs to include imageCategoryClassifier will work. Try using the technique described in this Answer to do that.

1 comentario

Michael
Michael el 4 de Ag. de 2016
Steve-
Thanks for the response.
I added the following to my script.
%#imageCategoryClassifier.m
%#predict
The first is a constructor and second is a method. I still get an error when running the executable:
Undefined function 'predict' for input arguments of type 'single'.
Error in imageCategoryClassifier/predictImage (line 541)
Error in imageCategoryClassifier/predict (line 177)
Error in imageCategoryClassifier/getPredictionOutputClasses (line 551)
Error in imageCategoryClassifier/predict (line 150)
Am I specifying the method directive correctly? Mike

Iniciar sesión para comentar.

Preguntada:

el 2 de Ag. de 2016

Editada:

el 19 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by