Keras load history model error: AttributeError:'str' object has no attribute'decode'

Keras 2.3.0 reported an error when loading the historical model: AttributeError:'str' object has no attribute'decode'

Solution:

1. Downgrade h5py

pip3 install h5py==2.10.0

2. Change the model loading method

The above error appears in load_weights()the process of calling the load model parameters, but the keras.models.load_modelfunction can also be called when loading the historical model , just load it as follows:

model= keras.models.load_model(model_path,custom_objects= {
    
    'Denoising_Enhancing_layer':Denoising_Enhancing_layer},compile=False)

Denoising_Enhancing_layer is a custom Keras layer. Note that if there is a custom layer, you need to specify similar parameters for custom_objects.

Tiankeng: It should be pointed out that load_model is a Tiankeng. When it loads a model (especially a complex model, such as a model with residuals and multiple inputs and outputs), it does not seem to actually load the loaded parameters into the model correctly. So there will be: the training phase, the result of the test data set is very good; after saving the model, reloading the model, and then testing, but the test results are very strange things!
When this tiankeng appears, please re-use it load_weightsto load the historical model!

Guess you like

Origin blog.csdn.net/jmh1996/article/details/111224700