I've been trying to use tensorflow for two days now installing and reinstalling it over and over again in python2.7 and 3.4. No matter what I do, I get this error message when trying to use tensorflow.placeholder()
It's very boilerplate code:
tf_in = tf.placeholder("float", [None, A]) # Features
No matter what I do I always get the trace back:
Traceback (most recent call last): File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 2, in <module> import tensorflow as tf File "/home/willim/PycharmProjects/tensorflow/tensorflow.py", line 53, in <module> tf_in = tf.placeholder("float", [None, A]) # Features AttributeError: 'module' object has no attribute 'placeholder'
Anyone know how I can fix this?
The AttributeError: module 'tensorflow' has no attribute 'placeholder' occurs when you try to use a placeholder in TensorFlow 2.0. placeholder is part of the TF1. x API. To solve this error, you can either migrate to TensorFlow 2.0 and use tf.
The problem is with TensorFlow version; the one you are running is 2.0 or something above 1.5 , while placeholder can only work with 1.4 .
A placeholder is simply a variable that we will assign data to at a later date. It allows us to create our operations and build our computation graph, without needing the data. In TensorFlow terminology, we then feed data into the graph through these placeholders.
tf. compat allows you to write code that works both in TensorFlow 1.
If you have this error after an upgrade to TensorFlow 2.0, you can still use 1.X API by replacing:
import tensorflow as tf
by
import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With