我想模拟相当于theano后端(它已经存在的TensorFlow后端)的一个SeparableConvolution2D图层。作为第一步我需要做的是从张量传递一个通道到下一层。所以说我有一个名为conv1的二维卷积图层,带有16个过滤器,它们生成一个形状为(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后端重塑。这是将个人频道传递到下一层的正确方法吗?
您应该引用该链接的相关部分,以便该答案是独立的。 –