Python 报错 AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
placeholder是TensorFlow的占位符节点,由placeholder方法创建,其也是一种常量,但是由用户在调用run方法是传递的,也可以将placeholder理解为一种形参。即其不像constant那样直接可以使用,需要用户传递常数值。
输入:
x = tf.placeholder(tf.int32, [batch_size, num_steps], name='input_placeholder')
y = tf.placeholder(tf.int32, [batch_size, num_steps], name='output_placeholder')
结果报错:
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’
解决方法:
Tensorflow 1.x 版本提供placeholder,而 2.0版本暂时没有这个模块。
因此把Tensorflow 换回 1.x版本即可。
(2020.10.27更新)评论区@末得名字 提供的解决方法:
不要使用:
import tensorflow as tf
替换为:
import tensorflow.compat.v1 as tf tf.disable_v2_behavior()
还没有评论,来说两句吧...