[英]Multilayer perceptron with target variable as array instead of a single value
我是深度學習的新手,我一直在嘗試使用theano庫來訓練我的數據。 這里的MLP教程有一個標量輸出值,而我的用例有一個數組,其中1對應於輸出中描述的值。
例如(假設可能的標量值為0,1,2,3,4,5),
0 = [1,0,0,0,0,0]
1 = [0,1,0,0,0,0]
2 = [0,0,1,0,0,0]
我只修改了代碼來讀取我的輸入和輸出(現在輸出是theano的用法中的二維數組或矩陣)。 代碼的其他部分與上面粘貼的MLP教程相同。
我得到的錯誤在以下函數中
test_model = theano.function(inputs=[index],
outputs=classifier.errors(y),
givens={
x: test_set_x[index * batch_size:(index + 1) * batch_size],
y: test_set_y[index * batch_size:(index + 1) * batch_size]}) //line 286
錯誤堆棧:
Traceback (most recent call last):
File "mlp.py", line 398, in <module>
test_mlp()
File "mlp.py", line 286, in test_mlp
y: test_set_y[index * batch_size:(index + 1) * batch_size]})
File "/usr/local/lib/python2.7/dist-packages/theano/compile/function.py", line 223, in function
profile=profile)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 490, in pfunc
no_default_updates=no_default_updates)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 241, in rebuild_collect_shared
cloned_v = clone_v_get_shared_updates(outputs, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 92, in clone_v_get_shared_updates
clone_a(v.owner, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 131, in clone_a
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 92, in clone_v_get_shared_updates
clone_a(v.owner, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 131, in clone_a
clone_v_get_shared_updates(i, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 92, in clone_v_get_shared_updates
clone_a(v.owner, copy_inputs_over)
File "/usr/local/lib/python2.7/dist-packages/theano/compile/pfunc.py", line 135, in clone_a
strict=rebuild_strict)
File "/usr/local/lib/python2.7/dist-packages/theano/gof/graph.py", line 213, in clone_with_new_inputs
new_inputs[i] = curr.type.filter_variable(new)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/type.py", line 205, in filter_variable
self=self)<br><br>
TypeError: Cannot convert Type TensorType(int64, matrix) (of Variable Subtensor{int64:int64:}.0) into Type TensorType(int32, vector). You can try to manually convert Subtensor{int64:int64:}.0 into a TensorType(int32, vector).
我想知道如何更改此theano.function以適應y值作為矩陣。
您需要將y
定義為T.imatrix()
而不是T.lvector()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.