【发布时间】:2016-08-13 23:26:29
【问题描述】:
我在执行训练时尝试输入包含正确标签的张量。
整个训练数据集的正确标签包含在一个从 numpy 数组转换而来的张量中:
numpy_label = np.zeros((614,5),dtype=np.float32)
for i in range(614):
numpy_label[i,label_numbers[i]-1] = 1
# Convert to tensor
y_label_all = tf.convert_to_tensor(numpy_label,dtype=tf.float32)
我有一个占位符用于每个批次的正确标签:
images_per_batch = 5
y_label = tf.placeholder(tf.float32,shape=[images_per_batch,5])
在每个训练步骤中,我将y_label_all 的相应部分切片为y_,并希望将其输入为y_label:
for step in range(100):
# Slice correct labels for current batch
y_ = tf.slice(y_label_all,[step,0],[images_per_batch,5])
# Train
_, loss_value = sess.run([train_step,loss],feed_dict={y_label:y_})
这会产生错误:
_, loss_value = sess.run([train_step,loss],feed_dict={y_label:y_})
File "/usr/local/lib/python2.7/dist- packages/tensorflow/python/client/session.py", line 357, in run
np_val = np.array(subfeed_val, dtype=subfeed_t.dtype.as_numpy_dtype)
ValueError: setting an array element with a sequence.
变量y_和y_label的形状:
#y_:
Tensor("Slice:0", shape=TensorShape([Dimension(5), Dimension(5)]), dtype=float32)
#y_label:
Tensor("Placeholder:0", shape=TensorShape([Dimension(5), Dimension(5)]), dtype=float32)
我不明白出了什么问题?显然这与 numpy 有关 - 但现在我已将 numpy 数组转换为张量,这会影响什么吗?
非常感谢您的帮助和洞察力。谢谢!
【问题讨论】:
-
我们缺少一些指定“值”类型的文档,应该在github.com/tensorflow/tensorflow/issues/2051中修复
标签: python arrays numpy tensorflow