Error running matlab convolutional network from c#

1 ビュー (過去 30 日間)
Manuel Rios
Manuel Rios 2017 年 1 月 4 日
コメント済み: Guillaume 2017 年 1 月 5 日
I am trying to develop a Xamarin mobile app for android that recognizes objects on images taken for the user, basically I already trained the CNN on matlab and the plan is to call it from a c# web service!.
I wrote this piece of code in a .m file , and I converted it into a .net assembly using the Matlab deploying tool.
function label = RedNeuronal()
load('E:xxxx\capa.mat');
load('E:xxxx\CNN.mat');
load('E:xxxx\SVM.mat');
newImage ='E:xxxxx\GatoBoyaca.jpg';
I = imread(newImage);
if ismatrix(I)
I = cat(3,I,I,I);
end
img = imresize(I, [227 227]);
imageFeatures = activations(convnet, img, featureLayer);
label = char(predict(classifier, imageFeatures));
end
As you can notice this code simply loads the CNN , the name of the feature layer and also a SVM, finally it preprocess the image and get the result using the predict command. If i run this .m fie from matlab it runs perfectly.
On the other hand, in c# I wrote this piece of code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using RedNeuronalComp;
namespace CargarDll
{
class Program
{
static void Main(string[] args)
{
MWArray SalidaCNN = null;
MLCnnClass CNN = new MLCnnClass();
SalidaCNN=CNN.RedNeuronal();
}
}
}
But Sadly this code gives me the following error:
It seems that it can not use the CNN , like if it would not have access to the toolbox or something. What should I do ?

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 1 月 5 日
I advise against using load() without an output parameter in a compiled module. You are relying upon variables being "poofed" into existence, which is something that the compiler can have difficulty in figuring out.
  6 件のコメント
Guillaume
Guillaume 2017 年 1 月 5 日
Note that the problem is not with C# per say, the error messages shown are not typical CLR error messages, so must come from the interface provided by matlab.
Like Walter, my first suspicion is that the load confuse matlab code generator which probably does not know where the variables come from and thus fail to include some necessary code. This is the first thing that I'd change. It's always good practice to load variables into a structure anyway (to avoid overwriting existing variables / functions).
There may be some other deeper issues like matlab coder not supporting some of the functions you're using. I wouldn't know, I do not have or have ever used matlab compiler SDK.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by