theislab / scgen

Single cell perturbation prediction
https://scgen.readthedocs.io
GNU General Public License v3.0
260 stars 52 forks source link

AttributeError: module 'tensorflow' has no attribute 'placeholder' #14

Closed cartal closed 4 years ago

cartal commented 4 years ago

Hi guys,

I had to upgrade my tensorflow to re-install diffxpy and this seems to have broken my scGen: I've got the AttributeError: module 'tensorflow' has no attribute 'placeholder'`.

I'm trying to find a workaround this, but it seems that it's something that scGen will have to fix at some point? Do you have any recommendations?

Thanks in advance!

cartal commented 4 years ago

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

Kaarthic29 commented 4 years ago

Hi,

Even I face the same AttributeError: module 'tensorflow' has no attribute 'placeholder' issue with tensorflow version 2.0

Any leads or workaround for this is greatly appreciated.

M0hammadL commented 4 years ago

Hi @cartal and @Kaarthic29, We will eventually update to tf2 but currently I am super busy with other stuff. The current and safest option is to use tf <2.0 for now. We will have a new release when we update it and also add trVAE.

Mo

Kaarthic29 commented 4 years ago

Thanks @M0hammadL , as of now i have used tf.compat.v1 to solve that placeholder error in tf v2.0

LaylaUJ commented 4 years ago

AttributeError: module 'tensorflow' has no attribute 'placeholder' can any one please tell me how to solve this error message

Kiran995 commented 4 years ago

If you are using tf v2.0. tf v2.0 does not seems to have placeholder(), .reset_default_graph(). You can find more information here: https://www.tensorflow.org/guide/effective_tf2

mikeyEcology commented 4 years ago

I solved this and several other incompatibilities in my code by going back to tensorflow version 1: pip install tensorflow==1.4

g1ave commented 4 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

botbark commented 4 years ago

This error may come if you have installed TensorFlow 2.0 and want to run code that is not compatible with TensorFlow 2.0

For example if you are trying to run below code, you will get the above error. Please check the below post.

https://botbark.com/2019/12/18/attributeerror-module-tensorflow-has-no-attribute-placeholder-tensorflow-2-0/

kaungsoethar commented 4 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

It works well Thank you ^_^

yannis1962 commented 4 years ago

I re-installed tensorflow==1.15.2 and it worked (otherwise rasa-nlu wouldn't work)

ghost commented 4 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

yeah it is working now

shariefimran commented 4 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

yeah it is working now

for me its not working

Gennaro-Farina commented 4 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

yeah it is working now

for me its not working

Hello sharifimran, for me what worked was to reinstall TF + Keras version I use. Try this combination: python -m pip install Keras==2.3.1 tensorflow==2.1.0

moschjoon commented 4 years ago

just remove the current version of tensorflow (using command: conda remove tensorflow), then install 1.15.0 using command: conda install tensorflow=1.15.0. it works

deepgupta06 commented 4 years ago

The same problem was happening to me...

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

it works..

RahulKamma0369 commented 4 years ago

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

well it worked for me

RahulKamma0369 commented 4 years ago

the error is because we are using tensorflow version 2 and the command is from version 1 so if we use tf.compat.v1.summary.(method_name) it'll work

sakshijain032 commented 4 years ago

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

It worked for me too. I was getting this error from this file site-packages\keras\backend\tensorflow_backend.py I used this code over there.

parva-jain commented 4 years ago

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

It is working for me but the thing is it is affecting other parts of my code so is there any solution within version 2

sakshijain032 commented 4 years ago

May I know what it's affecting

parva-jain commented 4 years ago

what these couple of line of codes does is disabling the version 2 of tensorflow but I'm using AdamOptimizer which have different syntax in different versions and executing those couple of line is affecting the version 2 syntax of AdamOptimizer.....I may not be so clear as I'm new tensorflow user but any help would be appreciated

On Sun, 3 May 2020 at 15:08, sakshijain032 notifications@github.com wrote:

May I know what it's affecting

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/theislab/scgen/issues/14#issuecomment-623082183, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANQRR7HCKN3QSG37C2FULJLRPU3QFANCNFSM4I7MJCCA .

cu2uyash commented 4 years ago

pip install tensorflow==1.4 will work as it has placeholder attribute

Gooogr commented 4 years ago

If you use Keras try change your import from keras.name_of_class to tensorflow.keras.name_of_class

qinchaofeng commented 4 years ago

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

I was using tf(2.0.0-alpha0),python(Python 3.6.4) and it worked for me

amansani commented 4 years ago

just remove the current version of tensorflow (using command: conda remove tensorflow), then install 1.15.0 using command: conda install tensorflow=1.15.0. it works

This worked for me. Thanks.

mikechen66 commented 4 years ago

The following lines of code do not work in the environment of TensorFlow 2.2 and Keras 2.4.3

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

or

import tensorflow.compat.v1 as tf
tf.compat.v1.disable_eager_execution()

AttributeError: module 'tensorflow' has no attribute 'placeholder'

However, the following line code works effectively.

tf.compat.v1.placeholder()
kountaydwivedi commented 4 years ago

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

This worked for me. image

bm777 commented 4 years ago

Hi @cartal and @Kaarthic29, We will eventually update to tf2 but currently I am super busy with other stuff. The current and safest option is to use tf <2.0 for now. We will have a new release when we update it and also add trVAE.

Mo

Hi @M0hammadL Hope you are well. I have this same issue with TensorFlow 2.1.0, I don't know if you finally found an alternative to use a placeholder in tf2 without disabling tf2.behavior? Thank for advance

DilipKarki commented 4 years ago

The below worked for a similar problem i was facing. I tried going back to a previous version but couldn't. Now i have v2.3 working with the below: 1) Used upgrade script to change all my old files to v2 - https://www.tensorflow.org/guide/upgrade 2) After that there was still an issue which got fixed with this line (from suggestion few posts above here) tf.compat.v1.disable_eager_execution()

ParasGeeek commented 3 years ago

import tensorflow.compat.v1 as tf tf.compat.v1.disable_eager_execution() It is working for me

prataplyf commented 3 years ago

It

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

Damm.... It works for me too, great

alitokur commented 3 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

its still working.

Bryson582 commented 3 years ago

Can somebody help me? import tensorflow.compat.v1 as tf tf.disable_v2_behavior() It reminds me that I

WARNING:tensorflow:From /Users/brycelee/PycharmProjects/MNST/venv/lib/python3.8/site-packages/tensorflow/python/compat/v2_compat.py:96: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term

And it tells me 'no module named compat'

alitokur commented 3 years ago

@Bryson582 which version of tensorflow do u use?

Bryson582 commented 3 years ago

@alitokur I am using Python 2.7.16 and tensorflow '2.3.1'

alitokur commented 3 years ago

@Bryson582 may the problem be your python version? tensorflow2 requires python 3.5–3.8, pip and venv >= 19.0

juiceboxjoe commented 3 years ago

import tensorflow.compat.v1 as tf tf.disable_v2_behavior()

working with Python3.7 and TF 2.3.1

monacv commented 3 years ago

@mikechen66 AttributeError: module 'tensorflow' has no attribute 'compact'

bm777 commented 3 years ago

@mikechen66 AttributeError: module 'tensorflow' has no attribute 'compact'

Check if your TensorFlow is well installed on your machine. try: import tensorflow

GP-Kulam commented 3 years ago
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

works. I am using Python 3.7 and tensorflow 2.0.

hey, where to place this code snippet, can u please mention?

alitokur commented 3 years ago

@GP-Kulam you can use like the following on the import part:

import numpy as np
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 
sshams514 commented 3 years ago

Hey I did that: import tensorflow.compat.v1 as tf tf.disable_v2_behavior() but it does not work. What else could be the problem?

bm777 commented 3 years ago

Print the error here.

sshams514 commented 3 years ago

@bm777: AttributeError: module 'tensorflow' has no attribute 'placeholder'

Thank you for your help!

bm777 commented 3 years ago

For me, you have two choices if you are using TensorFlow 2.x:

  1. use TensorFlow 2.x, by
    • import tensorflow.compat.v1 as tf and use tf in your code.
  2. Remove your current version of TensorFlow, and install 1.x TensorFlow version. pip uninstall tensorflow pip install tensorflow==1.7
sshams514 commented 3 years ago

@bm777 I tried that one too but I also use Keras in the code and for Keras tensorflow 2.2 is needed at least. Is there another solution?

bm777 commented 3 years ago

For better help, could you please, show a part of your code and plot the screenshot of your error here too.

xtSumit commented 3 years ago

Hi,

Even I face the same AttributeError: module 'tensorflow' has no attribute 'placeholder' issue with tensorflow version 2.0

Any leads or workaround for this is greatly appreciated. import tensorflow as tf tf.compat.v1.disable_eager_execution() us tf.compat.v1.placeholder

aditycahyap commented 3 years ago

The solution provided by the Tensorflow team on their website:

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior() 

doesn't seem to work either

module 'tensorflow.compat.v1' has no attribute 'contrib'