2016-08-23 6 views
1

私はtheanoバックエンド(これは既にTensorFlowバックエンド用に存在する)のSeparableConvolution2Dレイヤーに相当するものをエミュレートしようとしています。最初のステップとして、テンソルから次のレイヤーに1つのチャンネルを渡すだけです。ですから、形状を持つ出力を生成する16個のフィルタを持つconv1という2次元畳み込みレイヤーがあります。(batch_size、16、height、width)形状(:、0、:、:)でサブセンサーを選択し、次のレイヤー。十分に簡単ですか?テナーの個別チャネルをKerasのレイヤーに渡す

これは私のコードです:

from keras import backend as K 

image_input = Input(batch_shape = (batch_size, 1, height, width), name = 'image_input') 

conv1 = Convolution2D(16, 3, 3, name='conv1', activation = 'relu')(image_input) 

conv2_input = K.reshape(conv1[:,0,:,:] , (batch_size, 1, height, width)) 

conv2 = Convolution2D(16, 3, 3, name='conv1', activation = 'relu')(conv2_input) 

これはスロー:

Exception: You tried to call layer "conv1". This layer has no information about its expected input shape, and thus cannot be built. You can build it manually via: layer.build(batch_input_shape)

をなぜ層は、必要な形状情報を持っていませんか?私はtheanoバックエンドからの形を変えています。これは、個々のチャンネルを次のレイヤに渡す正しい方法ですか?

答えて

1

私はkeras・ユーザー・グループにこの質問をして、私はそこに答えました。それを引用

https://groups.google.com/forum/#!topic/keras-users/bbQ5CbVXT1E

あなたはラムダ層を使用する必要があるが、のように:ラムダ(x [0]、l、x [2]、x [3]))

このような手動実装分離可能な畳み込みがひどく非効率的になる。正しい解決策は、TensorFlowバックエンドを使用することです。

+1

この回答が自己完結型であるように、リンクの関連部分を引用する必要があります。 –

関連する問題