まず、KerasとTheanoの新機能です。ローカル応答正規化(LRN)を使用するCNNを実装しています。私の知る限り、kerasとtheanoの両方の基本機能にはこのようなレイヤーは実装されていません。だから私はLRNを実装するケラスラムダ層を使用してみました。Keras Lambda Layer&Theanoコード:TensorVariableのディメンションと値へのアクセス
「DEF local_response_normalization(X): #LRNパラメータ K = 2 N = 5 アルファ= 0.0001 ベータ= 0.75
result = x.eval()
x_tmp = x.eval()
#building functions for the theano computation graph
scalar_op = T.dscalar('scalar_op')
matrix1_op = T.dmatrix('matrix1_op')
matrix2_op = T.dmatrix('matrix2_op')
mul_result = scalar_op * matrix1_op
add_result = scalar_op + matrix1_op
pow_result = matrix1_op ** scalar_op
div_result = matrix1_op/matrix2_op
sc_mat_mul_f = function([scalar_op, matrix1_op], mul_result)
sc_mat_add_f = function([scalar_op, matrix1_op], add_result)
sc_mat_pow_f = function([scalar_op, matrix1_op], pow_result)
mat_div_f = function([matrix1_op, matrix2_op], div_result)
#x is supposed to be a 3-dimensional tensor (a x b x c)
a_dim = x_tmp.shape[0]
b_dim = x_tmp.shape[1]
c_dim = x_tmp.shape[2]
#iterating through channels
for i in range(0, a_dim):
j_l = max(0, i-(n/2))# j_l(ower_bound)
j_u = min(N-1, i+(n/2))# j_u(pper_bound)
x_tmp = x.eval()
#retrieving set of local 'neurons'
x_tmp = x_tmp[j_l:j_u+1,:,:]
#building squared sum
x_tmp = T.sqr(x_tmp)#TensorVariable
x_tmp = T.sum(x_tmp, axis=0)#axis no. 0 = 'channel' axis
#x_tmp is now 2-dimensional
x_tmp = sc_mat_mul_f(alpha, x_tmp.eval())
x_tmp = sc_mat_add_f(k, x_tmp)
x_tmp = sc_mat_pow_f(beta, x_tmp)
x_tmp = mat_div_f(result[i], x_tmp)
#exchanging channel i with x_tmp (= LRN)
result[i] = x_tmp
return result`
Iはmodel.add(local_response_normalization, ...)
を使用してモデルにこの層を一体化してい
theano.gof.fg.MissingInputError: Input 0 of the graph (indices start from 0), used to compute AbstractConv2d{convdim=2, border_mode='half', subsample=(4, 4), filter_flip=True, imshp=(None, 3, 220, 220), kshp=(96, 3, 11, 11), filter_dilation=(1, 1)}(/conv2d_1_input, InplaceDimShuffle{3,2,0,1}.0), was not provided and not given a value. Use the Theano flag exception_verbosity='high', for more information on this error.
主な問題は、モデルのコンパイル時にeval()を呼び出せないことです。私はeval()を使ってnumpy配列に変換する以外に、xの要素(conv2d層の出力テンソル)をアクセスして操作する別の方法を見つけることはできませんが、明らかに動作しません。私はLambda LayersとTensorVariablesの背後にある主なコンセプトが一般的に見当たりません。
私はこの問題を扱う最後の2日間を過ごしました。私は本当に立ち往生しています。