2016-11-13 69 views
0

我正嘗試使用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類型: '名單'

回答

0

那麼,錯誤是相當自我描述。

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

相關問題