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

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.

 Accepted Answer

save net01
When you need it later
load net01
Voila!

3 Comments

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!).
I am also training multiple networks for forecasting. Were you ever able to solve the problem of saving each one of the nets through a For Loop. Because the code above only names it, as u said, literally.

Sign in to comment.

More Answers (2)

Can't you just save it?

4 Comments

I agree. Save the whole net instead of saving parameters and weights separately.
Thanks. So, the following commands should work. Am I right?
To save: save net1.mat net
To use later: load net1.mat net

Sign in to comment.

This doesn't work for me, and gives a save error saying my file may be corrupt. The syntax that works for me is:
save 'foo' net
...where 'foo' is the name you want to save it as, and 'net' is the trained network that you want to save as 'foo'. The file you save will be called foo.mat, and will be located in the current directory.

Categories

Find more on Networks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!