【问题标题】:Accuracy is dropped after adding a dense layer to a pretrained Mobilenet model向预训练的 Mobilenet 模型添加密集层后精度下降
【发布时间】:2021-08-17 01:55:51
【问题描述】:

我有以下代码,利用 mobilenetv2 进行两类分类。添加2个单元的dense layer后,准确率明显下降到45%。我无法弄清楚可能是什么问题,我更改了优化器,但准确性仍然没有提高。我的训练数据集是 2000,有两个类别,猫和狗。

custom= MobileNetV2(input_shape=None,
                   alpha=1.0,
                   include_top=True,
                   weights='imagenet',     
                   input_tensor=None,
                   pooling=None,
                   classes=1000,
                   classifier_activation='softmax')
   x= custom.output
   final_output=layers.Dense(2, activation='sigmoid')(x)
   model = keras.Model(inputs=custom.input, outputs = final_output)
   for layer in custom.layers:
     layer.trainable = False

   model.compile(optimizer="adam", loss='BinaryCrossentropy', metrics=['accuracy'],loss_weights=0.1)

【问题讨论】:

  • 你将一个分类器放在另一个分类器之上,难怪它表现不佳。
  • @Dr.Snoopy 说了什么。准确地说。您有一个具有 1000 大小输出和 softmax 激活的分类器,在此之上您添加了另一层。你应该做什么,你应该用新层替换最后一层或简单地使用 classes 参数

标签: tensorflow machine-learning keras conv-neural-network


【解决方案1】:

您可以在加载预训练模型时使用include_top=False 语句。此代码语句删除了预训练模型的最后一部分。

【讨论】:

    猜你喜欢
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 2018-11-02
    • 2018-05-05
    相关资源
    最近更新 更多