我试图模拟与theano后端的SeparableConvolution2D层相当的东西(它已经存在于TensorFlow后端) . 作为第一步我需要做的是将一个通道从张量传递到下一层 . 所以说我有一个名为conv1的2D卷积层,有16个过滤器,它产生一个形状为的输出:(batch_size,16,height,width)我需要选择形状为(:,0,:,:)的subtensor并将其传递给下一层 . 够简单吧?
这是我的代码:
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后端的重塑 . 这是将各个 Channels 传递到下一层的正确方法吗?
1 回答
我在keras用户组问了这个问题,我在那里得到了答案:
https://groups.google.com/forum/#!topic/keras-users/bbQ5CbVXT1E
引用它: