Keras: Not able to import saving

Created on 29 May 2018  路  8Comments  路  Source: keras-team/keras

I'm trying to use Intel NLP Architect and its example has this line that makes it not working:

>>> from keras.engine import saving
Using TensorFlow backend.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'saving'

Anyone knows how to fix it? Thank you!
Also this is a link to the whole framework: http://nlp_architect.nervanasys.com/ner_crf.html But the line that makes it not working is just that one line.

========================================================================

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

  • [x] 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.

  • [x] 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).

Most helpful comment

It is super late but I want to give the solution in case somebody is still looking for it.

I am using Keras (2.1.3) and Tensorflow (1.3.0) and I saw that the developers rewrote the word saving as topology.

Therefore, in order to make it work, you need to modify (in your _model_ file of ...\site-packages\mrcnn) this:

From:

from keras.engine import saving

To:

from keras.engine import topology

And from:

if by_name: saving.load_weights_from_hdf5_group_by_name(f, layers)

else: saving.load_weights_from_hdf5_group(f, layers)

To:

if by_name: topology.load_weights_from_hdf5_group_by_name(f, layers)

else: topology.load_weights_from_hdf5_group(f, layers)

All 8 comments

Hi!

It seems the saving file in keras.engine has been initialized after the last release of keras (2.1.6 -- relevant commit).

You can either:

  • wait for the next release
  • directly clone the repo in your site-packages and run the install there.

Thank you! It seems to be a problem with Intel NLP Architect that they are not requiring the correct version.

@fallcat don't forget to close the issue if you don't have any more problems!

@fallcat How exactly did you fix this issue? I'm also trying to use NLP Architect and am running into the same error.

I'm trying to use keras_contrib and get the same issue when trying to import their save_load_utils file (which in turn is trying to import saving from keras) @RaphaelMeudec

@akshitharamachandran Sorry that I forgot to reply. I didn't fix the issue.... I saw https://github.com/NervanaSystems/nlp-architect/issues/4 so it's a problem with NLP Architect, and hopefully they will fix it.

in pre v2.1.6, it is from keras.models import load_model

It is super late but I want to give the solution in case somebody is still looking for it.

I am using Keras (2.1.3) and Tensorflow (1.3.0) and I saw that the developers rewrote the word saving as topology.

Therefore, in order to make it work, you need to modify (in your _model_ file of ...\site-packages\mrcnn) this:

From:

from keras.engine import saving

To:

from keras.engine import topology

And from:

if by_name: saving.load_weights_from_hdf5_group_by_name(f, layers)

else: saving.load_weights_from_hdf5_group(f, layers)

To:

if by_name: topology.load_weights_from_hdf5_group_by_name(f, layers)

else: topology.load_weights_from_hdf5_group(f, layers)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LuCeHe picture LuCeHe  路  3Comments

zygmuntz picture zygmuntz  路  3Comments

braingineer picture braingineer  路  3Comments

fredtcaroli picture fredtcaroli  路  3Comments

KeironO picture KeironO  路  3Comments