0

I downloaded a saved CNN model from here. However, I am unable to load the model. I have tried the following code

import tensorflow as tf
import keras
from tensorflow.keras.models import load_model 
model = load_model('./full_retina_model.h5')

It gives an error

ValueError: bad marshal data (unknown type code)

I also have the hdf5 downloaded from the same web which I am trying to use like:

model = tf.keras.models.Sequential()
model.load_weights('./retina_weights.best.hdf5')

which over error

ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights.

Any help in loading this model from the URL is appreciated

Sathvik K S
  • 109
  • 1
  • 2
  • 11
  • I suggest you can check Python / Tensorflow versions of the saved model and the environment that you are loading into. It's possibly the reason for this. – Quan Nguyen Nov 10 '22 at 03:42
  • You should create the Retina model as mentioned in the link, and then use `retina_model.load_weights()` – Vijay Mariappan Nov 10 '22 at 13:23
  • 1
    Hi @SathvikKS, This error usually occurs when you save a model in one Python version (for example, 3.6) and then try to load it in another Python version (e.g., 3.9). Please refer to this [thread](https://stackoverflow.com/a/73441916/14290697) For loading weights kindly refer [this](https://stackoverflow.com/questions/63658086/tensorflow-2-0-valueerror-while-loading-weights-from-h5-file). Thank you! –  Nov 21 '22 at 12:03

0 Answers0