Error loading a saved model?
See original GitHub issueThere is my model:
data_dim = 25*88
timesteps = 40
secen = Sequential()
secen.add(Convolution2D(32, 3, 3, activation='relu', border_mode='same', input_shape=(1, 25, 88)))
secen.add(MaxPooling2D((2, 2)))
secen.add(Dropout(0.25))
secen.add(Convolution2D(32, 3, 3, activation='relu', border_mode='same'))
secen.add(MaxPooling2D((2, 2)))
secen.add(Dropout(0.25))
secen.add(Convolution2D(32, 3, 3, activation='relu', border_mode='same'))
secen.add(MaxPooling2D((2, 2)))
secen.add(Dropout(0.25))
secen.add(Flatten())
secde = Sequential()
secde.add(Convolution2D(32, 3, 3,border_mode='same', input_shape=(1, 25, 11)))
secde.add(Activation('tanh'))
secde.add(UpSampling2D(size=(1, 2)))
secde.add(Convolution2D(32, 3, 3, border_mode='same'))
secde.add(Activation('tanh'))
secde.add(UpSampling2D(size=(1, 2)))
secde.add(Convolution2D(32, 3, 3, border_mode='same'))
secde.add(Activation('tanh'))
secde.add(UpSampling2D(size=(1, 2)))
secde.add(Convolution2D(1, 3, 3, border_mode='same'))
secde.add(Activation('sigmoid'))
music_input = Input(shape=(timesteps, 1, 25, 88))
encoded_frame_sequence = TimeDistributed(secen)(music_input)
encoded_music = LSTM(data_dim/8,return_sequences=True)(encoded_frame_sequence)
encoded_music=Dropout(0.25)(encoded_music)
encoded_music=Reshape((timesteps, 1, 25,11 ))(encoded_music)
decode_music=TimeDistributed(secde)(encoded_music)
model=Model(input=music_input,output=decode_music)
model.compile(optimizer='rmsprop',
loss='binary_crossentropy')
I fitted the model.However when I load it from a .h5 file,i got an error.
model = load_model('midinet_0110.h5')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda2\Lib\site-packages\keras\models.py", line 179, in load_model
model.optimizer.set_weights(optimizer_weight_values)
File "C:\Anaconda2\Lib\site-packages\keras\optimizers.py", line 90, in set_weights
'provided weight shape ' + str(w.shape))
ValueError: Optimizer weight shape (275L, 275L) not compatible with provided weight shape (1056, 275)
I guess it may caused by the complicacy of my model?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top Results From Across the Web
Error loading saved model · Issue #51746 - GitHub
After saving a Quant Aware model to saved_model using model.save(), I get this error while loading it with tf.keras.models.load_model() - ...
Read more >Error when loading a saved model - TensorFlow Forum
Hello communit, i saved a model which i trained for a deep-q learning project. Tensorflow/keras 2.7.0 on Python 3.9.9 64bit on Windows 10....
Read more >Unable to load a Keras saved model (Error: unable to open file)
Try like this, model.save("my_model"). Calling model.save('my_model') creates a folder named my_model, containing the following:
Read more >Error loading saved model - PyTorch Forums
I have a model: cnn=CNN() torch.save(cnn, './model/trained_model.pt') model = torch.load('./model/trained_model.pt') AttributeError: Can't ...
Read more >Save and load models in Tensorflow - GeeksforGeeks
Save and load models in Tensorflow ... The development of the model can be saved both before and after testing. As a result,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Reproduced with Keras 2.0.5 on Tensorflow with the Adam optimizer. I’m using an Inception V4 model.
I had same problems with save_model + load_model on trained model with Adam optimizer on Theano. Keras 1.1.1 The problem was that the optimizer weights were not loaded in the same order so there was an assertion on weight shapes. I could solve locally this issue modifying Adam code to set names for each weights it used so that weights matched between save and load. In optimizers.py :
I haven’t seen yet if there is a naming convention that should be used and if this is the correct fix, probably all optimizers need it.