tensorflowkerastensorflow.js

Need to convert Keras model to TensorFlow.js but facing version compatibility issues between TensorFlow and Keras


When I tried to convert a .h5 model by using this command in the terminal

tensorflowjs_converter --input_format keras model.h5 ./folder

I got an output that says "ValueError: Expected Keras version 2; got Keras version 3.3.3".

So, I reinstalled keras for keras 2.6.0, but THAT didn't work because tensorflow 2.16.1 requires keras to be at least version 3.0.0. So, the logical thing I tried to do was to downgrade tensorflow to a version that is compatible to keras 2.6.0, but there isn't a version of tensorflow that I can choose to install that actually is. There's only two versions of tensorflow that I can choose from: tensorflow 2.16.0rc and tensorflow 2.16.1, and neither are compatible with keras 2.6.0. I'm kind of new to all of this, so if my problem seems trivial, don't overthink it.


Solution

  • You need to downgrade your python version to install TensorFlow < 2.16

    As of today (2024-06-10), TensorFlow versions < 2.16 are not compatible with Python 3.12. Refer to this table: Tested build configuration to check compatibility.

    You can also check the tensorflow package on PyPi. For example, the version 2.15.1 has binary packages available for Python 3.9 to 3.11.