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.

 Respuesta aceptada

Ayush Aniket
Ayush Aniket el 23 de Dic. de 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 comentarios

Abdul
Abdul el 23 de Dic. de 2024
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 ?
Ayush Aniket
Ayush Aniket el 24 de Dic. de 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
Abdul
Abdul el 24 de Dic. de 2024
Thank you very much Ayush for your valuable advice, will go through the resources you sent and make good use of them.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 22 de Dic. de 2024

Comentada:

el 24 de Dic. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by