How can I save a trained model using python and load the same model and use it in MATLAB

37 Ansichten (letzte 30 Tage)
Suppose I trained a tensorflow deep learning model using Python. How to save that in . mat file.
Again load that trained model in MATLAB and use it.

Antworten (1)

Milan Bansal
Milan Bansal am 26 Mär. 2024
Hi Anusaya,
I understand that you want to save a TensorFlow deep learning model trained using Python and then use the saved model in MATLAB.
Please refer to the steps given below to achieve this.
1.) After training your model, save it using the "save_model" function from TensorFlow's "keras.models" module. This will save your model in the SavedModel format. This will save the model in the form of a directory. Please refer to the below Python code for saving the TensorFlow model.
Python Code: model.save('tensorFlowModel')
2.) Now, load the saved TensorFlow model directly into MATLAB using the "importNetworkFromTensorFlow" function. Please refer to the following code snippet:
modelDir = "tensorFlowModel";
net = importNetworkFromTensorFlow(modelDir);
Additionally, to save this model as ".mat", use the "save" function in MATLAB. Please refer to the following code snippet:
save("matlabModel", "net");
Please refer to the following documentation link to learn more about "importNetworkFromTensorFlow".
Please refer to the following documentation link to learn more about "Save and load models" in TensorFlow.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by