第一步:准备数据
12种花卉数据:向日葵, 梨花, 水仙, 牡丹, 玉兰花, 玫瑰, 睡莲, 美人蕉, 荷花, 菊花, 郁金香, 鸡蛋花,总共有7017张图片,每个文件夹单独放一种花
第二步:搭建模型
本文选择MobileNetV3Small,其网络结构如下:
由于是十二分类问题,直接套用网络肯定是不行,因此会在全连接部分做手脚,参考代码如下:
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(256)(x)
x = Activation('relu')(x)
x = Dense(64)(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)MobileNetV3Small可以从头训练或者利用预训练模型进行训练:
w = 1
if w:
base_model = MobileNetV3Small(weights='imagenet', include_top=False, input_shape=(width, height, 3))
else:
base_model = MobileNetV3Small(weights=None, include_top=False, input_shape=(width, height, 3))
第四步:统计正确率
|
正确率高达94.5%
第五步:搭建GUI界面
第六步:整个工程的内容
有训练代码和训练好的模型以及训练过程,提供数据,提供GUI界面代码,主要使用方法可以参考里面的“文档说明_必看.docx”
代码的下载路径(新窗口打开链接):基于keras框架的MobileNetV3神经网络花卉/花朵分类识别系统源码
有问题可以私信或者留言,有问必答