Am使用VGG16提取另一个模型的特征。进入VGG16的输入来自一个输出灰度图像的神经网络。因此,我用接受1个通道图像的输入替换了VGG的输入,然后输入一个连接层使输入3个通道,以便卷积层可以在图像上进行操作。
vgg_16 = vgg16.VGG16(include_top = False,weights ='imagenet',input_tensor = None) #训练时冻结VGG_16 对于vgg_16.layers中的图层: layer.trainable = False
vgg_16.layers.pop(0)
inputs = Input(shape=(312, 312, 1))
concat = keras.layers.Concatenate(axis=3)([inputs] * 3)
outputs = vgg_16(concat)
vgg_first2 = Model(inputs, outputs)
vgg_first2.summary()
keras打印的摘要显示连接输出是预期的3个通道,
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_4 (InputLayer) (None, 312, 312, 1) 0
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 312, 312, 3) 0 input_4[0][0]
input_4[0][0]
input_4[0][0]
__________________________________________________________________________________________________
vgg16 (Model) multiple 14714688 concatenate_1[0][0]
==================================================================================================
最后我得到一个错误ValueError:输入通道数与过滤器的相应尺寸不匹配,9!= 3。
最后一点,我在使用带有tensorflow后端的keras