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

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike' #6177

Closed
Tahiya31 opened this issue Feb 9, 2019 · 17 comments
Assignees
Labels
stat:awaiting response Waiting on input from the contributor type:support

Comments

@Tahiya31
Copy link

Tahiya31 commented Feb 9, 2019

Hi,

I am using Keras with Tensorflow backend to build and run autoencoder. I am having this error, when I use autoencoder to predict:

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'
screen shot 2019-02-08 at 5 38 38 pm

I have already made sure I am running python 3.7 in my notebook. I created a virtual environment and used pip to install all my packages and they are all properly imported, but the error is still there.

Can you please help?

@tensorflowbutler tensorflowbutler added the stat:awaiting response Waiting on input from the contributor label Feb 10, 2019
@tensorflowbutler
Copy link
Member

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

@Tahiya31
Copy link
Author

Tahiya31 commented Feb 11, 2019

Thanks a lot for your response! Please find the following information:
What is the top-level directory of the model you are using:
I am using Tensorflow as backend for keras

Have I written custom code:
Keras autoencoder code from https://blog.keras.io/building-autoencoders-in-keras.html

OS Platform and Distribution:
MacOS High Sierra version 10.13.6

TensorFlow installed from: Using Conda
TensorFlow version: Version 1.10.0

Bazel version: N/A
CUDA/cuDNN version: N/A

GPU model and memory: Using CPU (8GB)

Exact command to reproduce:

from keras.layers import Input, Dense from keras.models import Model

this is the size of our encoded representations
encoding_dim = 32 # 32 floats -> compression of factor 24.5, assuming the input is 784 floats

this is our input placeholder
input_img = Input(shape=(784,))
"encoded" is the encoded representation of the input
encoded = Dense(encoding_dim, activation='relu')(input_img)
"decoded" is the lossy reconstruction of the input
decoded = Dense(784, activation='sigmoid')(encoded)

this model maps an input to its reconstruction
autoencoder = Model(input_img, decoded)

Running the above code gives me following error:
screen shot 2019-02-10 at 10 00 40 pm

I will highly appreciate any help! Thank you!

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Waiting on input from the contributor label Feb 12, 2019
@ymodak
Copy link
Contributor

ymodak commented Feb 14, 2019

I suspect its due to lower keras and/or tensorflow versions. Can you please try to execute your code using google.colab.sandbox?
You can use pip to install latest version of tensorflow and test your code.
I tried the link you referenced in the issue and it works fine in google colab using latest tensorflow build.
Let me know if this works for you too. Thanks!

@ymodak ymodak self-assigned this Feb 14, 2019
@ymodak ymodak added stat:awaiting response Waiting on input from the contributor type:support labels Feb 14, 2019
@Tahiya31
Copy link
Author

Thanks a lot for your response! I eventually started using Amazon Web Service and having no issue to run my code there.
In my local machine, it still gives an error (although I have upgraded Keras + TensorFlow).

@greysou1
Copy link

I have the same issue with the command that you're using. Works fine on Googe Colab but doesn't work locally. I'm using TF2.0

@viswanath27
Copy link

I am also facing same issue, is there any fix/work around for the issue.

below is the call trace.

Using TensorFlow backend.
2020-04-14 22:25:45.655322: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
Traceback (most recent call last):
File "src/train.py", line 3, in
my_model = create_model()
File "/home/sandbox/vissu/diabetic_retenopathy/model_1/keras-cnn/src/model/cnn.py", line 27, in create_model
activation='relu', use_bias=True, strides=1, padding='same'))
File "/usr/local/lib/python3.6/dist-packages/keras/engine/sequential.py", line 166, in add
layer(x)
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 76, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 446, in call
self.assert_input_compatibility(inputs)
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 310, in assert_input_compatibility
K.is_keras_tensor(x)
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 696, in is_keras_tensor
if not is_tensor(x):
File "/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py", line 704, in is_tensor
return isinstance(x, tf_ops._TensorLike) or tf_ops.is_dense_tensor_like(x)
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

this is very urgent issue, any help here is appreciated

@viswanath27
Copy link

also keras version is
keras in /usr/local/lib/python3.6/dist-packages (2.3.1)
Tensorflow Version is 2.2.0-dev20200409

@moodyrashid
Copy link

In local machine, could you please try with
from tensorflow.keras.layers import ... instead of from keras.layers import ....

@Saqueeb
Copy link

Saqueeb commented Jun 13, 2020

I am having this issue in google colab...
My code is following:

_model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)

model.load_weights(COCO_MODEL_PATH, by_name=True)_

and the error is:
AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

Any help would be appreciated!

@HarshiniVenkat
Copy link

Same error.

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

How do you overcome it?

@dgks0n
Copy link

dgks0n commented Jul 29, 2020

@HarshiniVenkat You should do as below

from tensorflow.keras.layers import ... instead of from keras.layers import ....

@shakibyzn
Copy link

I am having an issue on Google Colab

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

My Keras version is 2.3.1 and I have to stick with this version although I know that it can be solved by upgrading to an upper version such as 2.4.3

Could anyone help me, please?

@udaylunawat
Copy link

I am having an issue on Google Colab

AttributeError: module 'tensorflow.python.framework.ops' has no attribute '_TensorLike'

My Keras version is 2.3.1 and I have to stick with this version although I know that it can be solved by upgrading to an upper version such as 2.4.3

Could anyone help me, please?

Did you resolve it by any chance?

@leandron
Copy link

As mentioned by others, it looks like it is fixed on keras ==2.4.3.

(just in case you are here from search results)

@osmancakir
Copy link

I am still having the issue with keras==2.4.3

@leandron
Copy link

leandron commented Nov 2, 2020

It is out of scope here, but there is an issue with a recently released h5py, that required me to pin it, like this: keras==2.4.3 "h5py<3.0". Maybe that works for you as well.

@MUKESHBADIGINENI
Copy link

It is out of scope here, but there is an issue with a recently released h5py, that required me to pin it, like this: keras==2.4.3 "h5py<3.0". Maybe that works for you as well.

I tried this either, but still, the issue is the same. you can see my prompt info regarding its installation, next to that is the screenshot of my jupyter notebook.

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response Waiting on input from the contributor type:support
Projects
None yet
Development

No branches or pull requests