我正试图将列表传入feed_dict,但是我很难这样做.说我有:
inputs = 10 * [tf.placeholder(tf.float32, shape=(batch_size, input_size))]
Run Code Online (Sandbox Code Playgroud)
输入被输入到outputs我想要计算的某个函数中.所以要在tensorflow中运行它,我创建了一个会话并运行以下内容:
sess.run(outputs, feed_dict = {inputs: data})
#data is my list of inputs, which is also of length 10
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,TypeError: unhashable type: 'list'.
但是,我能够像这样传递数据元素:
sess.run(outputs, feed_dict = {inputs[0]: data[0], ..., inputs[9]: data[9]})
Run Code Online (Sandbox Code Playgroud)
所以我想知道是否有办法解决这个问题.我也尝试构建一个字典(使用for循环),但是这会产生一个包含单个元素的字典,其中键是:
tensorflow.python.framework.ops.Tensor at 0x107594a10
我正在查看Tensorflow的机制部分,特别是关于共享变量的部分.在"问题"部分,他们正在处理卷积神经网络,并提供以下代码(通过模型运行图像):
# First call creates one set of variables.
result1 = my_image_filter(image1)
# Another set is created in the second call.
result2 = my_image_filter(image2)
Run Code Online (Sandbox Code Playgroud)
如果模型是以这种方式实现的,那么学习/更新参数是不可能的,因为我的训练集中的每个图像都有一组新的参数?
编辑:我也在一个简单的线性回归示例中尝试了"问题"方法,并且这种实现方法似乎没有任何问题.训练似乎也可以在代码的最后一行显示.所以我想知道tensorflow文档中是否存在微妙的差异以及我正在做什么.:
import tensorflow as tf
import numpy as np
trX = np.linspace(-1, 1, 101)
trY = 2 * trX + np.random.randn(*trX.shape) * 0.33 # create a y value which is approximately linear but with some random noise
X = tf.placeholder("float") # create symbolic variables
Y = tf.placeholder("float")
def model(X):
with tf.variable_scope("param"): …Run Code Online (Sandbox Code Playgroud)