Tensorflow中的InvalidArgumentError
问题描述:
我正尝试使用Tensorflow工具创建神经网络。Tensorflow中的InvalidArgumentError
sizeOfRow = len(data[0])
x = tensorFlow.placeholder("float", shape=[None, sizeOfRow])
y = tensorFlow.placeholder("float")
def neuralNetworkTrain(x):
prediction = neuralNetworkModel(x)
# using softmax function, normalize values to range(0,1)
cost = tensorFlow.reduce_mean(tensorFlow.nn.softmax_cross_entropy_with_logits(prediction, y))
这是从网上 部分我有错误:
InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[500,2] labels_size=[1,500]
[[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape, Reshape_1)]]
有人知道什么`错了吗?
编辑: 也是我从这段代码有:
for temp in range(int(len(data)/batchSize)):
ex, ey = takeNextBatch(i) # takes 500 examples
i += 1
# TO-DO : fix bug here
temp, cos = sess.run([optimizer, cost], feed_dict= {x:ex, y:ey})
此错误 类型错误:unhashable类型: '名单'
答
那么,错误是相当自我描述。
logits and labels must be same size: logits_size=[500,2] labels_size=[1,500]
因此,首先,你的标签应换位有大小500, 1
第二,softmax_cross_entropy_with_logits预计labels
在一个概率分布(例如,[[0.1, 0.9], [1.0, 0.0]]
)的形式呈现。
如果你知道你的课程是独占的(可能是这种情况),你应该切换到使用sparse_softmax_cross_entropy_with_logits。