how to save and reuse a trained neural network

O
Omotayo-asiru · Jun 15, 2021 · 2.4K views
Question
I just trained a neural network and i will like to test it with new data set that were not included in the training so as to check its performance on new data. This is my code; net = patternnet(30); net = train(net,x,t); save (net); y = net(x); perf = perform(net,t,y) classes = vec2ind(y); where x and t are my input and target respectively. I understand that save net; can be used but my questions are as follows ; 1.At what point in my code will i put save net 2.Using save net;, which location on the system is the trained network saved? 3.How can i load the trained network and supply new data that i want to test it with? Please Note: I want to be able to save the trained neural network such that when i run the code over and over again with the training data set,it gives same output. I have discovered that each time i run my code,it gives a different output which i do not want once i have an acceptable result. 
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 30, 2026

1.At what point in my code will i put save net

 

 Any time after training it and before deleting it. 
However, give it a unique name so that it is not overwritten 
or used by mistake. 

 gregnet1 = net;
 save gregnet1
2.Using save net;, which location on the system is the trained network saved?
 
 
 What ever directory you are in when you save it UNLESS you 
specify another directory.

3.How can i load the trained network and supply new data that i want to test it with?

 load gregnet1
 newoutput = gregnet1(newinput);

Please Note: I want to be able to save the trained neural network such that when i run the code over and over again with the training data set,it gives same output. I have discovered that each time i run my code,it gives a different output which i do not want once i have an acceptable result.

 Then initialize the RNG to the same state before training to 
obtain reproducibility. See any of my training example posts.
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!