Deep Learning Toolbox Converter for TensorFlow Models
Import and export TensorFlow models within MATLAB
9,5K téléchargements
Mise à jour
15 oct. 2025
The converter for TensorFlow models enables you to import a pretrained TensorFlow model and weights and export a MATLAB dlnetwork as a TensorFlow model.
Import:
Note: importNetworkFromTensorFlow accepts TensorFlow models in the SavedModel format. Use the following commands before import to save a TensorFlow model in the SavedModel format.
For TensorFlow versions 2.15 and earlier, save the model with the following Python command: :
model.save("modelName")
For TensorFlow versions 2.16 and later, save the model with the following Python commands.
First, install the Keras 2 (tf_keras) package:
pip install tf_keras
Note: if you are using a Jupyter notebook, restart the notebook kernel before running the code.
Now, precede any import tensorflow statement with the following lines of code:
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
import tensorflow
Next, Import Keras 2 (tf_keras) as keras. Do not import Keras 3 (keras) directly. Keras 3 specific features are unsupported:
import tf_keras as keras
from tf_keras import layers
To verify if you are using Keras 2, the following command should print `False`
is_keras3 = hasattr(keras, "version"))
print(is_keras3)
Finally, once you verify the Keras version, save the model:
model.save("modelName")
The TensorFlow Model Importer has been tested up to 2.15. SavedModels saved with versions 2.16 and higher may also work without issues. When using tf_keras for versions 2.16 and higher, Keras 3 specific features such as Keras Ops will not be supported.
Export:
Export supports:
- TensorFlow v2.0 or later, no support for Keras 3.0
- Python version 3.0 or later
Compatibilité avec les versions de MATLAB
Créé avec
R2017b
Compatible avec les versions R2017b à R2026a
Plateformes compatibles
Windows macOS (Apple Silicon) macOS (Intel) LinuxCatégories
En savoir plus sur Deep Learning Toolbox dans Help Center et MATLAB Answers
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
