keras: Exception upon loading back a model in Keras 1.0.0
Hello,
I have freshly upgraded to Keras 1.0.0 from 0.3.x and an error message was raised upon loading back a previously saved network. Using theano backend, tried with theano 0.8.0 and 0.8.1 with the same results.
The error message is the following:
Using gpu device 0: GeForce GTX TITAN X (CNMeM is enabled with initial size: 90.0% of memory, CuDNN 4007)
File "nn.py", line 185, in <module>
model.load_weights('my_model_weights_best.h5')
File "/usr/lib/python2.7/site-packages/keras/engine/topology.py", line 2286, in load_weights
str(len(flattened_layers)) + ' layers.')
Exception: You are trying to load a weight file containing 17 layers into a model with 16 layers.
The network is defined as follows:
model = Sequential()
model.add(Convolution2D(32, 5, 5,
border_mode='valid',
input_shape=(loadedImage_rolled.shape)))
model.add(Activation('relu'))
model.add(Convolution2D(32, 5, 5))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Convolution2D(64, 3, 3, border_mode='valid'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(fc_neurons))
model.add(Activation('relu'))
model.add(Dropout(dropout))
model.add(Dense(num_variables))
model.add(Activation('linear'))
Please note that upon starting the training, the following warning is raised since Keras 1.0.0 (didn’t appear with the previous version):
/usr/lib/python2.7/site-packages/keras/backend/theano_backend.py:484: UserWarning: theano.function was asked to create a function computing outputs given certain inputs, but the provided input variable at index 3 is not part of the computational graph needed to compute the outputs: keras_learning_phase.
To make this warning into an error, you can pass the parameter on_unused_input='raise' to theano.function. To disable it completely, use on_unused_input='ignore'.
After a few epochs, both the model topology and weights were saved and later loaded back with the appropriate functions shown in the Keras documentation [1]. The same piece of code worked without a hiccup with the previous version of Keras (0.3.x).
Let me know if you need more information and thanks for your time in advance!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 31 (8 by maintainers)
The issue is fixed, you can pull master and reinstall.
1.0 has very extensive unit test coverage, and was beta tested by over twenty people before release, for a couple weeks. Some bugs will always slip though the cracks though.