首页 文章

使用keras mobilenet模型

提问于
浏览
1

我正在尝试使用Keras的MobileNet进行图像分类 . 我的输入形状是 (64, 64, 3) ,我的数据集中有两个类 . 我不想使用训练过的重量 .

这是我的代码 .

model = MobileNet(weights=None, include_top=True, input_shape=(64, 64, 3), classes=2)

我的问题是, include_top 应该 TrueFalse ?既然这位官员说过,

input_shape: 可选的形状元组,仅在include_top为False时指定

include_top: 是否在网络顶部包含完全连接的层 .

我想做图像分类,所以我认为我的最后一层应该是完全连接的 . 这是对的吗?

谢谢 .

1 回答

  • 0

    如果你想传递一个(64,64,3)的输入形状,那么你需要

    include_top=False
    

    是的,你最后需要完全连接的层 . 你必须 Build 自己的网络顶部 . 你的模型就是这样的

    base_model= MobileNet(weights=None, include_top=False, input_shape=(64, 64, 3))
    x=base_model.output
    x=Flatten()(x)
    x=Dense(...)(x)
    .
    .
    # Softmax layer for classification
    predictions=Dense(2,activation='softmax')
    model=(x=base_model.input,output=predictions)
    

    我不知道为什么我们需要删除完全连接的层以更改input_shape,但我认为上述解决方案将起作用

    Edit:

    如果input_shape不同,为什么要将include_top设置为False?

    因为它会在最后将输入大小更改为完全连接的层 .
    有关详细说明,请参阅this答案

相关问题