Does Any one got “AttributeError: 'str' object has no attribute 'decode' ” , while Loading a Keras Saved Model

后端 未结 5 1849
轮回少年
轮回少年 2021-01-01 17:01

After Training, I saved Both Keras whole Model and Only Weights using

model.save_weights(MODEL_WEIGHTS) and model.save(MODEL_NAME)

Models

相关标签:
5条回答
  • 2021-01-01 17:40

    This is probably due to a model saved from a different version of keras. I got the same problem when loading a model generated by tensorflow.keras (which is similar to keras 2.1.6 for tf 1.12 I think) from keras 2.2.6.

    You can load the weights with model.load_weights and resave the complete model from the keras version you want to use.

    0 讨论(0)
  • 2021-01-01 17:43

    For me it was the version of h5py that was superior to my previous build.
    Fixed it by setting to 2.10.0.

    0 讨论(0)
  • 2021-01-01 17:45

    For me the solution was downgrading the h5py package (in my case to 2.10.0), apparently putting back only Keras and Tensorflow to the correct versions was not enough.

    0 讨论(0)
  • 2021-01-01 17:46

    saved using TF format file and not h5py: save_format='tf'. In my case:

    model.save_weights("NMT_model_weight.tf",save_format='tf')
    
    0 讨论(0)
  • 2021-01-01 18:01

    I had the same problem, solved putting compile=False in load_model:

    model_ = load_model('path to your model.h5',custom_objects={'Scale': Scale()}, compile=False)
    sgd = SGD(lr=1e-3, decay=1e-6, momentum=0.9, nesterov=True)
    model_.compile(loss='categorical_crossentropy',optimizer='sgd',metrics=['accuracy'])
    
    0 讨论(0)
提交回复
热议问题