毕业设计So Easy:卷积神经网络实现中药材识别系统APP

目录

1、项目概述

2、开发环境

3、项目架构

4、项目实现

5、项目效果演示


很多计算机专业大学生经常和我交流:毕业设计没思路、不会做、论文不会写、太难了......

针对这些问题,决定分享一些软、硬件项目的设计思路和实施方法,希望可以帮助大家,也祝愿各位学子,顺利毕业!

项目专栏:7天搞定毕业设计和论文

计算机技术感兴趣的小伙伴请关注公众号:美男子玩编程,公众号优先推送最新技术博文,创作不易,请各位朋友多多点赞、收藏、关注支持\~     


1、项目概述

中药识别系统主要采用APP端拍照上传的方式,构建卷积神经网络(CNN)对图像进行识别,具有识别效率高,准确度高的特点。APP端的功能包括但不限于拍照识别、中药问答、检索查询、中药性状以及功效查看、方剂智能推荐等,本系统包含APP端以及服务器端。

项目资源下载请参考:https://download.csdn.net/download/m0_38106923/87577964

2、开发环境

1、medicine-app APP端

  • Flutter开发

2、medicine-server服务器端工程

  • Gradle构建
  • SpringBoot框架,一键启动与部署
  • 文档数据库:MongoDB
  • 全文检索:Elasticsearch + IK分词器
  • 数据库:MySQL
  • 深度学习运行时架构:ONNX Runtime(ONNX Runtime is a cross-platform inference and training machine-learning accelerator)

3、m edicine-crawler爬虫工程

  • 爬虫主要用来爬取训练集以及中药的详细信息,包含但不限于:中药名称、中药形态、图片、 别名、英文名、配伍药方、功效与作用、临床应用、产地分布、药用部位、 性味归经、药理研究、主要成分、使用禁忌、采收加工、药材性状等信息。
  • 爬虫框架:WebMagic
  • 数据持久化:MongoDB
  • 数据结构(简略展示)

中药一级分类信息如下所示: 

中药详细信息如下所示: 

4、medicine-model卷积神经网络工程

  •  Language: Python
  • 使用TensorFlow 深度学习框架,使用Keras会大幅缩减代码量
  • 常用的卷积网络模型及在ImageNet上的准确率 

3、项目架构

本项目包含六个模块:

  • medicine-app:APP端
  • medicine-server:服务器端
  • medicine-crawler:爬虫工程
  • medicine-model:卷积神经网络
  • medicine-util:公用工具类
  • medicine-dataset:数据集

4、项目实现

由于硬件条件限制,综合考虑模型的准确率、大小以及复杂度等因素,采用了Xception模型,该模型是134层(包含激活层,批标准化层等)拓扑深度的卷积网络模型。

Xception函数定义:

``` def Xception(includetop=True, weights='imagenet', inputtensor=None, input_shape=None, pooling=None, classes=1000, **kwargs)

参数

include_top:是否保留顶层的全连接网络

weights:None代表随机初始化,即不加载预训练权重。'imagenet’代表加载预训练权重

input_tensor:可填入Keras tensor作为模型的图像输入tensor

inputshape:可选,仅当includetop=False有效,应为长为3的tuple,指明输入图片的shape,图片的宽高必须大于71,如(150,150,3)

pooling:当include_top=False时,该参数指定了池化方式。None代表不池化,最后一个卷积层的输出为4D张量。‘avg’代表全局平均池化,‘max’代表全局最大值池化。

classes:可选,图片分类的类别数,仅当include_top=True并且不加载预训练权重时可用

```

设置Xception参数,迁移学习参数权重加载:xception_weights,如下所示:

```

设置输入图像的宽高以及通道数

img_size = (299, 299, 3)

basemodel = keras.applications.xception.Xception(includetop=False, weights='..\resources\keras-model\xceptionweightstfdimorderingtfkernelsnotop.h5', inputshape=img_size, pooling='avg')

全连接层,使用softmax激活函数计算概率值,分类大小是628

model = keras.layers.Dense(628, activation='softmax', name='predictions')(basemodel.output) model = keras.Model(basemodel.input, model)

锁定卷积层

for layer in base_model.layers: layer.trainable = False ```

全连接层训练如下所示:

``` from base_model import model

设置训练集图片大小以及目录参数

imgsize = (299, 299) datasetdir = '..\dataset\dataset' imgsavetodir = 'resources\image-traing\' logdir = 'resources\train-log'

model_dir = 'resources\keras-model\'

使用数据增强

traindatagen = keras.preprocessing.image.ImageDataGenerator( rescale=1. / 255, shearrange=0.2, widthshiftrange=0.4, heightshiftrange=0.4, rotationrange=90, zoomrange=0.7, horizontalflip=True, verticalflip=True, preprocessingfunction=keras.applications.xception.preprocessinput)

testdatagen = keras.preprocessing.image.ImageDataGenerator( preprocessingfunction=keras.applications.xception.preprocess_input)

traingenerator = traindatagen.flowfromdirectory( datasetdir, savetodir=imgsavetodir, targetsize=imgsize, class_mode='categorical')

validationgenerator = testdatagen.flowfromdirectory( datasetdir, savetodir=imgsavetodir, targetsize=imgsize, class_mode='categorical')

早停法以及动态学习率设置

earlystop = EarlyStopping(monitor='valloss', patience=13) reducelr = ReduceLROnPlateau(monitor='valloss', patience=7, mode='auto', factor=0.2) tensorboard = keras.callbacks.tensorboardv2.TensorBoard(logdir=log_dir)

for layer in model.layers: layer.trainable = False

模型编译

model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])

history = model.fitgenerator(traingenerator, stepsperepoch=traingenerator.samples // traingenerator.batchsize, epochs=100, validationdata=validationgenerator, validationsteps=validationgenerator.samples // validationgenerator.batchsize, callbacks=[earlystop, reduce_lr, tensorboard])

模型导出

model.save(modeldir + 'chinesemedicinemodelv1.0.h5') ```

对于顶部的6层卷积层,我们使用数据集对权重参数进行微调,如下所示:

``` # 加载模型 model=keras.models.loadmodel('resources\keras-model\chinesemedicinemodelv2.0.h5')

for layer in model.layers: layer.trainable = False for layer in model.layers[126:132]: layer.trainable = True

history = model.fitgenerator(traingenerator, stepsperepoch=traingenerator.samples // traingenerator.batchsize, epochs=100, validationdata=validationgenerator, validationsteps=validationgenerator.samples // validationgenerator.batchsize, callbacks=[earlystop, reducelr, tensorboard]) model.save(modeldir + 'chinesemedicinemodel_v2.0.h5') ```

最后,服务器端,使用ONNX Runtime调用训练好的模型。

训练过程正确率以及损失函数可视化展示:

5、项目效果演示

   项目资源下载请参见:https://download.csdn.net/download/m0_38106923/87577964

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_44079197

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值