.NET assembly in c# not working properly

4 visualizzazioni (ultimi 30 giorni)
Suleman Qamar
Suleman Qamar il 5 Ott 2018
Risposto: Kojiro Saito il 5 Ott 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.

Risposte (1)

Kojiro Saito
Kojiro Saito il 5 Ott 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.

Categorie

Scopri di più su Containers in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by