当前位置: 首页 > article >正文

基于深度学习的花卉智能分类识别系统

温馨提示:文末有 CSDN 平台官方提供的学长 QQ 名片 :) 

1. 项目简介

        传统的花卉分类方法通常依赖于专家的知识和经验,这种方法不仅耗时耗力,而且容易受到主观因素的影响。本系统利用 TensorFlow、Keras 等深度学习框架构建卷积神经网络(CNN),利用花卉数据集进行模型训练与验证,预测准确率达到 84.3%,使用Flask框架结合Bootstrap前端技术搭建了一个交互式的分析预测平台,能够从大量的图像数据中自动学习和提取特征,从而实现高效、准确的分类。

2. 花卉数据集读取与预处理

        利用 Tensorflow 框架从文件夹中读取花卉图像数据:

# 花卉类别
class_map = {'tulip': 0, 'sunflower': 1, 'rose': 2, 'dandelion': 3, 'daisy': 4}
class_name_dict = {0: 'tulip', 1: 'sunflower', 2: 'rose', 3: 'dandelion', 4: 'daisy'}


def image_generator(height,width):
    datagen = ImageDataGenerator(
            rescale=1./255.,
            validation_split=0.2,
            rotation_range=10,
            width_shift_range=0.05,
            height_shift_range=0.05,
            # shear_range=0.05,
            brightness_range=[0.5, 1.5],
            )
    train_ds = datagen.flow_from_directory(
            data_dir,
            batch_size=batch_size,
            subset="training",
            #color_mode = 'grayscale',
            shuffle=True,
            class_mode='categorical',
            target_size=(height, width),
            classes=class_map
            )
    val_ds = datagen.flow_from_directory(
              data_dir,
              subset="validation",
              #seed=123,
              #color_mode = 'grayscale',
              class_mode='categorical',
              target_size=(height, width),
              batch_size=batch_size,
            classes=class_map
            )
    return train_ds, val_ds

3. 深度卷积神经网络模型构建

3.1 VGG16 Base Model

        VGG(Visual Geometry Group)是一个视觉几何组在2014年提出的深度卷积神经网络架构。VGG在2014年ImageNet图像分类竞赛亚军,定位竞赛冠军;VGG网络采用连续的小卷积核(3x3)和池化层构建深度神经网络,网络深度可以达到16层或19层,其中VGG16和VGG19最为著名。

VGG16和VGG19网络架构非常相似,都由多个卷积层和池化层交替堆叠而成,最后使用全连接层进行分类。两者的区别在于网络的深度和参数量,VGG19相对于VGG16增加了3个卷积层和一个全连接层,参数量也更多。

VGG网络被广泛应用于图像分类、目标检测、语义分割等计算机视觉任务中,并且其网络结构的简单性和易实现性使得VGG成为了深度学习领域的经典模型之一。

input_shape = (height, width, 3)
base_model = tf.keras.applications.vgg16.VGG16(
    weights='./pretrained_models/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5', 
    include_top=False,
    input_shape=input_shape
)
base_model.trainable = False

model_vgg16 = tf.keras.Sequential()
model_vgg16.add(base_model)
model_vgg16.add(tf.keras.layers.Flatten())

model_vgg16.add(tf.keras.layers.Dense(len(class_map), activation='softmax'))

model_vgg16.compile(loss='categorical_crossentropy', 
              optimizer=tf.keras.optimizers.Adam(0.001),
              metrics=['accuracy'])
model_vgg16.summary()

         模型训练:

vgg16_history = model_vgg16.fit(
    train_ds,
    validation_data=val_ds,
    epochs=epochs,
    callbacks=[checkpointer, earlystopper]
)
Epoch 1/100
69/69 [==============================] - ETA: 0s - loss: 0.9497 - accuracy: 0.6451
Epoch 1: val_accuracy improved from -inf to 0.78102, saving model to best_vgg16_model.h5
69/69 [==============================] - 308s 4s/step - loss: 0.9497 - accuracy: 0.6451 - val_loss: 0.6584 - val_accuracy: 0.7810

......
Epoch 11/100
69/69 [==============================] - ETA: 0s - loss: 0.0755 - accuracy: 0.9854
Epoch 11: val_accuracy did not improve from 0.80839
69/69 [==============================] - 349s 5s/step - loss: 0.0755 - accuracy: 0.9854 - val_loss: 0.6177 - val_accuracy: 0.7938
Epoch 11: early stopping

 3.2 InceptionV3 Base Model

        深度神经网络(Deep Neural Networks, DNN)或深度卷积网络中的Inception模块是由Google的Christian Szegedy等人提出,包括Inception-v1、Inception-v2、Inception-v3、Inception-v4及Inception-ResNet系列。

tf.keras.backend.clear_session()

base_model = tf.keras.applications.InceptionV3(
    weights='./pretrained_models/inception_v3_weights_tf_dim_ordering_tf_kernels_notop.h5', 
    include_top=False, 
    input_shape=input_shape
)
base_model.trainable = False

model_inceptionv3 = tf.keras.Sequential()
model_inceptionv3.add(base_model)
model_inceptionv3.add(tf.keras.layers.Flatten())

model_inceptionv3.add(tf.keras.layers.Dense(len(class_map), activation='softmax'))

model_inceptionv3.compile(loss='categorical_crossentropy',
    optimizer=tf.keras.optimizers.Adam(0.001),
    metrics=['accuracy']
)
model_inceptionv3.summary()

        模型训练:

inceptionv3_history = model_inceptionv3.fit(
    train_ds,
    validation_data=val_ds,
    epochs=epochs,
    callbacks=[checkpointer, earlystopper]
)

3.3 模型性能对比

labels = ['损失Loss','准确率Accuracy']
vgg16_evals = [vgg16_eval_result['损失Loss'], vgg16_eval_result['准确率Accuracy']]
inceptionv3_evals = [inceptionv3_eval_result['损失Loss'], inceptionv3_eval_result['准确率Accuracy']]

x = np.arange(len(labels))  # the label locations
bar_width = 0.35  # the width of the bars

fig, ax = plt.subplots(figsize=(8, 6), dpi=100)
rects1 = ax.bar(x - bar_width/2, vgg16_evals, bar_width, label='VGG16')
rects2 = ax.bar(x + bar_width/2, inceptionv3_evals, bar_width, label='Inception-V3')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Loss/Acc')
ax.set_title('VGG16 与 Inception-V3 的花卉分类性能对比')
ax.set_xticks(x, labels)
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)

fig.tight_layout()
 
plt.show()

        可以看出,基于 Inception-V3 为 base 模型的卷积神经网络,其预测准确率较高,为84.31%,以此花卉智能分类识别系统中,我们将集成该模型。

4. 花卉图片数据采集与样本扩充

        原始数据集的每类花卉包括 607 个样本,虽然样本均衡,但是针对深度学习类的神经网络模型来说,样本还是不足,从建模过程中也能看出,预测准确率为 84.3%。

{'tulip': 607, 'sunflower': 607, 'rose': 607, 'dandelion': 607, 'daisy': 607}

        本项目中,利用网络爬虫采集搜索引擎中搜索到的各类花卉的图片,来扩充样本数据集:

Coding 进行中,待更新......

5. 花卉智能分类识别系统

5.1 系统首页

        系统首页提供简洁明了的界面设计,包括系统名称、主要功能简介以及使用指南等内容。用户可以通过主页快速了解系统的基本操作流程及注意事项。首页上还会展示一些示例图片,让用户直观地感受到系统的实际效果。

5.2 卷积神经网络模型介绍

5.3 花卉品种实时分类预测

        用户上传花卉图像后,系统将自动调用预先训练好的深度学习模型进行分析处理。模型会根据图像中的特征判断花卉种类,并给出相应的分类结果。此外,系统还会提供模型对所有类别的预测概率分布,提升模型输出可解释性。

        (1)郁金香(Tulip)类别样本预测

        (2)太阳花(Sunflower)类别样本预测

        (3)玫瑰花(Rose)类别样本预测

        (4)蒲公英(Dandelion)类别样本预测

        (5)雏菊(Daisy)类别样本预测

6. 总结

        本系统利用 TensorFlow、Keras 等深度学习框架构建卷积神经网络(CNN),利用花卉数据集进行模型训练与验证,预测AUC达到 94.9%,使用Flask框架结合Bootstrap前端技术搭建了一个交互式的分析预测平台,能够从大量的图像数据中自动学习和提取特征,从而实现高效、准确的分类。 
 

 欢迎大家点赞、收藏、关注、评论啦 ,由于篇幅有限,只展示了部分核心代码。技术交流、源码获取认准下方 CSDN 官方提供的学长 QQ 名片 :)

精彩专栏推荐订阅:

1. Python-数据挖掘实战案例

2. Python-深度学习实战案例

3. Python-管理系统实战案例


http://www.kler.cn/news/313077.html

相关文章:

  • 【win工具】win安装flameshot并设置截图快捷键
  • 【Python报错已解决】xlrd.biffh.XLRDError: Excel xlsx file; not supported
  • C++自动寻径算法
  • 《黑神话悟空》开发框架与战斗系统解析
  • 4.C++中程序中的命名空间
  • git 本地分支误删,怎么恢复?误删本地已提交未推送的分支!
  • 基于Python实现一个浪漫烟花秀
  • 如何设置 Django 错误邮件通知 ?
  • I2C中继器TCA9517A(TI)
  • 新160个crackme - 060-snake
  • 2024年Q3国际信息系统安全认证联盟(ISC2)内部研讨会要点分享
  • 系统架构设计师 大数据架构篇二
  • 球形包围框-Bounding Sphere-原理-代码实现
  • Mycat中间件
  • 牛客BC92,逆序输出
  • 222222222
  • Qt/C++开发经验
  • 【深度学习 transformer】理解 Transformer:机器学习界的“变形金刚
  • Vue3:v-model实现组件通信
  • Streamlit:使用 Python 快速开发 Web 应用
  • 大数据新视界 --大数据大厂之AI 与大数据的融合:开创智能未来的新篇章
  • Git入门学习(1)
  • HTTP中的Cookie与Session
  • pandoc自定义过滤器
  • 小程序构建npm失败
  • WPF 所有的控件和每个控件的主要作用和应用场景
  • 25届计算机专业毕设选题推荐-基于python+Django协调过滤的新闻推荐系统
  • 数学辅导微信小程序--论文ppt源码调试讲解
  • 执行网络攻击模拟的 7 个步骤
  • 注册建造师执业工程规模标准(公路工程铁路工程通信与广电工程民航机场工程港口与航道工程)