转自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/
'''
params
dataset_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 |
|
|
|
|
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: 2
TrainDataset:
!COCODataSet
image_dir: JPEGImages
anno_path: coco_train.json
dataset_dir: /home/aistudio/work
data_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd']
EvalDataset:
!COCODataSet
image_dir: JPEGImages
anno_path: coco_val.json
dataset_dir: /home/aistudio/work
TestDataset:
!ImageFolder
anno_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_final
pretrain_weights: https://paddledet.bj.bcebos.com/models/pretrained/CSPResNetb_s_pretrained.pdparams
depth_mult: 0.33
width_mult: 0.50
TrainReader:
batch_size: 12
LearningRate:
base_lr: 0.001
epoch: 200
LearningRate:
base_lr: 0.025
schedulers:
- !CosineDecay
max_epochs: 360
- !LinearWarmup
start_factor: 0.
epochs: 5
OptimizerBuilder:
optimizer:
momentum: 0.9
type: Momentum
regularizer:
factor: 0.0005
type: 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#deprecations if 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#deprecations if 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#deprecations if 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.473 Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.853 Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.466 Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.306 Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.503 Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.627 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.128 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.475 Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.589 Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.467 Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.616 Average 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#deprecations if 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#deprecations if 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#deprecations if 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#deprecations if 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#deprecations if 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或领航团技术大牛作为领航团开源导师,手把手指导成员完成开源项目。 在这个过程中呢,从无知到认知,学会了很多很多东西,为将来的就业打下基础。同时开始渐渐喜欢上了这个的专业,感受到学习的过程才是最完美的。 非常感谢高睿导师的指导,也非常感谢百度飞桨能够提供这样的机会。
关于作者:华北理工大学轻工学院物联网工程专业大二学生 付文昌 肖一多 陈亮