You need to log in to create posts and topics.

[SOLVED] - AttributeError: module 'tensorflow' has no attribute 'placeholder'

The cause of the mentioned problem is incompatibile code with installed tensorflow library. In this case you have code compatible with tensorflow 1.0 version but installed tensorflow 2.0 or higher. Let's see what you can do to solve the problem.

Solution 1. Follow tensorflow migration guide

Migrate your code following this guide. Solution for the title problem is to use variables instead of placeholders. Let's see the following example:


[adinserter block="1"]

#tensorflow 1.x
self._states = tf.placeholder(shape=[None, self._num_states], dtype=tf.float32)

#tensorflow 2.x
self._states = tf.Variable(tf.ones(shape=[None, self._num_states]), dtype=tf.float32)

Solution 2. Use tensorflow 1.x compatibility mode

The second approach is to use tensorflow v1 copatiblity mode. To dot his you have to use import tensorflow.compat.v1 as tf instead of import tensorflow as tf and add tf.disable_v2_behavior().

import tensorflow as tf

x = tf.placeholder(shape=[None, 2], dtype=tf.float32)

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()
x = tf.placeholder(shape=[None, 2], dtype=tf.float32)