keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.98k stars 19.47k forks source link

Not able to import saving #10311

Closed fallcat closed 6 years ago

fallcat commented 6 years ago

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!

RaphaelMeudec commented 6 years ago

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:

fallcat commented 6 years ago

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

RaphaelMeudec commented 6 years ago

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

akshitharamachandran commented 6 years ago

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

mary-octavia commented 6 years ago

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

fallcat commented 6 years ago

@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.

jemshit commented 6 years ago

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

albavilanova commented 4 years ago

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)

MLHafizur commented 3 years ago

topology

Tried this, But no luck unfortunately, getting same error.

mr7manohar commented 3 years ago

i resolve this issue by downgrading to python 3.7 with keras 2.0.8 and tesnorflow 1.13.1. and it worked