獲取輸出分類。 我從教程中獲得了這個特定的代碼以獲得預測的結果,並且我會生成一個csv文件發送給kaggle。 但與烤寬麪條,它不起作用。 我嘗試了幾件事情,但他們都給錯誤。獲取輸出分類與意大利千層麪/ Theano</p> <p>我遷移我的代碼從純Theano到意大利千層麪烤寬麪條
如果有人能幫助我判斷出了什麼問題,我會很樂意!
我粘貼整個代碼在這裏: http://pastebin.com/e7ry3280
test_data = np.loadtxt("../inputData/test.csv", dtype=np.uint8, delimiter=',', skiprows=1)
# The inputs are vectors now, we reshape them to monochrome 2D images,
# following the shape convention: (examples, channels, rows, columns)
data = data.reshape(-1, 1, 28, 28)
test_data = test_data.reshape(-1, 1, 28, 28)
index = T.lscalar() # index to a [mini]batch
preds = []
for it in range(len(test_data)):
test_data = test_data[it]
N = len(test_data)
# print "N : ", N
test_data = theano.shared(np.asarray(test_data, dtype=theano.config.floatX))
test_labels = T.cast(theano.shared(np.asarray(np.zeros(batch_size), dtype=theano.config.floatX)),'uint8')
###target_var
#y = T.ivector('y') # the labels are presented as 1D vector of [int] labels
#index = T.lscalar() # index to a [mini]batch
ppm = theano.function([index],lasagne.layers.get_output(network, deterministic=True),
givens={
input_var: test_data[index * batch_size: (index + 1) * batch_size],
target_var: test_labels
}, on_unused_input='warn')
p = [ppm(ii) for ii in range(N // batch_size)]
p = np.array(p).reshape((N, 10))
print (p)
p = np.argmax(p, axis=1)
p = p.astype(int)
preds.append(p)
subm = np.empty((len(preds), 2))
subm[:, 0] = np.arange(1, len(preds) + 1)
subm[:, 1] = preds
np.savetxt('submission.csv', subm, fmt='%d', delimiter=',',header='ImageId,Label', comments='')
return preds
上與ppm = theano.function...
開頭的行的代碼失敗:
TypeError: Cannot convert Type TensorType(float32, 3D) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(float32, 4D). You can try to manually convert Subtensor{int64:int64:}.0 into a TensorType(float32, 4D).
我只是想輸入的測試數據到CNN並將結果轉換爲CSV文件。我該怎麼做?我知道我必須使用minibatches,因爲整個測試數據不適合GPU。
該代碼完全在ppm行上失敗。 – KenobiShan
'test_data'的維度是什麼? 'input_var'是一個4D張量,所以'test_data'也必須是一個4D張量。此錯誤消息表明test_data是3D張量。 –
更新後。更多地解釋。 – KenobiShan