Being able to export ANN without retraining

I have created an ANN that I would like to test on different data but when i run the code that i exported using "generate code" it retrains the ANN and I get different values for MSE, and other values i would have wanted to keep. this re-training happens before the test data is sent to the ANN for prediction. If anyone has any idea how I can retain the ANN with its previous training and still be able to use it in MATLAB I would be very grateful for your help.

 Accepted Answer

To use a pre-trained Artificial Neural Network (ANN) for testing on new data without retraining, you need to save the trained network and then load it for testing as shown below:
% Assuming 'net' is your trained network
save('trainedANN.mat', 'net');
% Load the trained network
load('trainedANN.mat', 'net');
% Test data
testData = ...;
% Use the loaded network for prediction
predictions = net(testData);
You need to modify your generated code to include this workflow. If you are still facing issues, share the code you are using.

3 Comments

I am a new to all this, if i use "generate code" doesnt that save all the training and weights ? or would using "export model" be used in that case ?
I am assuming you are using Deep Network Desginer to design yopur neural network graphically, and then using the "Generate Network Code" button to generate live scipt. This script contains code for network details and loads paramaeters for pre-trained networks. Refer to this documentation link: https://www.mathworks.com/help/deeplearning/ug/generate-matlab-code-from-deep-network-designer.html
If you want to train this model or predict output for your test data you have to manually write code for it. Refer to this example which shows the whole process of designing , training and testing a deep learning model: https://www.mathworks.com/help/deeplearning/ug/transfer-learning-with-deep-network-designer.html#TransferLearningWithDeepNetworkDesignerExample-8
Additionally, I would suggest you to take this Deep Learning Onramp to gain more knowledge: https://matlabacademy.mathworks.com/details/deep-learning-onramp/deeplearning
Thank you very much Ayush for your valuable advice, will go through the resources you sent and make good use of them.

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products

Release

R2024b

Asked:

on 22 Dec 2024

Commented:

on 24 Dec 2024

Community Treasure Hunt

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

Start Hunting!