Export a neural network trained with MATLAB in other programming languages

前端 未结 5 1600
失恋的感觉
失恋的感觉 2020-12-13 02:44

I trained a neural network using the MATLAB Neural Network Toolbox, and in particular using the command nprtool, which provides a simple GUI to use the toolbox

5条回答
  •  轮回少年
    2020-12-13 03:39

    This is a small improvement to the great Vito Gentile's answer.

    If you want to use the preprocessing and postprocessing 'mapminmax' functions, you have to pay attention because 'mapminmax' in Matlab normalizes by ROW and not by column!

    This is what you need to add to the upper "classify" function, to keep a coherent pre/post-processing:

    [m n] = size(input);
    ymax = 1;
    ymin = -1;
    for i=1:m
       xmax = max(input(i,:));
       xmin = min(input(i,:));
       for j=1:n
         input(i,j) = (ymax-ymin)*(input(i,j)-xmin)/(xmax-xmin) + ymin;
       end
    end
    

    And this at the end of the function:

    ymax = 1;
    ymin = 0;
    xmax = 1;
    xmin = -1;
    Results = (ymax-ymin)*(Results-xmin)/(xmax-xmin) + ymin;
    

    This is Matlab code, but it can be easily read as pseudocode. Hope this will be helpful!

提交回复
热议问题