ImportError: cannot import name 'tf' from 'keras.backend'
See original GitHub issueI 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)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ImportError: cannot import name 'backend' - Stack Overflow
I encounter an ImportError when importing backend from keras from keras import backend. The output is. Using TensorFlow backend.
Read more >How to avoid KERAS import errors in your notebooks - Kaggle
Recently I had an issue while importing KERAS libraries with issues such as. ImportError: cannot import name 'is_tf_type' from ...
Read more >cannot import name get_config from tensorflow.python.eager ...
importerror: cannot import name get_config from tensorflow.python.eager.context error occurs because of incompatibility of keras module.
Read more >Error using tensorflowjs_converter (ImportError: cannot import ...
Error using tensorflowjs_converter (ImportError: cannot import name model_fn) ... in <module> from tensorflow.contrib.tpu.python.tpu.keras_support import ...
Read more >cannot import name 'export_saved_model - 腾讯云开发者社区
Import Error : cannot import name 'export_saved_model ... install\lib\site-packages\keras\backend\__init__.py", line 1, in <module> from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Works with
pip install keras-segmentation
gives version 0.2.0 which is showing errors - usepip install git+https://github.com/divamgupta/image-segmentation-keras.git
instead