转自AI Studio,原文链接:​​​​​​【AI Workshop】PaddleDetection番茄目标果检测 - 飞桨AI Studio

1、项目内容

随着日常饮食的逐渐丰富,以番茄为原料的食品种类也在不断地增多。在当下劳动力日渐匮乏的时代,人工采摘番茄耗时耗力,生产成本很高,应大力发展智能采摘设备,提高采摘效率。针对番茄采摘过程中,番茄果实目标识别不准确以及无法对番茄串采摘点定位的问题,开展基于深度学习的温室内番茄果实目标识别,可以准确地识别出重叠的番茄果实,希望通过视频监控->目标检测->智能采摘的方式智能、高效的完成此任务。

为解决以上问题,我们选用飞桨目标检测开发套件PaddleDetection来完成,PaddleDetection提供了非常丰富的目标检测模型,项目要求模型精度高、速度达标,本项目采用多种模型,yolov3、ppyolov2和ppyoloe训练进行对比

PaddleDetection为基于飞桨PaddlePaddle的端到端目标检测套件,内置30+模型算法250+预训练模型,覆盖目标检测、实例分割、跟踪、关键点检测等方向,其中包括服务器端和移动端高精度、轻量级产业级SOTA模型、冠军方案和学术前沿算法,并提供配置化的网络模块组件、十余种数据增强策略和损失函数等高阶优化支持和多种部署方案,在打通数据处理、模型开发、训练、压缩、部署全流程的基础上,提供丰富的案例及教程,加速算法产业落地应用。

提供目标检测、实例分割、多目标跟踪、关键点检测等多种能力 应用场景覆盖工业、智慧城市、安防、交通、零售、医疗等十余种行业

  • 模型丰富: 包含目标检测实例分割人脸检测关键点检测多目标跟踪250+个预训练模型,涵盖多种全球竞赛冠军方案。
  • 使用简洁:模块化设计,解耦各个网络组件,开发者轻松搭建、试用各种检测模型及优化策略,快速得到高性能、定制化的算法。
  • 端到端打通: 从数据增强、组网、训练、压缩、部署端到端打通,并完备支持云端/边缘端多架构、多设备部署。
  • 高性能: 基于飞桨的高性能内核,模型训练速度及显存占用优势明显。支持FP16训练, 支持多机训练。

最终模型效果展示如下:

视频地址

2、环境要求

  • PaddlePaddle = 2.2.2

  • Python = 3.7

  • PaddleDetection = 2.4

  • paddlex =2.1.0

3、环境配置

In [ ]

# 下载PaddleDetection代码
# 只有第一次运行本项目时需要执行
!git clone https://gitee.com/paddlepaddle/PaddleDetection
Cloning into 'PaddleDetection'...
remote: Enumerating objects: 23983, done.
remote: Counting objects: 100% (4453/4453), done.
remote: Compressing objects: 100% (2058/2058), done.
Receiving objects:  20% (4876/23983), 7.46 MiB | 714.00 KiB/s

In [ ]

# 下载依赖
# 每次启动项目后都需要先执行
!pip install -r PaddleDetection/requirements.txt

In [ ]

# 更换当前路径 编译安装paddledet
%cd PaddleDetection
!python setup.py install
#  返回主目录
%cd 

In [ ]

#  查看gpu版本号
!cat /usr/local/cuda/version.txt
CUDA Version 10.1.243

In [ ]

#  下载对应的版本
!python -m pip install paddlepaddle-gpu==2.3.0.post101 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html

4、数据集准备

本项目使用的数据集是:番茄采摘数据集 该数据集已加载至本环境中,位于:data/data142431/archive (5).zip 本基线系统使用的数据格式是PascalVOC格式
先将data/data142431/目录下archive (5).zip重命名为tomato.zip

In [ ]

# 解压数据
!unzip -o -q -d  /home/aistudio/work /home/aistudio/data/data142431/tomato.zip
#  重命名annotations文件夹名称
!mv work/annotations work/Annotations
#  重命名images文件夹名称
!mv work/images work/JPEGImages

In [ ]

#  安装paddlex:为了方便切分数据集
!pip install paddlex==2.1.0

In [ ]

# 切分数据集
!paddlex --split_dataset --format VOC --dataset_dir work --val_value 0.2 --test_value 0.1

划分完成后,该数据集下会生成labels.txt, train_list.txt, val_list.txt和test_list.txt,分别存储类别信息,训练样本列表,验证样本列表,测试样本列表。如下图所示:

将voc数据集转换为coco格式

In [ ]

# 训练集
%cd PaddleDetection/
'''
paramsdataset_type: 原数据格式voc_anno_dir: xml标注文件夹voc_anno_list: 训练集列表voc_label_list: 类别标签voc_out_name: 输出json文件
'''
!python tools/x2coco.py \--dataset_type voc \--voc_anno_dir /home/aistudio/work \--voc_anno_list /home/aistudio/work/train_list.txt \--voc_label_list /home/aistudio/work/labels.txt \--voc_out_name /home/aistudio/work/coco_train.json
[Errno 2] No such file or directory: 'PaddleDetection/'
/home/aistudio/PaddleDetection
Start converting !
100%|██████████████████████████████████████| 627/627 [00:00<00:00, 10028.52it/s]

In [ ]

# 验证集
!python tools/x2coco.py \--dataset_type voc \--voc_anno_dir /home/aistudio/work/ \--voc_anno_list /home/aistudio/work/val_list.txt \--voc_label_list /home/aistudio/work/labels.txt \--voc_out_name /home/aistudio/work/coco_val.json
Start converting !
100%|██████████████████████████████████████| 179/179 [00:00<00:00, 11010.93it/s]

In [ ]

# 测试集
!python tools/x2coco.py \--dataset_type voc \--voc_anno_dir /home/aistudio/work/ \--voc_anno_list /home/aistudio/work/test_list.txt \--voc_label_list /home/aistudio/work/labels.txt \--voc_out_name /home/aistudio/work/coco_test.json
Start converting !
100%|█████████████████████████████████████████| 89/89 [00:00<00:00, 8498.61it/s]

In [ ]

%cd
/home/aistudio

5. 模型选择

套件结构概览

Architectures Backbones Components Data Augmentation
  • Object Detection

    • Faster RCNN
    • FPN
    • Cascade-RCNN
    • Libra RCNN
    • Hybrid Task RCNN
    • PSS-Det
    • RetinaNet
    • YOLOv3
    • YOLOv4
    • PP-YOLOv1/v2
    • PP-YOLO-Tiny
    • SSD
    • CornerNet-Squeeze
    • FCOS
    • TTFNet
    • PP-PicoDet
    • DETR
    • Deformable DETR
    • Swin Transformer
    • Sparse RCNN
  • Instance Segmentation
    • Mask RCNN
    • SOLOv2
  • Face Detection
    • FaceBoxes
    • BlazeFace
    • BlazeFace-NAS
  • Multi-Object-Tracking
    • JDE
    • FairMOT
    • DeepSort
  • KeyPoint-Detection
    • HRNet
    • HigherHRNet
  • ResNet(&vd)
  • ResNeXt(&vd)
  • SENet
  • Res2Net
  • HRNet
  • Hourglass
  • CBNet
  • GCNet
  • DarkNet
  • CSPDarkNet
  • VGG
  • MobileNetv1/v3
  • GhostNet
  • Efficientnet
  • BlazeNet
  • Common

    • Sync-BN
    • Group Norm
    • DCNv2
    • Non-local
  • KeyPoint

    • DarkPose
  • FPN

    • BiFPN
    • BFP
    • HRFPN
    • ACFPN
  • Loss

    • Smooth-L1
    • GIoU/DIoU/CIoU
    • IoUAware
  • Post-processing

    • SoftNMS
    • MatrixNMS
  • Speed

    • FP16 training
    • Multi-machine training
  • Resize
  • Lighting
  • Flipping
  • Expand
  • Crop
  • Color Distort
  • Random Erasing
  • Mixup
  • Mosaic
  • Cutmix
  • Grid Mask
  • Auto Augment
  • Random Perspective

PaddleDetection 提供了非常丰富的目标检测模型,这里我们选择yolov3、ppyolov2和ppyoloe训练进行对比 以ppyoloe配置为例

6. 模型训练

通常一个项目模型完整的落地流程可以总结为如下6个步骤,其中需要根据评估和预测的结果,对模型进行反复的优化和再训练:

也可以参考 PaddleDetecion 提供的 快速上手指南。另外,在实际项目的推进过程中,可以根据实际情况决定是否采用模型压缩的相关手段。

6.1 ppyoloe 的配置文件

ppyoloe_crn_s_300e_coco 的配置文件,由 1 个入口配置文件,和5个相关联的子配置文件组成。入口配置文件位于:

PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml

相关的 5 个子配置文件为:

_BASE_: ['../datasets/coco_detection.yml','../runtime.yml','./_base_/optimizer_300e.yml','./_base_/ppyoloe_crn.yml','./_base_/ppyoloe_reader.yml',
]

6.1.1 数据集配置文件 coco_detection.yml

设置数据集的配置信息。根据本案例的情况,请按照如下内容进行修改

metric: COCO
num_classes: 2TrainDataset:!COCODataSetimage_dir: JPEGImagesanno_path: coco_train.jsondataset_dir: /home/aistudio/workdata_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd']EvalDataset:!COCODataSetimage_dir: JPEGImagesanno_path: coco_val.jsondataset_dir: /home/aistudio/workTestDataset:!ImageFolderanno_path: coco_test.json # also support txt (like VOC's label_list.txt)dataset_dir: /home/aistudio/work # if set, anno_path will be 'dataset_dir/anno_path'

6.1.2 运行时配置文件 runtime.yml

用于设置运行时的参数,主要包括:

use_gpu:  是否使用GPU训练
use_xpu:  是否使用XPU训练
log_iter:  显示训练信息的间隔
save_dir:  模型保存路径
snapshot_epoch: 保存模型的间隔
# Exporting the model: 与导出模型相关的设置

这里我们暂且保留默认值,不做修改即可。

6.1.3 模型网络参数 ppyoloe_crn.yml

用于设置模型的网络参数,也包括预训练集的加载,这里为了可以快速开始实际训练,我们也暂时保留默认的参数,不做修改。

6.1.4 训练优化参数 optimizer_300e.yml

主要说明了学习率和优化器的配置。其中比较重要的参数是训练轮数 epoch 和 学习率 base_lr。同样,我们暂时不在这里修改,稍后再设置。

6.1.5 数据读取器配置参数ppyoloe_reader.yml

主要说明了在训练时读取数据集的配置参数,其中比较重要的有:

sample_transforms / batch_transforms: 数据增强算子
batch_size:  批量大小
worker_num:  并发加载子进程数
resize:  读取后的预处理大小

6.1.6 修改入口配置文件PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml

这是控制模型训练的主配置文件,其中设置的参数会覆盖掉子配置文件中的相关参数。在主配置文件内集中修改参数,可以更方便的修改训练参数,避免要修改的参数过于分散。

按如下内容修改主配置文件的内容:

_BASE_: ['../datasets/coco_detection.yml','../runtime.yml','./_base_/optimizer_300e.yml','./_base_/ppyoloe_crn.yml','./_base_/ppyoloe_reader.yml',
]log_iter: 100
snapshot_epoch: 2
weights: output/ppyoloe_crn_s_300e_coco/model_finalpretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_s_pretrained.pdparams
depth_mult: 0.33
width_mult: 0.50TrainReader:batch_size: 12LearningRate:base_lr: 0.001epoch: 200LearningRate:base_lr: 0.025schedulers:- !CosineDecaymax_epochs: 360- !LinearWarmupstart_factor: 0.epochs: 5OptimizerBuilder:optimizer:momentum: 0.9type: Momentumregularizer:factor: 0.0005type: L2

其中:

  • Batch Size指模型在训练过程中,前向计算一次(即为一个step)所用到的样本数量
  • 如若使用多卡训练, batch_size会均分到各张卡上(因此需要让batch size整除卡数)
  • Batch Size跟机器的显存/内存高度相关,batch_size越高,所消耗的显存/内存就越高
  • PP-YOLOE模型训练过程中使用8 GPUs进行混合精度训练,如果GPU卡数或者batch size发生了改变,需要按照公式 lrnew = lrdefault * (batch_sizenew * GPU_numbernew) / (batch_sizedefault * GPU_numberdefault) 调整学习率。

6.2 开始训练

In [ ]

#  yolov3_darknet53训练数据
!export CUDA_VISIBLE_DEVICES=0
!python  PaddleDetection/tools/train.py -c PaddleDetection/configs/yolov3/yolov3_darknet53_270e_voc.yml

In [ ]

#  ppyolo/ppyolov2训练数据
!export CUDA_VISIBLE_DEVICES=0
!python  PaddleDetection/tools/train.py -c PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml

In [5]

# ppyoloe_crn_s训练数据
!export CUDA_VISIBLE_DEVICES=0
!python PaddleDetection/tools/train.py -c PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml -r output/ppyoloe_crn_s_300e_coco/239.pdparams

7、模型评估

In [ ]

#评估yolov3_darknet53模型
!export CUDA_VISIBLE_DEVICES=0
!python PaddleDetection/tools/eval.py -c PaddleDetection/configs/yolov3/yolov3_darknet53_270e_voc.yml -o weights=output/yolov3_darknet53_270e_voc/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
W0519 19:02:17.224961 25187 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0519 19:02:17.229497 25187 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[05/19 19:02:20] ppdet.utils.checkpoint INFO: Finish loading model weights: output/yolov3_darknet53_270e_voc/model_final.pdparams
[05/19 19:02:20] ppdet.engine INFO: Eval iter: 0
[05/19 19:02:24] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[05/19 19:02:24] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 84.04%
[05/19 19:02:24] ppdet.engine INFO: Total sample number: 89, averge FPS: 20.824143558391864

In [ ]

#评估ppyolov2_r50vd模型
!export CUDA_VISIBLE_DEVICES=0
!python PaddleDetection/tools/eval.py -c PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml -o weights=output/ppyolov2_r50vd_dcn_voc/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
W0519 18:39:34.264786 23682 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0519 18:39:34.269814 23682 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[05/19 18:39:38] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyolov2_r50vd_dcn_voc/model_final.pdparams
[05/19 18:39:38] ppdet.engine INFO: Eval iter: 0
[05/19 18:39:43] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[05/19 18:39:43] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 87.50%
[05/19 18:39:43] ppdet.engine INFO: Total sample number: 89, averge FPS: 18.75877683866569

In [7]

#评估ppyoloe_crn_s_300e模型
!export CUDA_VISIBLE_DEVICES=0
!python PaddleDetection/tools/eval.py -c PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml -o weights=output/ppyoloe_crn_s_300e_coco/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
W0524 20:57:11.320129 26383 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0524 20:57:11.324745 26383 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[05/24 20:57:15] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_s_300e_coco/model_final.pdparams
[05/24 20:57:15] ppdet.engine INFO: Eval iter: 0
[05/24 20:57:22] ppdet.metrics.metrics INFO: The bbox result is saved to bbox.json.
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[05/24 20:57:22] ppdet.metrics.coco_utils INFO: Start evaluate...
Loading and preparing results...
DONE (t=0.08s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=1.94s).
Accumulating evaluation results...
DONE (t=0.17s).Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.473Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.853Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.466Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.306Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.503Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.627Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.128Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.475Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.589Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.467Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.616Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.715
[05/24 20:57:25] ppdet.engine INFO: Total sample number: 179, averge FPS: 25.355280069172952
yolov3_darknet53 ppyolov2_r50vd ppyoloe_crn_s_300e
mAP(.50) 84.04% 87.50% 85.30%
FPS 20.82 18.75 25.35

在同等计算量的前提下,评估三个模型
我们可以看到百度自研算法ppyoloe无论是速度还是精度都是非常强大的。

8、模型导出

将模型模型导出保存在./inference_model

In [ ]

#  yolov3_darknet53模型导出
!python PaddleDetection/tools/export_model.py -c PaddleDetection/configs/yolov3/yolov3_darknet53_270e_voc.yml --output_dir=./inference_model -o weights=output/yolov3_darknet53_270e_voc/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
[05/15 16:54:05] ppdet.utils.checkpoint INFO: Finish loading model weights: output/yolov3_darknet53_270e_voc/model_final.pdparams
[05/15 16:54:05] ppdet.engine INFO: Export inference config file to ./inference_model/yolov3_darknet53_270e_voc/infer_cfg.yml
W0515 16:54:09.442514 17021 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0515 16:54:09.442566 17021 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[05/15 16:54:19] ppdet.engine INFO: Export model and saved in ./inference_model/yolov3_darknet53_270e_voc

In [ ]

# ppyolov2_r50vd 模型导出
!python PaddleDetection/tools/export_model.py -c PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml --output_dir=./inference_model -o weights=output/ppyolov2_r50vd_dcn_voc/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
[05/19 18:44:34] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyolov2_r50vd_dcn_voc/model_final.pdparams
[05/19 18:44:34] ppdet.engine INFO: Export inference config file to ./inference_model/ppyolov2_r50vd_dcn_voc/infer_cfg.yml
W0519 18:44:39.328130 24180 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0519 18:44:39.328193 24180 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[05/19 18:44:44] ppdet.engine INFO: Export model and saved in ./inference_model/ppyolov2_r50vd_dcn_voc

In [8]

# ppyoloe 模型导出
!python PaddleDetection/tools/export_model.py -c PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml --output_dir=./inference_model -o weights=output/ppyoloe_crn_s_300e_coco/model_final.pdparams
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
[05/24 21:01:52] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_s_300e_coco/model_final.pdparams
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
[05/24 21:01:52] ppdet.engine INFO: Export inference config file to ./inference_model/ppyoloe_crn_s_300e_coco/infer_cfg.yml
W0524 21:01:55.423156 26759 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0524 21:01:55.423204 26759 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[05/24 21:01:58] ppdet.engine INFO: Export model and saved in ./inference_model/ppyoloe_crn_s_300e_coco

9、预测

9.1 图片预测

In [ ]

#  图片预测
!python PaddleDetection/deploy/python/infer.py --model_dir=inference_model/yolov3_darknet53_270e_voc --image_file=work/JPEGImages/tomato87.png --device=GPU

In [ ]

#  图片预测
!python PaddleDetection/deploy/python/infer.py --model_dir=inference_model/ppyolov2_r50vd_dcn_voc --image_file=work/JPEGImages/tomato87.png --device=GPU

9.2设置参数预测

draw_threshold设置为0.6,输出结果保存在在infer_output

In [ ]

!export CUDA_VISIBLE_DEVICES=0 #windows和Mac下不需要执行该命令
!python PaddleDetection/tools/infer.py -c PaddleDetection/configs/ppyolo/ppyolov2_r50vd_dcn_voc.yml \--infer_img=work/JPEGImages/tomato130.png \--output_dir=infer_output/ \--draw_threshold=0.6 \-o weights=output/ppyolov2_r50vd_dcn_voc/model_final.pdparams \--use_vdl=Ture
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:130: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
W0523 18:45:00.956478  2780 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0523 18:45:00.961278  2780 device_context.cc:465] device: 0, cuDNN Version: 7.6.
[05/23 18:45:05] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyolov2_r50vd_dcn_voc/model_final.pdparams
100%|█████████████████████████████████████████████| 1/1 [00:00<00:00,  4.19it/s]
[05/23 18:45:05] ppdet.engine INFO: Detection bbox results save in infer_output/tomato130.png

In [ ]

!export CUDA_VISIBLE_DEVICES=0 #windows和Mac下不需要执行该命令
!python PaddleDetection/tools/infer.py -c PaddleDetection/configs/ppyoloe/ppyoloe_crn_s_300e_coco.yml \--infer_img=work/JPEGImages/tomato130.png \--output_dir=infer_output/ \--draw_threshold=0.6 \-o weights=output/ppyoloe_crn_s_300e_coco/model_final.pdparams \--use_vdl=Ture
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecationsif data.dtype == np.object:
W0524 17:23:10.575150 30581 gpu_context.cc:278] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1
W0524 17:23:10.579721 30581 gpu_context.cc:306] device: 0, cuDNN Version: 7.6.
[05/24 17:23:13] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_crn_s_300e_coco/109.pdparams
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
100%|█████████████████████████████████████████████| 1/1 [00:00<00:00,  4.89it/s]
[05/24 17:23:13] ppdet.engine INFO: Detection bbox results save in infer_output/tomato130.png

9.3 视频预测

输出视频保存在output/

In [9]

#  视频预测
!python PaddleDetection/deploy/python/infer.py --model_dir=inference_model/ppyoloe_crn_s_300e_coco --video_file=tomato.mp4 --device=GPU

10 活动总结

AI Workshop是面向深度学习爱好者的开源活动,邀请PPDE或领航团技术大牛作为领航团开源导师,手把手指导成员完成开源项目。 在这个过程中呢,从无知到认知,学会了很多很多东西,为将来的就业打下基础。同时开始渐渐喜欢上了这个的专业,感受到学习的过程才是最完美的。 非常感谢高睿导师的指导,也非常感谢百度飞桨能够提供这样的机会。

关于作者:华北理工大学轻工学院物联网工程专业大二学生 付文昌 肖一多 陈亮

基于目标检测的番茄采摘模型相关推荐

  1. 助力质量生产,基于目标检测模型MobileNetV2-YOLOv3-Lite实现PCB电路板缺陷检测

    在很多需要机械性重复性工作的场景中,使用AI技术来进行检测识别能够实现更高的效率以及更高的质量,比如:按键.测温.质控等等. 在前面的一些文章中,我也写过有关质量相关的检测类文中,今天的实践与此相关, ...

  2. 服务医学,基于目标检测模型实现细胞检测识别

    在我以往的认知里面,显微镜下面的世界是很神奇的存在,可能只平时接触到的绝大多数是都是宏观的世界吧,看到微观世界里面各色各样的生物.细胞就会觉得很神奇,电子显微镜往往都是医生来操作观察的,对于采样.病理 ...

  3. 【看论文】之《基于双目视觉的棚室番茄采摘关键技术研究_胡慧明》

    论文信息 题目:<基于双目视觉的棚室番茄采摘关键技术研究> 作者:胡慧明 单位:湖北工业大学 论文性质:硕士学位论文 提交日期:2018.5.31 摘要 绪论 国外研究现状 20世纪60年 ...

  4. 《南溪的目标检测学习笔记》——模型预处理的学习笔记

    1 介绍 在目标检测任务中,模型预处理分为两个步骤: 图像预处理:基于图像处理算法 数值预处理:基于机器学习理论 关于图像预处理,请参考<南溪的目标检测学习笔记>--图像预处理的学习笔记 ...

  5. 基于目标检测的海上舰船图像超分辨率研究

    基于目标检测的海上舰船图像超分辨率研究 人工智能技术与咨询 来源:< 图像与信号处理> ,作者张坤等 关键词: 目标检测:生成对抗网络:超分辨率 摘要: 针对海上舰船图像有效像素在整体像素 ...

  6. 让AI帮你玩游戏(一) 基于目标检测用几个样本帮你实现在魔兽世界中钓鱼(群已满)

    让AI帮你玩游戏 让AI帮你玩游戏(一) 基于目标检测用几个样本实现在魔兽世界中钓鱼 前言 思路 环境 获取图像(几个样本即可) 标记图片 从标记文件中获取Boxes坐标 搭建目标检测模型 准备训练数 ...

  7. 目标检测 YOLOv5 - 如何提高模型的指标,提高精确率,召回率,mAP等

    目标检测 YOLOv5 - 如何提高模型的指标,提高精确率,召回率,mAP等 flyfish 文中包括了YOLOv5作者分享的提高模型指标小技巧和吴恩达(Andrew Ng)在做缺陷检测项目( ste ...

  8. 百度飞桨开源Open Images Dataset V5目标检测比赛最好单模型MSF-DET

    目标检测是计算机视觉领域中的核心任务.Open Images Dataset V5(OIDV5)是目前规模最大的目标检测公开数据集[1].基于飞桨(PaddlePaddle)的PaddleDetect ...

  9. 无人机基于目标检测的路径规划任务

    无人机目标检测相机配置 目标检测基于darknet-yolo框架,darknet用于C/C++代码实现,适用于嵌入式设备上的目标检测 更改目标检测相机 使用RGB-D相机的左摄像头而不是单目相机,修改 ...

最新文章

  1. 深度学习---TensorFlow学习笔记:搭建CNN模型
  2. 华人小哥开发“CG工坊”,帮你快速入门计算机图形学 | GitHub热榜
  3. E数据结构实验之查找五:平方之哈希表
  4. web.xml中load-on-startup的作用
  5. 算法竞赛入门经典(第二版) | 例题5-2 木块问题 (紫皮书牛啤!)(UVa101,The Blocks Problem)
  6. Rails之格式化价格方法
  7. luogu p1652 圆
  8. 实践与交流:采取“硬刷”方式完美激活Windows 7旗舰版的具体方法步骤(图文详解教程)...
  9. PhotoShop简单案例(4)——利用ps制作正在加载中动画(loading.gif)
  10. 【工科数学分析】2021-10-01-工科数学分析叒复习(一)
  11. 宝鸡渭滨区11―12学年度第一学期高二期末联考试卷高二地理
  12. LPRNet车牌识别算法?其实没有想象那么难
  13. Linux 基本命令入门
  14. 任正非,马云,马化腾:真正顶级厉害的人,都有一个共同特点
  15. 数值算法之adjacent_difference
  16. selenium tbody表单获取封装函数
  17. 上研究生学计算机去河大学校好不好,河南大学研究生,河南大学研究生值得读吗?...
  18. 【开源】.net微服务开发引擎Anno 让复杂的事简单点- 日志、链路追踪一目了然 (上)
  19. Reverse Engineering the NC ECU (revisited) -- SH7508
  20. 用Python来表白,把情书写进她的照片里

热门文章

  1. thinkphp整合系列之融云即时通讯在线聊天
  2. visual studio 2019/vs2019 大括号的风格
  3. Mysql-Explain用法详解
  4. np.polyfit()
  5. 【SWT组件】内容滚动组件 ScrolledComposite
  6. 小猪的爆炸以及加分的实现
  7. Mybatis解决数据库Blob类型存储与读取问题
  8. 五一堵车 | AI“高速”车辆检测轻而易举监测大家安全
  9. js arguments参数使用和详解
  10. android html转ubb,简单的Html转换UBB的程序