Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow, "'module' object has no attribute 'placeholder'"

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?

like image 466
user3023715 Avatar asked May 23 '16 06:05

user3023715


People also ask

How do I fix the module TensorFlow has no attribute placeholder?

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.

Which TensorFlow version has placeholder?

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 .

What is placeholder in TensorFlow?

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.

What is TF compat v1?

tf. compat allows you to write code that works both in TensorFlow 1.


1 Answers

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() 
like image 64
u2gilles Avatar answered Sep 30 '22 18:09

u2gilles