基于yolov11+django+deepseek的农业害虫检测系统带登录界面python源码+onnx模型+精美web界面

作品简介

效果展示

登录界面


主界面

基于 YOLO11 的目标检测系统,支持图片、视频和实时摄像头检测,集成 DeepSeek AI 分析功能。

功能特性

  • 图片目标检测
  • 视频文件检测
  • 实时摄像头检测
  • DeepSeek AI 智能分析
  • 可调节的检测参数(置信度、IoU)
  • 美观的用户界面

【测试环境】

windows10

anaconda3+python3.10

torch 2.3.1

ultralytics 8.4.7

Django==5.2.11

notallow==1.17.0

【模型可以检测出95类别】

[‘1 riceleafroller’,‘10 small brown plant hopper’,‘11 rice water weevil’,‘12 rice leafhopper’,‘13 grain spreader thrips’,‘14 riceshellpest’,‘15 grub’,‘16 mole cricket’,‘17 wireworm’,‘18 white margined moth’,‘19 black cutworm’,‘2 rice leaf caterpillar’,‘20 large cutworm’,‘21 yellow cutworm’,‘22 red spider’,‘23 corn borer’,‘24 army worm’,‘25 aphids’,‘26 Potosiabre vitarsis’,‘27 peach borer’,‘28 english grain aphid’,‘29 green bug’,‘3 paddy stem maggot’,‘30 bird cherry-oataphid’,‘31 wheat blossom midge’,‘32 penthaleus major’,‘33 longlegged spider mite’,‘34 wheat phloeothrips’,‘35 wheat sawfly’,‘36 cerodonta denticornis’,‘37 beet fly’,‘38 flea beetle’,‘39 cabbage army worm’,‘4 asiatic rice borer’,‘40 beet army worm’,‘41 Beet spot flies’,‘42 meadow moth’,‘43 beet weevil’,‘44 sericaorient alismots chulsky’,‘45 alfalfa weevil’,‘46 flax budworm’,‘47 alfalfa plant bug’,‘48 tarnished plant bug’,‘49 Locustoidea’,‘5 yellow rice borer’,‘50 lytta polita’,‘51 legume blister beetle’,‘52 blister beetle’,‘53 therioaphis maculata Buckton’,‘54 odontothrips loti’,‘55 Thrips’,‘56 alfalfa seed chalcid’,‘57 Pieris canidia’,‘58 Apolygus lucorum’,‘59 Limacodidae’,‘6 rice gall midge’,‘60 Viteus vitifoliae’,‘61 Colomerus vitis’,‘62 Brevipoalpus lewisi McGregor’,‘63 oides decempunctata’,‘64 Polyphagotars onemus latus’,‘65 Pseudococcus comstocki Kuwana’,‘66 parathrene regalis’,‘67 Ampelophaga’,‘68 Lycorma delicatula’,‘69 Xylotrechus’,‘7 Rice Stemfly’,‘70 Cicadella viridis’,‘71 Miridae’,‘72 Trialeurodes vaporariorum’,‘73 Erythroneura apicalis’,‘74 Papilio xuthus’,‘75 Panonchus citri McGregor’,‘76 Phyllocoptes oleiverus ashmead’,‘77 Icerya purchasi Maskell’,‘78 Unaspis yanonensis’,‘79 Ceroplastes rubens’,‘8 brown plant hopper’,‘80 Chrysomphalus aonidum’,‘81 Parlatoria zizyphus Lucus’,‘82 Nipaecoccus vastalor’,‘83 Aleurocanthus spiniferus’,‘84 Tetradacus c Bactrocera minax’,‘85 Dacus dorsalis-Hendel-’,‘86 Bactrocera tsuneonis’,‘87 Prodenia litura’,‘88 Adristyrannus’,‘89 Phyllocnistis citrella Stainton’,‘9 white backed plant hopper’,‘90 Toxoptera citricidus’,‘91 Toxoptera aurantii’,‘92 Aphis citricola Vander Goot’,‘93 Scirtothrips dorsalis Hood’,‘94 Dasineura sp’,‘96 Salurnis marginella Guerr’,‘97 Deporaus marginatus Pascoe’]

【训练数据集介绍】

数据集格式:YOLO格式(不包含分割路径的txt文件,仅仅包含jpg图片以及对应的yolo格式txt文件)

图片数量(jpg文件个数):8518

标注数量(txt文件个数):8518

训练集数量:5963

验证集数量:1704

测试集数量:851

标注类别数:95

所在github仓库:firc-dataset

标注类别名称(注意yolo格式类别顺序不和这个对应,而以labels文件夹classes.txt为准):[‘1 rice leaf roller’,‘10 small brown plant hopper’,‘11 rice water weevil’,‘12 rice leafhopper’,‘13 grain spreader thrips’,‘14 rice shell pest’,‘15 grub’,‘16 mole cricket’,‘17 wireworm’,‘18 white margined moth’,‘19 black cutworm’,‘2 rice leaf caterpillar’,‘20 large cutworm’,‘21 yellow cutworm’,‘22 red spider’,‘23 corn borer’,‘24 army worm’,‘25 aphids’,‘26 Potosiabre vitarsis’,‘27 peach borer’,‘28 english grain aphid’,‘29 green bug’,‘3 paddy stem maggot’,‘30 bird cherry-oataphid’,‘31 wheat blossom midge’,‘32 penthaleus major’,‘33 longlegged spider mite’,‘34 wheat phloeothrips’,‘35 wheat sawfly’,‘36 cerodonta denticornis’,‘37 beet fly’,‘38 flea beetle’,‘39 cabbage army worm’,‘4 asiatic rice borer’,‘40 beet army worm’,‘41 Beet spot flies’,‘42 meadow moth’,‘43 beet weevil’,‘44 sericaorient alismots chulsky’,‘45 alfalfa weevil’,‘46 flax budworm’,‘47 alfalfa plant bug’,‘48 tarnished plant bug’,‘49 Locustoidea’,‘5 yellow rice borer’,‘50 lytta polita’,‘51 legume blister beetle’,‘52 blister beetle’,‘53 therioaphis maculata Buckton’,‘54 odontothrips loti’,‘55 Thrips’,‘56 alfalfa seed chalcid’,‘57 Pieris canidia’,‘58 Apolygus lucorum’,‘59 Limacodidae’,‘6 rice gall midge’,‘60 Viteus vitifoliae’,‘61 Colomerus vitis’,‘62 Brevipoalpus lewisi McGregor’,‘63 oides decempunctata’,‘64 Polyphagotars onemus latus’,‘65 Pseudococcus comstocki Kuwana’,‘66 parathrene regalis’,‘67 Ampelophaga’,‘68 Lycorma delicatula’,‘69 Xylotrechus’,‘7 Rice Stemfly’,‘70 Cicadella viridis’,‘71 Miridae’,‘72 Trialeurodes vaporariorum’,‘73 Erythroneura apicalis’,‘74 Papilio xuthus’,‘75 Panonchus citri McGregor’,‘76 Phyllocoptes oleiverus ashmead’,‘77 Icerya purchasi Maskell’,‘78 Unaspis yanonensis’,‘79 Ceroplastes rubens’,‘8 brown plant hopper’,‘80 Chrysomphalus aonidum’,‘81 Parlatoria zizyphus Lucus’,‘82 Nipaecoccus vastalor’,‘83 Aleurocanthus spiniferus’,‘84 Tetradacus c Bactrocera minax’,‘85 Dacus dorsalis-Hendel-’,‘86 Bactrocera tsuneonis’,‘87 Prodenia litura’,‘88 Adristyrannus’,‘89 Phyllocnistis citrella Stainton’,‘9 white backed plant hopper’,‘90 Toxoptera citricidus’,‘91 Toxoptera aurantii’,‘92 Aphis citricola Vander Goot’,‘93 Scirtothrips dorsalis Hood’,‘94 Dasineura sp’,‘96 Salurnis marginella Guerr’,‘97 Deporaus marginatus Pascoe’]

每个类别标注的框数:

1 rice leaf roller(稻纵卷叶螟)框数 = 154

10 small brown plant hopper(灰飞虱)框数 = 91

11 rice water weevil(稻水象甲)框数 = 611

12 rice leafhopper(稻叶蝉)框数 = 186

13 grain spreader thrips(稻管蓟马)框数 = 58

14 rice shell pest(稻苞虫)框数 = 21

15 grub(蛴螬)框数 = 241

16 mole cricket(蝼蛄)框数 = 31

17 wireworm(金针虫)框数 = 111

18 white margined moth(白边地老虎)框数 = 150

19 black cutworm(小地老虎)框数 = 387

2 rice leaf caterpillar(稻毛虫)框数 = 117

20 large cutworm(大地老虎)框数 = 85

21 yellow cutworm(黄地老虎)框数 = 36

22 red spider(红蜘蛛)框数 = 456

23 corn borer(玉米螟)框数 = 119

24 army worm(黏虫)框数 = 44

25 aphids(蚜虫)框数 = 22

26 Potosiabre vitarsis(苹毛金龟子)框数 = 83

27 peach borer(桃蛀螟)框数 = 27

28 english grain aphid(麦长管蚜)框数 = 76

29 green bug(麦二叉蚜)框数 = 74

3 paddy stem maggot(稻秆蝇)框数 = 595

30 bird cherry-oataphid(禾谷缢管蚜)框数 = 110

31 wheat blossom midge(麦红吸浆虫)框数 = 30

32 penthaleus major(麦圆蜘蛛)框数 = 94

33 longlegged spider mite(麦长腿蜘蛛)框数 = 28

34 wheat phloeothrips(小麦皮蓟马)框数 = 106

35 wheat sawfly(小麦叶蜂)框数 = 79

36 cerodonta denticornis(麦鞘毛眼水蝇)框数 = 176

37 beet fly(甜菜潜叶蝇)框数 = 166

38 flea beetle(跳甲)框数 = 309

39 cabbage army worm(甘蓝夜蛾)框数 = 25

4 asiatic rice borer(二化螟)框数 = 158

40 beet army worm(甜菜夜蛾)框数 = 30

41 Beet spot flies(甜菜斑蝇)框数 = 83

42 meadow moth(草地螟)框数 = 145

43 beet weevil(甜菜象甲)框数 = 72

44 sericaorient alismots chulsky(东方绢金龟)框数 = 29

45 alfalfa weevil(苜蓿叶象)框数 = 111

46 flax budworm(苜蓿夜蛾)框数 = 48

47 alfalfa plant bug(苜蓿盲蝽)框数 = 50

48 tarnished plant bug(牧草盲蝽)框数 = 67

49 Locustoidea(蝗虫)框数 = 68

5 yellow rice borer(三化螟)框数 = 205

50 lytta polita(苹芫菁)框数 = 55

51 legume blister beetle(豆芫菁)框数 = 21

52 blister beetle(芫菁)框数 = 136

53 therioaphis maculata Buckton(苜蓿斑蚜)框数 = 193

54 odontothrips loti(牛角花齿蓟马)框数 = 26

55 Thrips(蓟马)框数 = 72

56 alfalfa seed chalcid(苜蓿籽蜂)框数 = 74

57 Pieris canidia(东方菜粉蝶)框数 = 23

58 Apolygus lucorum(绿盲蝽)框数 = 187

59 Limacodidae(刺蛾)框数 = 241

6 rice gall midge(稻瘿蚊)框数 = 1345

60 Viteus vitifoliae(葡萄根瘤蚜)框数 = 61

61 Colomerus vitis(葡萄锈壁虱)框数 = 15

62 Brevipoalpus lewisi McGregor(刘氏短须螨)框数 = 81

63 oides decempunctata(葡萄十星叶甲)框数 = 1

64 Polyphagotars onemus latus(侧多食跗线螨)框数 = 56

65 Pseudococcus comstocki Kuwana(康氏粉蚧)框数 = 63

66 parathrene regalis(葡萄透翅蛾)框数 = 53

67 Ampelophaga(葡萄天蛾)框数 = 12

68 Lycorma delicatula(斑衣蜡蝉)框数 = 12

69 Xylotrechus(葡萄虎天牛)框数 = 131

7 Rice Stemfly(稻潜蝇)框数 = 46

70 Cicadella viridis(大青叶蝉)框数 = 9

71 Miridae(盲蝽科)框数 = 95

72 Trialeurodes vaporariorum(温室白粉虱)框数 = 11

73 Erythroneura apicalis(桃一点叶蝉)框数 = 40

74 Papilio xuthus(柑橘凤蝶)框数 = 163

75 Panonchus citri McGregor(柑橘全爪螨)框数 = 44

76 Phyllocoptes oleiverus ashmead(柑橘锈壁虱)框数 = 15

77 Icerya purchasi Maskell(吹绵蚧)框数 = 28

78 Unaspis yanonensis(矢尖蚧)框数 = 32

79 Ceroplastes rubens(红蜡蚧)框数 = 37

8 brown plant hopper(褐飞虱)框数 = 78

80 Chrysomphalus aonidum(褐圆蚧)框数 = 37

81 Parlatoria zizyphus Lucus(黑点蚧)框数 = 8

82 Nipaecoccus vastalor(堆蜡粉蚧)框数 = 35

83 Aleurocanthus spiniferus(黑刺粉虱)框数 = 2

84 Tetradacus c Bactrocera minax(柑橘大实蝇)框数 = 51

85 Dacus dorsalis-Hendel-(橘小实蝇)框数 = 269

86 Bactrocera tsuneonis(日本蜜柑蝇)框数 = 15

87 Prodenia litura(斜纹夜蛾)框数 = 10

88 Adristyrannus(阿德瑞斯缇兰努斯蜂)框数 = 9

89 Phyllocnistis citrella Stainton(柑橘潜叶蛾)框数 = 15

9 white backed plant hopper(白背飞虱)框数 = 79

90 Toxoptera citricidus(橘蚜)框数 = 14

91 Toxoptera aurantii(茶蚜)框数 = 14

92 Aphis citricola Vander Goot(绣线菊蚜)框数 = 29

93 Scirtothrips dorsalis Hood(茶黄蓟马)框数 = 9

94 Dasineura sp(吸浆虫)框数 = 4

96 Salurnis marginella Guerr(青翅飞虱)框数 = 9

97 Deporaus marginatus Pascoe(梨虎象)框数 = 2

总框数=10031

使用标注工具:labelImg

标注规则:对类别进行画矩形框

重要说明:暂无

特别声明:本数据集不对训练的模型或者权重文件精度作任何保证

图片预览:




标注例子:


【训练信息】

训练集图片数=5963

验证集图片数=1704

训练map=48.8%

训练精度(Precision)=52.5%

训练召回率(Recall)=45.0%

【验证集精度】

类别=Map50(%)

MAP50

all=49

1 rice leaf roller=98

10 small brown plant hopper=38

11 rice water weevil=63

12 rice leafhopper=15

13 grain spreader thrips=13

14 rice shell pest=88

15 grub=44

16 mole cricket=83

17 wireworm=8

18 white margined moth=37

19 black cutworm=99

2 rice leaf caterpillar=26

20 large cutworm=82

21 yellow cutworm=73

22 red spider=70

23 corn borer=67

24 army worm=85

25 aphids=50

26 Potosiabre vitarsis=88

27 peach borer=9

28 english grain aphid=80

29 green bug=59

3 paddy stem maggot=79

30 bird cherry-oataphid=74

31 wheat blossom midge=11

32 penthaleus major=8

33 longlegged spider mite=36

34 wheat phloeothrips=76

35 wheat sawfly=69

36 cerodonta denticornis=41

37 beet fly=80

38 flea beetle=95

39 cabbage army worm=40

4 asiatic rice borer=66

40 beet army worm=46

41 Beet spot flies=65

42 meadow moth=62

43 beet weevil=47

44 sericaorient alismots chulsky=85

45 alfalfa weevil=31

46 flax budworm=0

47 alfalfa plant bug=46

48 tarnished plant bug=87

49 Locustoidea=25

5 yellow rice borer=46

50 lytta polita=55

51 legume blister beetle=34

52 blister beetle=99

53 therioaphis maculata Bucktnotallow=63

54 odontothrips loti=25

55 Thrips=86

56 alfalfa seed chalcid=58

57 Pieris canidia=11

58 Apolygus lucorum=55

59 Limacodidae=73

6 rice gall midge=96

60 Viteus vitifoliae=8

61 Colomerus vitis=63

62 Brevipoalpus lewisi McGregor=18

64 Polyphagotars onemus latus=53

65 Pseudococcus comstocki Kuwana=57

66 parathrene regalis=37

68 Lycorma delicatula=100

69 Xylotrechus=6

7 Rice Stemfly=30

70 Cicadella viridis=27

71 Miridae=21

72 Trialeurodes vaporariorum=40

73 Erythroneura apicalis=7

74 Papilio xuthus=56

75 Panonchus citri McGregor=38

76 Phyllocoptes oleiverus ashmead=27

77 Icerya purchasi Maskell=49

78 Unaspis yannotallow=36

79 Ceroplastes rubens=70

8 brown plant hopper=84

80 Chrysomphalus anotallow=52

81 Parlatoria zizyphus Lucus=5

82 Nipaecoccus vastalor=85

84 Tetradacus c Bactrocera minax=32

85 Dacus dorsalis-Hendel-=79

86 Bactrocera tsunenotallow=1

88 Adristyrannus=8

9 white backed plant hopper=23

90 Toxoptera citricidus=25

91 Toxoptera aurantii=100

92 Aphis citricola Vander Goot=2

93 Scirtothrips dorsalis Hood=58

94 Dasineura sp=5

96 Salurnis marginella Guerr=0

97 Deporaus marginatus Pascoe=0

安装依赖

pip install -r requirements.txt

数据库迁移

python manage.py makemigrations
python manage.py migrate

运行项目

python manage.py runserver

访问 ​http://127.0.0.1:8000​

默认登录信息

  • 用户名: admin
  • 密码: admin

项目主要文件结构

yolo11-django-deepseek-det-system/
├── manage.py                 # Django 管理脚本
├── yolo_detection/           # 项目配置目录
│   ├── __init__.py
│   ├── settings.py          # 项目设置
│   ├── urls.py               # 主 URL 配置
│   └── wsgi.py               # WSGI 配置
├── detection/                # 检测应用
│   ├── __init__.py
│   ├── apps.py               # 应用配置
│   ├── forms.py              # 表单定义
│   ├── models.py             # 数据模型
│   ├── urls.py               # 应用 URL 配置
│   └── views.py              # 视图函数
├── templates/                # 模板目录
├── test_img/                # 测试图片目录
│   ├── index.html            # 主页面
│   └── login.html            # 登录页面
├── static/                   # 静态文件目录
├── media/                    # 媒体文件目录
│   └── uploads/              # 上传文件目录
├── requirements.txt          # 依赖列表
├── weights/                # 模板目录
│   ├── yolov11n.onnx            # 模型文件
│   └── results.png            # 训练日志图片
│   ├── class_names            # 模型类别文件
│   └── 模型说明.txt            # 训练简单介绍和训练过程map0.5参数

技术栈

  • Django 4.2+
  • YOLO11 (Ultralytics)
  • OpenCV
  • DeepSeek API
  • Chart.js
  • HTML5/CSS3/JavaScript

注意事项

  • 确保 ​​yolov11n.onnx​​ 模型文件在项目weights目录
  • DeepSeek API 密钥需要在 ​​settings.py​​ 中配置
  • 建议使用 Python 3.8+

常用评估参数介绍

在目标检测任务中,评估模型的性能是至关重要的。你提到的几个术语是评估模型性能的常用指标。下面是对这些术语的详细解释:

Class: 这通常指的是模型被设计用来检测的目标类别。例如,一个模型可能被训练来检测车辆、行人或动物等不同类别的对象。

Images: 表示验证集中的图片数量。验证集是用来评估模型性能的数据集,与训练集分开,以确保评估结果的公正性。 Instances: 在所有图片中目标对象的总数。这包括了所有类别对象的总和,例如,如果验证集包含100张图片,每张图片平均有5个目标对象,则Instances为500。

P(精确度Precision): 精确度是模型预测为正样本的实例中,真正为正样本的比例。计算公式为:Precision = TP / (TP + FP),其中TP表示真正例(True Positives),FP表示假正例(False Positives)。

R(召回率Recall): 召回率是所有真正的正样本中被模型正确预测为正样本的比例。计算公式为:Recall = TP / (TP + FN),其中FN表示假负例(False Negatives)。

mAP50: 表示在IoU(交并比)阈值为0.5时的平均精度(mean Average Precision)。IoU是衡量预测框和真实框重叠程度的指标。mAP是一个综合指标,考虑了精确度和召回率,用于评估模型在不同召回率水平上的性能。在IoU=0.5时,如果预测框与真实框的重叠程度达到或超过50%,则认为该预测是正确的。

mAP50-95: 表示在IoU从0.5到0.95(间隔0.05)的范围内,模型的平均精度。这是一个更严格的评估标准,要求预测框与真实框的重叠程度更高。在目标检测任务中,更高的IoU阈值意味着模型需要更准确地定位目标对象。mAP50-95的计算考虑了从宽松到严格的多个IoU阈值,因此能够更全面地评估模型的性能。 这些指标共同构成了评估目标检测模型性能的重要框架。通过比较不同模型在这些指标上的表现,可以判断哪个模型在实际应用中可能更有效。

常见问题

目标检测训练中,Mean Average Precision(MAP)偏低可能有以下原因: 原因一:欠拟合:如果训练数据量过小,模型可能无法学习到足够的特征,从而影响预测效果,导致欠拟合,进而使MAP偏低。因此可以加大数据集数量

原因二:小目标:如果数据集包含大部分小目标则一般会有可能产生map偏低情况,因为小目标特征不明显,模型很难学到特征。

原因三:模型调参不对:比如学习率调整过大可能会导致学习能力过快,模型参数调节出现紊乱

原因四:过拟合(现在模型基本不存在这种情况):如果模型在训练数据上表现非常好,但在验证或测试数据上表现较差,可能是出现了过拟合。这通常是因为模型参数过多,而训练数据量相对较小,导致模型学习到了训练数据中的噪声或特定模式,而无法泛化到新的数据。如今现在目标检测模型都对这个情况做的很好,很少有这种情况发生。

原因五:场景不一样:验证集验证精度高,测试集不行,则有可能是与训练模型场景图片不一致导致测试map过低 针对以上原因,可以采取以下措施来提高MAP:

(1)优化模型结构:根据任务和数据集的特点选择合适的模型,并尝试使用不同的网络架构和构件来改进模型性能。

(2)增强数据预处理:对数据进行适当的预处理和增强,如数据归一化、缺失值填充、数据扩增等,以提高模型的泛化能力。

(3)调整损失函数:尝试使用不同的损失函数或组合多种损失函数来优化模型性能。

(4)优化训练策略:调整学习率、批次大小、训练轮数等超参数,以及使用学习率衰减、动量等优化算法来改善模型训练效果。

(5)使用预训练模型:利用在大规模数据集上预训练的模型进行迁移学习,可以加速模型收敛并提高性能。 (6)增加数据集数量

提供的文件

python源码

yolo11n.onnx模型(不提供pytorch模型)

训练的map,P,R曲线图(在weights\results.png)

测试图片(在test_img文件夹下面)

注意提供数据集在数据集地址.xlsx文件中

创作时间: