MATLAB Answers

0

.NET assembly in c# not working properly

Asked by Suleman Qamar on 5 Oct 2018
Latest activity Answered by Kojiro Saito on 5 Oct 2018
Hi i am working on a classification project, wrote functions for training network and using it to classify new images in matlab. everything worked fine. then i created a GUI in c# because it was prettier that way.
at first, i used MLApp to create matlab instance and call all matlab functions using it, this worked great without any error. but now i need to deploy the solution to another computer with no matlab installation. so i googled and found out about .NET assemblies, tested simple functions like sum and and product, it is working. but when i created .NET assembly for my classification functions, there are errors like the matlab function which classifies gives error at following line saying it needs 3 arguments, although it is working well from both matlab environment and from c# where i am using matlab instance.
label=classify(net,img);
this is how i called the function from c#
MWArray[] result = null;
// create classify class object
classifyClass classifyObj = new classifyClass();
// Call the MATLAB function
string netPath = textBox1.Text;
string imagePath = textBox2.Text;
result = classifyObj.classifyImg(1, netPath, imagePath);
i was wondering if there was a way to create matlab instance without its full installation, that way i won't need to use assembly, if not any other solution/suggestion is very welcome i urgently need to solve this, thank you.

  0 Comments

Sign in to comment.

1 Answer

Answer by Kojiro Saito on 5 Oct 2018

Do you want to use "classify" in Neural Network Toolbox (from R2018b, its name is changed to Deep Learning Toolbox)?
There are three "classify" functions in MATLAB: Statistics and Machine Learning Toolbox, Deep Learning Toolbox and Econometrics Toolbox. In MATLAB desktop, MATLAB knows which functions to be called from input. If the input of classify is SeriesNetwork, classify will call the function in Deep Learning Toolbox. In your error message "it needs 3 arguments" is derived from classify in Statistics and Machine Learning Toolbox.
To make the deployed dll know classify is that of Deep Learning, I think there are two ways.
  1. Add a mat file of deep learning network (for example, net.mat of AlexNet) in your dll by adding the mat file in "Files required for your library to run" of compiler window.
  2. Forcibly use "SeriesNetwork.loadobj" when loading network mat file
function predictedLabel = classifyImg(netFilePath, imageFilePath)
net = load(netFilePath);
net = SeriesNetwork.loadobj(net.net);
frame = imread(imageFilePath);
frame1 = imresize(frame, [227 227]);
[YPred,scores] = classify(net, frame1);
predictedLabel = char(YPred);
end
I've tested these two ways in R2018b and both worked.

  0 Comments

Sign in to comment.