raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.97k stars 664 forks source link

ImportError: cannot import name '_Conv' from 'keras.layers.convolutional' #228

Open mperini opened 4 years ago

mperini commented 4 years ago

Hi, after a fresh installation of keras-vis using pip install -U -I git+https://github.com/raghakot/keras-vis.git I try to import Keras by running import keras and encounter the following error: ImportError: cannot import name '_Conv' from 'keras.layers.convolutional'.

As backend for Keras I'm using Tensorflow version 2.2.0. As far as I understood the _Conv class is only available for older Tensorflow versions. I've tried to downgrade to Tensorflow 1.15.0, but then I encounter compatibility issues using Keras 2.0, as required by keras-vis.

Has anybody else encountered this issue? Is there a workaround?

techsharma2000 commented 4 years ago

Yes , I also encounter same issue but not sure what to do

vhu147 commented 3 years ago

I also encounter same issue

darinmandarin commented 3 years ago

Same here...

leilah92 commented 3 years ago

same problem. it was ok a month ago.

any solution? :(

TomohisaOgawaKEK commented 3 years ago

need help

bersbersbers commented 3 years ago

This project seems to stale, see https://github.com/raghakot/keras-vis/issues/221#issuecomment-662279588

vladimircape commented 3 years ago

That's why people start to migrate to Pytorch

shakibyzn commented 3 years ago

Any help?

bersbersbers commented 3 years ago

This project seems to be stale, see #221 (comment)

AniketSawale commented 3 years ago

Sorry for late reply.

Try this: pip install keras==2.2.2 & pip install tensorflow==1.10.0

Let me know, the solution worked or not

singhsukhendra commented 3 years ago

It is working now. Thanks, A lot!!!

shakibyzn commented 3 years ago

It also works for me although I have to make some changes to my code. I also used Keras 2.2.2 with TensorFlow 2.0 and it was okay too. However, I moved my code to tf.keras and used the method provided in the official Keras documentation and it works like a charm:)

mubeenmeo344 commented 3 years ago

Sorry for late reply.

Try this: pip install keras==2.2.2 & pip install tensorflow==1.10.0

Let me know, the solution worked or not

It also works for me although I have to make some changes to my code. I also used Keras 2.2.2 with TensorFlow 2.0 and it was okay too. However, I moved my code to tf.keras and used the method provided in the official Keras documentation and it works like a charm:)

I also have save issue of can't import '_Conv', but my problem is not solved by Keras 2.2.2 and TensorFlow 2.0. Can you guide me further, what will be the solution without downgrading Tensorflow. Or can you kindly share your code and environment details.

jmajumde commented 3 years ago

_Conv method not available with later version keras 2.4, the way to solve this is use Conv2D API. You can update the saliency.py module as I did below

$ diff visualization/saliency.py visualization/saliency.py.org 
5,6c5
< #from scipy.misc import imresize
< import cv2
---
> from scipy.misc import imresize
8,9c7,8
< from keras.layers.convolutional import Conv2D
< from keras.layers.pooling import MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D 
---
> from keras.layers.convolutional import _Conv
> from keras.layers.pooling import _Pooling1D, _Pooling2D, _Pooling3D
32c31
<             if isinstance(layer, (Conv2D, MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D)):
---
>             if isinstance(layer, (_Conv, _Pooling1D, _Pooling2D, _Pooling3D)):
187,189c186
<     #heatmap = imresize(heatmap, input_dims, interp='bicubic', mode='F')
<     heatmap = cv2.resize(src=heatmap, dsize=input_dims,interpolation=cv2.INTER_CUBIC) 
< 
---
>     heatmap = imresize(heatmap, input_dims, interp='bicubic', mode='F')
makquel commented 3 years ago

@jmajumde did you update your tensorflow_backend.py file as well?

tiagoyuzo commented 3 years ago

@jmajumde did you update your tensorflow_backend.py file as well?

I am having the same problem and would like to ask the same question. Do I need to update tensorflow_backend.py @jmajumde ?

ind-kum commented 3 years ago

Try this: pip install keras==2.2.2 & pip install tensorflow==1.14.0

solved my issue... installed in Colab

sciPher80s commented 3 years ago

try this: my version, got from pip list tensorflow 2.4.1 keras 2.4.3 keras-vis 0.5.0

change following lines in saliency.py from Python38\Lib\site-packages\vis\visualization\ 6 from keras.layers.convolutional import Conv2D 7 from keras.layers.pooling import MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D and 33 if isinstance(layer, (Conv2D, MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D)):

still if you want to use functions like visualize_saliency you may probably get other errors like keras.backend has no attribute identity; which are really hard to solve with current versions of tensorflow and keras, at least I spent ~ 2h and in my case it doesn't worth anymore.

This lib is far behind the current changes, consider using tf_keras_vis or other visualization libs.

Defcon27 commented 2 years ago

try this: my version, got from pip list tensorflow 2.4.1 keras 2.4.3 keras-vis 0.5.0

change following lines in saliency.py from Python38\Lib\site-packages\vis\visualization\ 6 from keras.layers.convolutional import Conv2D 7 from keras.layers.pooling import MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D and 33 if isinstance(layer, (Conv2D, MaxPooling1D, MaxPooling2D, AveragePooling1D, AveragePooling2D)):

still if you want to use functions like visualize_saliency you may probably get other errors like keras.backend has no attribute identity; which are really hard to solve with current versions of tensorflow and keras, at least I spent ~ 2h and in my case it doesn't worth anymore.

This lib is far behind the current changes, consider using tf_keras_vis or other visualization libs.

Yes, tf_keras_vis is great! Thanks for the suggestion