-
Notifications
You must be signed in to change notification settings - Fork 19.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception upon loading back a model in Keras 1.0.0 #2281
Comments
I will look into it. Can you upload your old save file somewhere for me to download it? |
Your model has a Dropout layer therefore it uses the learning phase. But apparently it isn't part of the graph --maybe you passed an invalid dropout value to your Dropout layer? Note: I just fixed it, passing invalid dropout values no longer makes the model use the learning phase. |
Thanks for the swift answer! I am passing 0.0 for the dropout and 256 for the fc_neurons. I usually start to train a network without dropout (i.e., dropout line with 0.0) until it stops improving, and reload it with a non-zero dropout to improve it from there. If the dropout layer is missing from the model, I may have a difficulty loading back the topology from the json file, therefore I usually leave it there with 0.0 at first. I can imagine that this might cause some unexpected behaviors, but it didn't with the earlier version of Keras. I will be able to upload the network topology and weights as soon as I get access to that computer. |
Excellent, thanks for the fix, I'll try it as soon as possible! |
Does this have to do with keras.engine.topology.InputLayer being augmented to the model? I am finding with Keras 1.0 that all my models get this layer added on to them. FWIW, I am saving my model in a derirved Callback class. |
I just posted the files to the keras google groups area. |
I don't see anything wildly different in the json file I get. However, even if I remove the dropout layer, the problem still persists. The topology and the model weights are now available here, they are saved with a dropout layer with a probability of 0.0 and 8 neurons in the FC layer to be as minimal as possible. Please note that at the moment, I cannot try the mentioned fix, but since the problem persists even without dropout, maybe there is something still going on. |
can you tell us what model.layers says? I suspect it will add the On Tue, Apr 12, 2016 at 2:52 PM, zsolnaifk notifications@github.com wrote:
|
Just verified, if I remove the topological layer from the model, the model
On Tue, Apr 12, 2016 at 2:55 PM, Isaac Gerg isaac.gerg@gergltd.com wrote:
|
I got exactly same error while loading trained model which was created with new functional API. I do not think that the problem is about dropout layer. I have checked the source code and found that there are two layer names for the first conv2d layer like "conv2d_input_1" and "conv2d_1" while there is only one layer in weights file. |
You have to remove the topological layer from your model when you save and then it will work. |
Can anybody provide a script I can run to reproduce such an issue? Completely unable to reproduce this right now. I can load any model saved with Keras 0.3.3 into Keras 1.0. Steps:
No issue. |
see the attached files I sent in a previous message. On Tue, Apr 12, 2016 at 4:44 PM, François Chollet notifications@github.com
|
As I said, I cannot reproduce your issue. Anyone else? |
Have you looked at my files? Can you verify you see the *_input_1 layer in On Tue, Apr 12, 2016 at 4:53 PM, François Chollet notifications@github.com
|
For me, the problem only happens when I save the model in a You should verify that when you create your model and print out On Tue, Apr 12, 2016 at 4:54 PM, Isaac Gerg isaac.gerg@gergltd.com wrote:
|
I have tried to put together a minimal example that yields the mentioned error on my side. A trivial python script and the model resources are available here: Here is the log of the output as I ran it locally:
|
My model shows: [<keras.engine.topology.InputLayer object at 0x0000000011089080>, that first layer is what messes up the output to hdf5 adding an extra On Tue, Apr 12, 2016 at 5:05 PM, zsolnaifk notifications@github.com wrote:
|
model = model_from_json(open('my_model_architecture.json').read())
model.load_weights('my_model_weights_best.h5') All that this scripts tells me is that there is a mismatch between the JSON file and the weights file that you have uploaded. What I would like to see is an example of a script where a same model can generate a mismatched JSON file and weight file, or where a same model can generate a weight file that cannot be loaded with the new version. The following works perfectly with both Keras 0.3 and 1.0, including when the weight file is saved with Keras 0.3 then loaded with Keras 1.0: from keras.models import Sequential, model_from_json
from keras.layers import *
model = Sequential()
model.add(Convolution2D(32, 5, 5,
border_mode='valid',
input_shape=(3, 216, 384)))
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(8))
model.add(Activation('relu'))
model.add(Dropout(0.))
model.add(Dense(9))
model.add(Activation('linear'))
# this line can be commented out when running
# with Keras 1.0, so that the save file will be
# from Keras 0.3
model.save_weights('test.h5')
config = model.to_json()
model = model_from_json(config)
model.load_weights('test.h5') |
I did clean installation of Keras 1.0 and tried to run the code sample from this gist and it produces error that we are talking about. |
Are u pulling the master or the keras 1.0 branch? I am pulling the master Sent from my Android.
|
@Refikcanmalli: thanks, I can repro this. Will look into it. |
Excellent, thanks for the help! The minimal example Francois provided runs without a problem, but my own full script does raise the error message. The only difference is that there is actual training going on with the full program. The gist is probably the easiest way to go for now, but if you need me to pass you my full script, just let me know, I'll be able to do it tomorrow! |
Figured it out, fix pending. It's unfortunate that you guys (isaacgerg?)
The bug, in short, was that that ModelCheckpointer (and in general, all On 12 April 2016 at 14:24, isaacgerg notifications@github.com wrote:
|
Unfortunately, I am providing what I can given how busy I am at the On Tue, Apr 12, 2016 at 6:02 PM, François Chollet notifications@github.com
|
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. |
So the bug turned out to be in the callbacks section. I mentioned that On Tue, Apr 12, 2016 at 6:18 PM, Isaac Gerg isaac.gerg@gergltd.com wrote:
|
How could it be a couple of weeks when 0.3 was still getting changes pumped On Tue, Apr 12, 2016 at 6:25 PM, François Chollet notifications@github.com
|
The fix indeed works, everything is going fine after pulling the new version. Thanks so much for the prompt answer! Closing. |
Just pulled. Looks like the fix worked. Thank you! On Tue, Apr 12, 2016 at 6:28 PM, zsolnaifk notifications@github.com wrote:
|
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:
The network is defined as follows:
Please note that upon starting the training, the following warning is raised since Keras 1.0.0 (didn't appear with the previous version):
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!
[1] http://keras.io/faq/#how-can-i-save-a-keras-model
The text was updated successfully, but these errors were encountered: