Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Is there a way to save a trained neural network for future use after the current run ends?

Asked by Sree Srinivasan on 9 Nov 2012

For applications that do not require real-time predictions, the user may tolerate Matlab ANN runs that seem to take forever. Case in point: With about 300 variables (or descriptors), 2000 data points, 5 different variations of neurons in the hidden layer (5 to 25 in increments of 5),3 re-initializations (to avoid local minima), but no division into training & validation sets (unnecessary with Bayes regularization), trainbr (1 hidden layer) takes about a week (on a Windows 7 laptop with 4GB RAM, running the 64 bit version of Matlab).

The run also includes, for comparison, trainings based on 30 linear or nonlinear principal components or selected descriptors instead of the 300 raw descriptors. So, asking me to explore "dimension reduction" is not the answer.

It would be nice to save the network (weights, etc.) trained at such an expense of time, so that it can be evaluated on test data that may become available in the future, without having to spend a week training the network everytime a new set of test data becomes available.

0 Comments

Sree Srinivasan

Products

No products are associated with this question.

2 Answers

Answer by Greg Heath on 14 Nov 2012
Accepted answer

save net01

When you need it later

load net01

Voila!

2 Comments

Sree Srinivasan on 17 Nov 2012

That works, but when assigning a file name within the batch run (not interactively), there is a problem:

            Net_Iter = {['Net', Run_Index, '.mat' ]}
            save Net_Iter net

Run_Index is a number that varies within a FOR loop (where several networks are trained one after another).

Net_Iter = 'Net123.mat'

But the save command results in Net_iter.mat (literally!).

Walter Roberson on 17 Nov 2012
save(Net_iter, 'net')
Greg Heath
Answer by Sean de Wolski on 9 Nov 2012

Can't you just save it?

3 Comments

Greg Heath on 13 Nov 2012

I agree. Save the whole net instead of saving parameters and weights separately.

Sree Srinivasan on 14 Nov 2012

Thanks. So, the following commands should work. Am I right?

To save: save net1.mat net

To use later: load net1.mat net

Greg Heath on 28 Nov 2012

I think all you need is

save net1

load net1

Sean de Wolski

Contact us