7
我試圖在CNTK中實現一個LSTM(使用Python)來對一個序列進行分類。CNTK在LSTM中抱怨動態軸
輸入:
-
號碼
特點是固定長度的序列(時間序列)
標籤是獨熱值的矢量
網絡:
input = input_variable(input_dim)
label = input_variable(num_output_classes)
h = Recurrence(LSTM(lstm_dim)) (input)
final_output = C.sequence.last(h)
z = Dense(num_output_classes) (final_output)
loss = C.cross_entropy_with_softmax(z, label)
輸出: 該序列的標籤相匹配的概率
所有的大小是固定的,所以我不認爲我需要任何動力軸並沒有指定任何。
然而,CNTK不開心,我得到:
return cross_entropy_with_softmax(output_vector, target_vector, axis, name)
RuntimeError: Currently if an operand of a elementwise operation has any dynamic axes, those must match the dynamic axes of the other operands
如果(按照一些例子)我定義標籤與動態軸
label = input_variable(num_output_classes, dynamic_axes=[C.Axis.default_batch_axis()])
它不再抱怨這個,並進一步獲取到:
tf = np.split(training_features,num_minibatches)
tl = np.split(training_labels, num_minibatches)
for i in range(num_minibatches*num_passes): # multiply by the
features = np.ascontiguousarray(tf[i%num_minibatches])
labels = np.ascontiguousarray(tl[i%num_minibatches])
# Specify the mapping of input variables in the model to actual minibatch data to be trained with
trainer.train_minibatch({input : features, label : labels})
但與此錯誤死亡:
File "C:\Users\Dev\Anaconda3\envs\cntk-py34\lib\site-packages\cntk\cntk_py.py", line 1745, in train_minibatch
return _cntk_py.Trainer_train_minibatch(self, *args)
RuntimeError: Node '__v2libuid__Plus561__v2libname__Plus552' (Plus operation): DataFor: FrameRange's dynamic axis is inconsistent with matrix: {numTimeSteps:1, numParallelSequences:100, sequences:[{seqId:0, s:0, begin:0, end:1}, {seqId:1, s:1, begin:0, end:1}, {seqId:2, s:2, begin:0, end:1}, {seqId:3, s:3, begin:0, end:1}, {seq...
我需要做些什麼來解決這個問題?
我試過了,它仍然在抱怨 – Tiny
RuntimeError:目前如果一個元素操作的操作數有任何動態軸,那些操作數必須與其他操作數的動態軸相匹配 – Tiny
我已經在實際嘗試之後更新了答案。 –