Being able to export ANN without retraining
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Ayush Aniket
on 23 Dec 2024
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
Ayush Aniket
on 24 Dec 2024
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
More Answers (0)
See Also
Categories
Find more on Sequence and Numeric Feature Data Workflows 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!