I trained a neural network in the Matlab "Neural Net Pattern Recognition" toolbox and generated a .m function from the toolbox. I also wrote my own function, which gets a dataset containing a inf x 5 matrix with datapoints as input, calls the NN function from the toolbox and returns a vector with the recognized pattern and a percent value. (the input matrix contains the pattern, which should be detected)
Because I need to run the code on an Arduino, I tried to use the Matlab Coder to generate C++ Code but it doesn't work. First, I get the warning that arrayfun is not supported for code generation (the call os arrayfun is in the generated function from the toolbox). After that, I defined the input of the function as " double(:7351 x 5)" (it's up to 7351 because my dataset for training is that big). Now the coder builds an MEX file for checking for run-time issues and there some errors occur.
I don't know why the target build log is in german because the rest of Matlab is in English but in generally some brackets and semicolons are missing but why? How can brackets be missing in the matrix.h or amlrt.h???
1 cl /c /Zp8 /GR /W3 /EHs /nologo /MD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE /O2 /Oy- /DNDEBUG /fp:strict /I "C:PROGRA~1MATLABR2016asimulinkinclude" /I "C:PROGRA~1MATLABR2016atoolboxsharedsimtargets" /I "C:UsersKaiDesktopYUN_SI~1" /I "C:UsersKaiDesktopYUN_SI~1codegenmexNeuralNetwork" /I ".interface" /I "C:PROGRA~1MATLABR2016aexterninclude" /I "." "NeuralNetwork_data.c"
2 NeuralNetwork_data.c
3 c:program filesmatlabr2016aexternincludematrix.h(260) : error C2061: Syntaxfehler: Bezeichner 'mxChar'
4 c:program filesmatlabr2016aexternincludematrix.h(260) : error C2059: Syntaxfehler: ';'
5 c:program filesmatlabr2016aexternincludematrix.h(605) : error C2143: Syntaxfehler: Es fehlt '{' vor '*'
6 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(56) : error C2143: Syntaxfehler: Es fehlt ')' vor '*'
7 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(56) : error C2143: Syntaxfehler: Es fehlt '{' vor '*'
8 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(56) : error C2373: 'emlrtCTX': Neudefinition; unterschiedliche Modifizierer
9 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(50): Siehe Deklaration von 'emlrtCTX'
10 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(56) : error C2146: Syntaxfehler: Fehlendes ';' vor Bezeichner 'aTLS'
11 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(56) : error C2059: Syntaxfehler: ')'
12 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(133) : error C2061: Syntaxfehler: Bezeichner 'EmlrtErrorFunction'
13 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(139) : error C2059: Syntaxfehler: '}'
14 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(194) : error C2061: Syntaxfehler: Bezeichner 'emlrtContextGlobal'
15 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(194) : error C2059: Syntaxfehler: ';'
16 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(808) : error C2143: Syntaxfehler: Es fehlt ')' vor '*'
17 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(808) : error C2143: Syntaxfehler: Es fehlt '{' vor '*'
18 C:PROGRA~1MATLABR2016aexternincludeemlrt.h(808) : error C2059: Syntaxfehler: ')'
19 c:userskaidesktopyun_simulinkcodegenmexneuralnetworkNeuralNetwork_data.h(32) : error C2061: Syntaxfehler: Bezeichner 'emlrtContextGlobal'
20 c:userskaidesktopyun_simulinkcodegenmexneuralnetworkNeuralNetwork_data.h(32) : error C2059: Syntaxfehler: ';'
21 NeuralNetwork_data.c(22) : error C2061: Syntaxfehler: Bezeichner 'emlrtContextGlobal'
22 NeuralNetwork_data.c(22) : error C2059: Syntaxfehler: ';'
23 NeuralNetwork_data.c(22) : error C2513: '/*global*/ ': Keine Variable vor '=' deklariert
24 gmake: *** [NeuralNetwork_data.obj] Error 2
In general, it is possible to create C++ code from the NN toolbox but why doesn't it work in my case?
The function I want to translate in c++ is:
function [ activity, percent ] = NeuralNetwork( Data )
%NN for recogniton of activitys standing, sitting, walking from Accelerometer data, relative error
%is returned in percent
% input Data contains 5 columns. 1. col -> time; 2-4.col ->
% x,y,z-Acceleration; 5.col -> activity
% VAR activity contains 1 for walking, 2 for sitting and 3 for standing
Acceleration_data = Data(:,2:4); %store acceleration data in a matrix
Acceleration_data = Acceleration_data'; %NN input expects transposed matrix
targets = Data(:,5); %activity that should be detected from the NN
targets = targets'; %output of NN is also transposed
NNfit = myNeuralNetworkFunction(Acceleration_data); %call the trained NN
NNfit = round(NNfit); %output can be e.g. 0.998 -> round to 1
activity=zeros(1,length(NNfit)); %allocate memory for cpp-code
for i=1:length(NNfit) %NNfit is a 3D matrix, after round one
[val pos] = max(NNfit(:,i)); %element is 1 the other are 0 the number of
%the row represents the activity
activity(i) = pos; %vektor containing the activity
end
cnt=0; %calc percent of correct recognized data points
for i=1:length(NNfit)
if activity(i) == targets(i)
cnt = cnt+1; %amound of correct recognized data points
end
end
percent = (cnt/length(targets))*100; %calc percent
end
edit:
The file NeuralNetwork_data.c:
/* Include files */
#include "rt_nonfinite.h"
#include "NeuralNetwork.h"
#include "NeuralNetwork_data.h"
#include "blas.h"
/* Variable Definitions */
emlrtCTX emlrtRootTLSGlobal = NULL;
const volatile char_T *emlrtBreakCheckR2012bFlagVar = NULL;
covrtInstance emlrtCoverageInstance;
emlrtContext emlrtContextGlobal = { true, false, 131434U, NULL, "NeuralNetwork",
NULL, false, { 2045744189U, 2170104910U, 2743257031U, 4284093946U }, NULL };
emlrtRSInfo f_emlrtRSI = { 68, "eml_mtimes_helper",
"C:\Program Files\MATLAB\R2016a\toolbox\eml\lib\matlab\ops\eml_mtimes_helper.m"
};
emlrtRSInfo g_emlrtRSI = { 85, "xgemm",
"C:\Program Files\MATLAB\R2016a\toolbox\eml\eml\+coder\+internal\+blas\xgemm.m"
};
emlrtRSInfo n_emlrtRSI = { 214, "minOrMax",
"C:\Program Files\MATLAB\R2016a\toolbox\eml\eml\+coder\+internal\minOrMax.m"
};
emlrtRSInfo o_emlrtRSI = { 375, "minOrMax",
"C:\Program Files\MATLAB\R2016a\toolbox\eml\eml\+coder\+internal\minOrMax.m"
};
emlrtRSInfo p_emlrtRSI = { 347, "minOrMax",
"C:\Program Files\MATLAB\R2016a\toolbox\eml\eml\+coder\+internal\minOrMax.m"
};
/* End of code generation (NeuralNetwork_data.c) */
Aucun commentaire:
Enregistrer un commentaire