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.

 採用された回答

Ayush Aniket
Ayush Aniket 2024 年 12 月 23 日

0 投票

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 件のコメント

Abdul
Abdul 2024 年 12 月 23 日
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 2024 年 12 月 24 日
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 2024 年 12 月 24 日
Thank you very much Ayush for your valuable advice, will go through the resources you sent and make good use of them.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDeep Learning Toolbox についてさらに検索

製品

リリース

R2024b

質問済み:

2024 年 12 月 22 日

コメント済み:

2024 年 12 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by