我有一个32x32大小的输入层。然后,我使用步幅(4,4)和16个滤镜的2d卷积,每个滤镜的内核大小为4x4。因此,最终的形状将为8 x 8 x16。现在,我想将结果重塑为输入形状,以便通道尺寸将在相应位置变成4x4正方形,即如果我们定义卷积的结果设为T
,期望的结果设为D
,那么我想要D[i * 4 + k, j * 4 + l] = T [i , j , k * 8 + l]
,其中i,j = 0,..,7和k,l = 0,..,3。有办法吗?
import numpy as np
from keras.layers import Input, Conv2D
from keras.initializers import Constant
input = Input(( 32, 32), dtype = 'float32')
filters = np.ndarray((4, 4, 16), dtype=np.float32)
# Initialization of the filter
filter_layer = Conv2D(16, 4, strides =(4,4), kernel_initialzer=Constant(filters), trainable = False)(input)
# no idea how to reshape the filter back