第一步:准备数据

9种蔬菜数据:'土豆', '大白菜', '洋葱', '胡萝卜', '茄子', '西红柿', '辣椒', '韭菜', '黄瓜',总共有5611张图片,每个文件夹单独放一种花

第二步:搭建模型

本文选择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.2%

第五步:搭建GUI界面

第六步:整个工程的内容

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

 

 项目完整文件下载请见演示与介绍视频的简介处给出:➷➷➷

https://www.bilibili.com/video/BV1RRUSYFESx/

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐