Why am I unable to import a TensorFlow model in MATLAB R2024b using the Deep Learning Toolbox Converter?

11 ビュー (過去 30 日間)

I have the Deep Learning Toolbox and the Deep Learning Toolbox Converter for TensorFlow Models support package installed in MATLAB R2024b. However, I encounter an error when trying to import my TensorFlow model into MATLAB. What could be causing this, and how can I resolve it?

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 8 月 27 日 0:00
This issue can occur due to incompatibility between the TensorFlow/Keras versions used to create the model and the versions supported by the Deep Learning Toolbox Converter for TensorFlow Models in MATLAB R2024b. Specifically:
  • The Deep Learning Toolbox Converter for TensorFlow Models currently supports TensorFlow versions up to 2.15.0.
  • TensorFlow versions 2.16 and above use Keras 3 by default, which is not compatible with the "importNetworkFromTensorFlow" function in MATLAB. The converter requires models to be built and saved using Keras 2.
To successfully import your TensorFlow model into MATLAB, use one of the following methods:
1) Build and Save the Model Using Keras 2
a. Install the Keras 2 (tf_keras) package:
>> pip install tf_keras
b. Before importing TensorFlow in your script, set the environment variable to use legacy Keras:
>> import os >> os.environ["TF_USE_LEGACY_KERAS"] = "1" >> import tensorflow
c. Import Keras 2 as follows:
>> import tf_keras as keras
>> from tf_keras import layers
d. Build and save your model in the SavedModel format:
>> model.save("myModelTF")
2) Downgrade TensorFlow to Version 2.15 or Lower
  • If you prefer not to use the above workaround, you can downgrade your TensorFlow installation to version 2.15 or lower, which uses Keras 2 by default.
  • Save your model using:
>> model.save("myModelTF")
Note: Ensure that the model is saved in the TensorFlow SavedModel format. Do not use the tf.saved_model.save function; instead, use the model.save method.
After saving the model as described above, you should be able to import it into MATLAB using the Deep Learning Toolbox Converter for TensorFlow Models.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel and Cloud についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by