Python 指出模块'tensorflow'缺少属性'placeholder'
发布时间
阅读量:
阅读量
在TensorFlow框架中,placeholder被定义为一种占位符节点,通过调用placeholder方法进行创建。它本质上属于常量类别,但与constant不同之处在于,其数值并非直接内嵌于计算图中,而是由用户在执行run方法时动态传入。因此,可以将placeholder类比为函数中的形式参数,在使用过程中需要外部提供具体的常数值才能完成计算过程。
x = tf.placeholder(tf.int32, [batch_size, num_steps], name='input_placeholder')
y = tf.placeholder(tf.int32, [batch_size, num_steps], name='output_placeholder')
结果报错:
Module 'tensorflow' 缺少属性 'placeholder' 的错误提示
解决方法:
【Tensorflow 1.x 版本中包含placeholder模块,但在2.0版本中该功能尚未被集成。
为此,可将Tensorflow版本切换回1.x以满足需求。
用户评论区解决方案更新
import tensorflow as tf
全部评论 (0)
还没有任何评论哟~
