Keras: Cannot load_model

Created on 29 Aug 2018  路  3Comments  路  Source: keras-team/keras

Thank you!

  • [ ] Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps

  • [x] If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • [ ] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
    pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • [x] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

I am using Google Colab to train a CNN and then save the entire model to a .h5 file. The code is available here: CNN-Colab

The model gets saved but when I later try to load it back, I get the following error:

TypeError: float() argument must be a string or a number, not 'dict'

The entire Output log is here: CNN - Colab - Error

tensorflow

Most helpful comment

Is there a way to apply the fix as a patch to Tensorflow 1.12 installed in Anaconda?

Edit:
For those looking to fix this issue, follow these steps.

  1. Open a python interpreter
  2. import tensorflow
  3. Type tensorflow.__file__ to find the location of your tensorflow install (call this $TENSORFLOW_DIR)
  4. Navigate to your tensorflow install directory
  5. Edit $TENSORFLOW_DIR/python/keras/layers/advanced_activations.py
  6. In the stack trace where you saw the TypeError: float() argument must be a string or a number message, a few lines up there should be a trace from advanced_activations.py.
  7. Edit the line in advanced_activations.py to use a try/except block

try: self.SOME_VALUE = K.cast_to_floatx(SOME_VALUE) except TypeError: self.SOME_VALUE = K.cast_to_floatx(SOME_VALUE['value'])

All 3 comments

@abhisheksoni27 I think you hit this bug, it has been fixed at keras-team/keras, but you are using tf.keras. Actually I have sent a fix to tf.keras as well, but not merged until now.

Closing this issue since the fixed has been merged. Feel free to reopen the issue if the problem still persists. Thanks!

Is there a way to apply the fix as a patch to Tensorflow 1.12 installed in Anaconda?

Edit:
For those looking to fix this issue, follow these steps.

  1. Open a python interpreter
  2. import tensorflow
  3. Type tensorflow.__file__ to find the location of your tensorflow install (call this $TENSORFLOW_DIR)
  4. Navigate to your tensorflow install directory
  5. Edit $TENSORFLOW_DIR/python/keras/layers/advanced_activations.py
  6. In the stack trace where you saw the TypeError: float() argument must be a string or a number message, a few lines up there should be a trace from advanced_activations.py.
  7. Edit the line in advanced_activations.py to use a try/except block

try: self.SOME_VALUE = K.cast_to_floatx(SOME_VALUE) except TypeError: self.SOME_VALUE = K.cast_to_floatx(SOME_VALUE['value'])

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oweingrod picture oweingrod  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

KeironO picture KeironO  路  3Comments

farizrahman4u picture farizrahman4u  路  3Comments