簡體   English   中英

Tensorflow中的InvalidArgumentError

[英]InvalidArgumentError in Tensorflow

我正在嘗試使用Tensorflow工具創建神經網絡。

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}) 

此錯誤TypeError:無法散列的類型:'list'

好吧,該錯誤是自描述的。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM