在 TensorFlow 中使用 feed_dict 将值提供给变量 [英] Feeding values to a Variable using feed_dict in TensorFlow

查看:33
本文介绍了在 TensorFlow 中使用 feed_dict 将值提供给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 https://www.tensorflow.org/get_started/mnist/专业人士.阅读请注意,您可以使用 feed_dict 替换计算图中的任何张量——它不仅限于占位符",我尝试使用 feed_dict 为变量赋值,如下所示:

I'm through https://www.tensorflow.org/get_started/mnist/pros. Reading "Note that you can replace any tensor in your computation graph using feed_dict -- it's not restricted to just placeholders," I tried to give values to a Variable using feed_dict as follows:

print(accuracy.eval(feed_dict={x: mnist.test.images, y_: mnist.test.labels, 
                           W[:, :]: np.zeros((784, 10))}))

然而,它给出了原始准确度 0.9149(我预计约为 0.1).我可以在使用 feed_dict 初始化后为变量赋予常量值吗?

However, it gave the original accuracy 0.9149 (I expected around 0.1). Can I give constant values to Variables after initialization using feed_dict?

推荐答案

在您的回答中,您已经将常量零传递给 W ,这是一个变量.并在声明中说

In your answer you have already passed the constants zeros to W which is a variable. And in the statement that

请注意,您可以使用 feed_dict 替换计算图中的任何张量——它不仅限于占位符

Note that you can replace any tensor in your computation graph using feed_dict -- it's not restricted to just placeholders

您通过 feed_dict 传递到图中的所有内容都是(通常是 numpy)常量,因此您也可以获得肯定的答案.

All what you pass into the graph by feed_dict are (often numpy) constants, so you can also get a positive answer.

这篇关于在 TensorFlow 中使用 feed_dict 将值提供给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆