Keras-facenet-h5 : Value error: bad marshal data (unknown type code)

I am trying to load keras-facenet-h5 on my environment with the code written in the course:

from tensorflow.keras.models import model_from_json
json_file = open(‘keras-facenet-h5/model.json’, ‘r’)
loaded_model_json = json_file.read()
json_file.close()
model = model_from_json(loaded_model_json)
model.load_weights(‘keras-facenet-h5/model.h5’)

But it fails with this error message:

  • ValueError: bad marshal data (unkown type code)

I use Python 3.9 / Tensorflow 2.7.0 / Keras 2.7.0 in a conda virtual environment.

I read on blogs that this might be caused by a model being saved in a pythonVersion or TF/Keras version different than the one used to generate the model.

  • How do we find the versions used in this model ?
  • Is there another way than creating a new conda virtual environment with a downgrading of the versions to be able to run this pretrained network ?

Any help appreciated

As you see, there are some dependencies to particular version of components… I have a 3-5 local environments in the conda for this course. :slight_smile:
Using the same version of Tensorflow (if remember correctly, it is 2.3… old one…) is the first thing to do, but, for this particular case, please try to use Python 3.7. In my local environment, it worked.

[updates]
It worked in the following virtual environment.
Python 3.7.7, Tensorflow 2.5.0, Keras 2.4.3
But, I suppose the version of Python is the key.

2 Likes

Thanks a lot Nobu_Asai.

I created a new virtual environment with the same specs than yours (Python 3.7.7, Tensorflow 2.5.0, Keras 2.4.3) and it worked perfectly.

Note that I also tried to create a virtual environment with Python 3.7.7 with Tensorflow 2.7.0 and Keras 2.7.0 but this failed with the same valueError: bad marshal data

how to create these new environments in jupyter in Windows?