Keras中带跳跃连接的预训练权重初始化问题

2024-10-03 15:28:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试实现预先训练的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并在更深层次进行更改时,权重初始化应该可以正常工作。在

谢谢


Tags: layerfalsel1inputoutputgetmodelinclude