我想模擬相當於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後端重塑。這是將個人頻道傳遞到下一層的正確方法嗎?
您應該引用該鏈接的相關部分,以便該答案是獨立的。 –