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

조회 수: 9 (최근 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 CenterFile Exchange에서 Parallel and Cloud에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by