Keras中具有跳过连接的预训练权重初始化问题

时间:2018-10-15 16:49:15

标签: python keras deep-learning

我正在尝试实施预训练的VGG-16,以与“跳过连接”一起进行重量初始化。尽管模型摘要显示了正确的参数数量,但是权重未正确初始化。我的代码如下:

vgg16_model = applications.vgg16.VGG16(weights='imagenet', include_top=False,input_shape = (224, 224, 3) )
L1 = vgg16_model.get_layer('block1_conv1').output
L3 = vgg16_model.get_layer('block2_conv1').output
L5 = vgg16_model.get_layer('block3_conv1').output
L6 = vgg16_model.get_layer('block3_conv2').output
L8 = vgg16_model.get_layer('block4_conv1').output
L9 = vgg16_model.get_layer('block4_conv2').output
L11 = vgg16_model.get_layer('block5_conv1').output
L12 = vgg16_model.get_layer('block5_conv2').output
L13= vgg16_model.get_layer('block5_pool').output
skipConnectionLayers = Concatenate()([L1,L3,L5,L6,L8,L9,L11,L12])
x = Flatten(name='flatten_1')(L13)
x = Concatenate()([skipConnectionLayers, x]) #weights are initialized propery if this line is commented
x = Dense(10, activation='softmax', name='fc4')(x)
my_model = Model(input=vgg16_model.input, output=x)

我认为,当我设置include_top = False并在更深层进行更改时,权重初始化应该可以正常工作。

谢谢

0 个答案:

没有答案