Я хочу использовать затем сканирование вычисления tensor3 в моем DNN, мы можем сказать, что этот тензор3 является 3D-матрицей, я хочу, чтобы каждый слой этой матрицы проходил через вычисление T.nnet.softmax(T.dot(v, W)+b)
, W
и b
должны быть фиксированными, поэтому я мог бы выполнить обновление позже. Ниже мое кодирование:Что я должен сделать для использования сканирования anano в глубоком обучении
XS = T.tensor3("XS")
W = T.matrix(name="W")
b = T.vector(name="b")
results, updates = theano.scan(lambda XS: T.nnet.softmax(T.dot(XS,W) + b),
sequences=[XS],
outputs_info=None)
result = results
Mutiply = theano.function(inputs=[XS, W, b], outputs=[result])
#initialization of output of layer2
w_o = init_weights((1089, 10))
b_o = init_weights((10,))
myFile_data = h5py.File('/Users/XIN/Masterthesis/Torch_Script/mnist-cluttered/train_data.h5', 'r')
myFile_label= h5py.File('/Users/XIN/Masterthesis/Torch_Script/mnist-cluttered/train_target.h5', 'r')
data = myFile_data['data'][...]
label = myFile_label['target'][...]
data = data.reshape(100000, 10000)
trX = data
trY = label
X_s = downsampling(trX)
X_nine = load_data_train(trX, trX.shape[0], 9)
X_nine = X_nine.transpose((((2,0,1))))
p_x_nine = Mutiply(X_nine, w_o, b_o)[0]
но результаты показывают эту ошибку:
runfile('/Users/XIN/Masterthesis/keras/thean_scan_test.py', wdir='/Users/XIN/Masterthesis/keras')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/XIN/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/Users/XIN/anaconda/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
builtins.execfile(filename, *where)
File "/Users/XIN/Masterthesis/keras/thean_scan_test.py", line 115, in <module>
p_x_nine = Mutiply(X_nine, w_o, b_o)[0]
File "/Users/XIN/anaconda/lib/python2.7/site-packages/theano/compile/function_module.py", line 786, in __call__
allow_downcast=s.allow_downcast)
File "/Users/XIN/anaconda/lib/python2.7/site-packages/theano/tensor/type.py", line 86, in filter
'Expected an array-like object, but found a Variable: '
TypeError: ('Bad input argument to theano function with name "/Users/XIN/Masterthesis/keras/thean_scan_test.py:92" at index 1(0-based)', 'Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?')
Я проверяю X_nine
тип: np
массив, но w_o
и b_o
является theano
типа. Итак, что мне делать, чтобы изменить этот код.