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 '_Conv' from 'keras.layers.convolutional' #228

Open
3 of 4 tasks
mperini opened this issue Jun 25, 2020 · 19 comments
Open
3 of 4 tasks

Comments

@mperini
Copy link

mperini commented Jun 25, 2020

  • Check that you are up-to-date with the master branch of keras-vis. You can update with:
    pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps

  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • 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

  • 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).

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
Copy link

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

@vhu147
Copy link

vhu147 commented Jul 8, 2020

I also encounter same issue

@darinmandarin
Copy link

Same here...

@leilah92
Copy link

same problem.
it was ok a month ago.

any solution? :(

@TomohisaOgawaKEK
Copy link

need help

@bersbersbers
Copy link

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

@vladimircape
Copy link

That's why people start to migrate to Pytorch

@shakibyzn
Copy link

Any help?

@bersbersbers
Copy link

bersbersbers commented Aug 6, 2020

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

@AniketSawale
Copy link

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
Copy link

singhsukhendra commented Aug 11, 2020

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

@shakibyzn
Copy link

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
Copy link

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
Copy link

jmajumde commented Oct 14, 2020

_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
Copy link

makquel commented Dec 22, 2020

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

@tiagoyuzo
Copy link

@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
Copy link

ind-kum commented May 20, 2021

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

solved my issue...
installed in Colab

@sciPher80s
Copy link

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
Copy link

Defcon27 commented Oct 3, 2021

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

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