Skip to content
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

ImportError: cannot import name 'tf' from 'keras.backend' #120

Closed
alexst07 opened this issue Oct 7, 2019 · 6 comments
Closed

ImportError: cannot import name 'tf' from 'keras.backend' #120

alexst07 opened this issue Oct 7, 2019 · 6 comments

Comments

@alexst07
Copy link

alexst07 commented Oct 7, 2019

I am having problems to execute the pre-trained models:

import keras_segmentation

model = keras_segmentation.pretrained.pspnet_50_ADE_20K() 
out = model.predict_segmentation(
    inp="input_image.jpg",
    out_fname="out.png"
)
ImportError                               Traceback (most recent call last)
<ipython-input-22-1a69a6bbd448> in <module>
      1 print(keras.__version__)
----> 2 model = keras_segmentation.pretrained.pspnet_50_ADE_20K()

~/anaconda3/lib/python3.7/site-packages/keras_segmentation/pretrained.py in pspnet_50_ADE_20K()
     44     latest_weights =  keras.utils.get_file( "pspnet50_ade20k.h5" , model_url  )
     45 
---> 46     return model_from_checkpoint_path( model_config , latest_weights  )
     47 
     48 

~/anaconda3/lib/python3.7/site-packages/keras_segmentation/pretrained.py in model_from_checkpoint_path(model_config, latest_weights)
      7 def model_from_checkpoint_path( model_config , latest_weights  ):
      8 
----> 9         model = model_from_name[ model_config['model_class']  ]( model_config['n_classes'] , input_height=model_config['input_height'] , input_width=model_config['input_width'] )
     10         model.load_weights(latest_weights)
     11         return model

~/anaconda3/lib/python3.7/site-packages/keras_segmentation/models/pspnet.py in pspnet_50(n_classes, input_height, input_width)
    103 
    104 def pspnet_50( n_classes ,  input_height=473, input_width=473 ):
--> 105     from ._pspnet_2 import _build_pspnet
    106 
    107     nb_classes = n_classes

~/anaconda3/lib/python3.7/site-packages/keras_segmentation/models/_pspnet_2.py in <module>
     10 from keras.optimizers import SGD
     11 
---> 12 from keras.backend import tf as ktf
     13 import tensorflow as tf
     14 

ImportError: cannot import name 'tf' from 'keras.backend' (/home/alex/anaconda3/lib/python3.7/site-packages/keras/backend/__init__.py)
@divamgupta
Copy link
Owner

Which keras version are you using. It should work fine with keras 2.0.0

@alexst07
Copy link
Author

alexst07 commented Oct 8, 2019

keras version: 2.3.0

@divamgupta
Copy link
Owner

This has been fixed recently. Please install the latest master commit of this repo.

@sainatarajan
Copy link

If anyone else is having this issue, just install via pip using this command: pip install git+https://github.com/divamgupta/image-segmentation-keras.git

@aviaisr
Copy link

aviaisr commented Jan 6, 2020

I'm still getting this issue.
I'm working with Keras 2.2.5 and the latest master (06/01/2020).

@davidADSP
Copy link

davidADSP commented Mar 1, 2020

Works with

tensorflow==2.1.0
keras==2.3.1
keras-segmentation==0.3.0

pip install keras-segmentation gives version 0.2.0 which is showing errors - use
pip install git+https://github.com/divamgupta/image-segmentation-keras.git instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants