I'm a beginner at python, but I can't get rid of the error.
The code is
import tensorflow as tf
a = tf.constant (3.0, tf.float32)
b = tf.constant (2.0, tf.float32)
x = tf.placeholder(tf.float32)
y = a * x + b
sess=tf.Session()
print(sess.run(y, {x:[0,1,2,3]}))
The error content is
module'tensorflow'has no attribute'placeholder'
I am using a mac and python is 3.7
tensorflow will be 2.0.0
python tensorflow
Workaround 1: Import v1 and disable v2.
import tensorflow.compat.v1astf
tf.disable_v2_behavior()
Workaround 2: Replace with v2 code.
import tensorflow as tf
a = tf.constant (3.0, tf.float32)
b = tf.constant (2.0, tf.float32)
def(x):
return a*x+b
print(f([0,1,2,3]))
対策Measures 1 and 2 only apply one or the other.
Workaround: Replace the filename.
mv tensorflow.py example.py
Ref: https://stackoverflow.com/questions/37383812/tensorflow-module-object-has-no-attribute-placeholder
© 2024 OneMinuteCode. All rights reserved.