AttributeError: module tensorflow has no attribute placeholder

52

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

#replace import tensorflow as tf by following
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

AttributeError: module 'tensorflow' has no attribute 'placeholder' site:stackoverflow.com -

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

module 'tensorflow' has no attribute 'placeholder' tf 2.0 -

change the <tf.placeholder> as <tf.compat.v1.placeholder>

such as

x = tf.placeholder(shape = [None, image_pixels], dtype = tf.float32)
change as

x = tf.compat.v1.placeholder(shape = [None, image_pixels], dtype = tf.float32)
but there would be another problem about runtime error with eager execution add <tf.compat.v1.disable_eager_execution()> after import part

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

Comments

Submit
0 Comments