Main Content

Deploy Training of Shallow Neural Networks

Tip

To learn about code generation for deep learning, see Deep Learning Code Generation.

Use MATLAB® Runtime to deploy functions that can train a model. You can deploy MATLAB code that trains neural networks as described in Create Standalone Applications from the Command Line (MATLAB Compiler).

The following methods and functions are NOT supported in deployed mode:

Here is an example of how you can deploy training of a network. Create a script to train a neural network, for example, mynntraining.m:

% Create the predictor and response (target)
x = [0.054 0.78 0.13 0.47 0.34 0.79 0.53 0.6 0.65 0.75 0.084 0.91 0.83
     0.53 0.93 0.57 0.012 0.16 0.31 0.17 0.26 0.69 0.45 0.23 0.15 0.54];
t = [0.46 0.079 0.42 0.48 0.95 0.63 0.48 0.51 0.16 0.51 1 0.28 0.3];
% Create and display the network
net = fitnet(); 
disp('Training fitnet')
% Train the network using the data in x and t
net = train(net,x,t);
% Predict the responses using the trained network
y = net(x);
% Measure the performance
perf = perform(net,y,t)

Compile the script mynntraining.m by using the command line:

mcc -m 'mynntraining.m'

mcc invokes the MATLAB Compiler™ to compile code at the prompt. The flag –m compiles a MATLAB function and generates a standalone executable. The EXE file is now in your local computer in the working directory.

To run the compiled EXE application on computers that do not have MATLAB installed, you need to download and install MATLAB Runtime. The readme.txt created in your working folder has more information about the deployment requirements.

Related Topics