具有可训练层和不可训练层的转移学习(MobileNet)的验证准确性差异

时间:2020-07-26 00:26:31

标签: tensorflow2.0

我正在使用MobileNet V1进行迁移学习。 我将Top = False设置为pooling ='max',并将weights ='imagnet ;;。然后添加一个密集层 225个具有softmax激活的神经元。我训练模型 在30,000张图片上验证,并在1050张图片上验证。 最初,我所有层都是可训练的。大约16个时期之后 训练精度为.9999和值精度为.967。 然后,我使用完全相同的设置,但建立了MobileNet模型的各层 由于无法训练,因此仅对稠密层进行训练。模型达到了 在短短几个时间段内仍可达到.999的训练准确性 验证准确性仅高达88。 谁能解释为什么会有显着差异?我最好的猜测是 Mobilenet模型确实具有用于设置退出水平的参数。如果层是 设置为不可训练我怀疑辍学没有影响,所以该模型过拟合。 真的吗? 代码在下面。

mobile = tf.keras.applications.mobilenet.MobileNet( include_top=False,
                                                           input_shape=(image_size,image_size,3),
                                                           pooling='max', weights='imagenet',
                                                           alpha=1, depth_multiplier=1,dropout=.4)
x=mobile.layers[-1].output
predictions=Dense (len(classes), activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=predictions) 
model.compile(Adamax(lr=lr_rate), loss='categorical_crossentropy', metrics=['accuracy'])
###########when I run with MobileNet layeys non-trainable code is########
mobile = tf.keras.applications.mobilenet.MobileNet( include_top=False,
                                                           input_shape=(image_size,image_size,3),
                                                           pooling='max', weights='imagenet',
                                                           alpha=1, depth_multiplier=1,dropout=.4)
for k,v in mobile._get_trainable_state().items():
    k.trainable = False
x=mobile.layers[-1].output
predictions=Dense (len(classes), activation='softmax')(x)
model = Model(inputs=mobile.input, outputs=predictions) 
model.compile(Adamax(lr=lr_rate), loss='categorical_crossentropy', metrics=['accuracy'])

0 个答案:

没有答案