第一步:准备数据

9种动物数据:'大熊猫', '大象', '狗', '狮子', '猫', '老虎', '长颈鹿', '鳄鱼', '鸡',总共有5005张图片,每个文件夹单独放一种动物

第二步:搭建模型

本文选择MobileNetV3Small,其网络结构如下:

 由于是九分类问题,直接套用网络肯定是不行,因此会在全连接部分做手脚,参考代码如下:

    x = base_model.output
    x = GlobalAveragePooling2D()(x)
    x = Dense(64)(x)
    x = Activation('relu')(x)
    x = Dense(16)(x)
    x = Activation('relu')(x)
    x = Dense(class_num)(x)
    predictions = Activation('softmax')(x)

    # for layer in base_model.layers:
    #     layer.trainable = True

    model = Model(inputs=base_model.input, outputs=predictions)
    return model

第三步:训练代码

1)损失函数为:交叉熵损失函数

2)MobileNetV2可以从头训练或者利用预训练模型进行训练:

    w = 1
    if w:
        base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(width, height, 3))
    else:
        base_model = MobileNetV2(weights=None, include_top=False, input_shape=(width, height, 3))

第四步:统计正确率

 正确率高达93.1%

第五步:搭建GUI界面

第六步:整个工程的内容

有训练代码和训练好的模型以及训练过程,提供数据,提供GUI界面代码,主要使用方法可以参考里面的“文档说明_必看.docx”

视频演示和项目源码下载:

keras框架——深度学习MobileNetV2神经网络动物分类识别系统源码_哔哩哔哩_bilibili

整套项目源码内容包含

有训练代码和训练好的模型以及训练过程,提供数据,提供GUI界面代码

更多推荐