python - 您必须使用 dtype float 和 shape [2,2] 为占位符张量“Placeholder”提供一个值
问题描述
我有错误。我You must feed a value for placeholder tensor 'Placeholder' with dtype float and shape [2,2]
已经喂了占位符aa
import numpy as np
import tensorflow as tf
aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(bb,feed_dict={aa:np.random.rand(2,2)}))
解决方案
问题出在sess.run(init)
;你需要一个值aa
来初始化bb
. aa
但是,以后不需要检索bb
,因为它已经被分配了一个值。
import numpy as np
import tensorflow as tf
aa = tf.placeholder(dtype=tf.float32, shape=(2, 2))
bb = tf.Variable(aa)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init, feed_dict={aa: np.random.rand(2, 2)})
print(sess.run(bb))
推荐阅读
- php - SOAP API:PHP 代码不起作用,但 SOAP UI 起作用
- reactjs - 成功验证后导航到主屏幕不起作用
- ios - Swift Firebase 选择 UITableView 原型单元 - UI 问题
- powershell - 如何循环直到没有 IE 进程正在运行
- javascript - 使用缩小的 script.js 及其源映射 .js.map 来恢复原始源代码
- mysql - mysql间隙和孤岛在记录之前更改记录时间
- python - 对张量进行矢量化操作,而不是在 keras 自定义损失函数中使用 for 循环
- arrays - Golang 子切片
- javascript - 如何将字母数字字符串拆分为数字和字符?
- drop-down-menu - iOS DropDown CocoaPod