【校园AI Day-AI workshop】交通信号标志图像分类

本文介绍基于PP-PicoDet_LCNet的中国交通标志分类检测项目。通过安装相关环境,处理数据集为COCO格式,用PP-PicoDet模型训练,验证集和测试集mAP(0.5)约98.9%,还进行了模型预测、导出及量化训练等,量化模型精度略有下降。

☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜

【校园ai day-ai workshop】交通信号标志图像分类 - 创想鸟

基于PicoDet_LCNet的中国交通标志图像的分类检测

1. 项目说明

对于交通标志识别系统,其核心作用就是可以准确并及时的识别道路交通标志信息获取当前路况以及行车环境,从而起到提醒和辅助驾驶员对道路信息的把控以及纠正错误交通行为的作用。传统的目标检测算法容易受到多种因素影响导致算法实现困难、识别精度低、识别速率慢等问题。

为解决以上问题,最终选用飞桨目标检测开发套件PaddleDetection中的全新的轻量级系列模型PP-PicoDet,该模型在移动端具有卓越的性能,成为全新SOTA轻量级模型。详细的技术细节可以参考arXiv技术报告。模型效果如 图1 所示。

【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟图1 交通标志识别效果图

2. 安装说明

2.1 运行环境

PaddlePaddle >= 2.2.2Python >= 3.5PaddleSlim >= 2.2.2PaddleLite >= 2.10

2.2 解压安装

提供了修改配置文件的PaddleDetection代码以及训练好的模型,解压即可。

In [1]

!unzip -q PaddleDetection.zip

2.3克隆安装

如果想下载PaddleDetection源码,执行如下命令

In [1]

# !git clone https://github.com/PaddlePaddle/PaddleDetection.git -b develop --depth 1# 可使用国内gitee镜像!git clone https://gitee.com/paddlepaddle/PaddleDetection.git
正克隆到 'PaddleDetection'...remote: Enumerating objects: 23983, done.remote: Counting objects: 100% (4453/4453), done.remote: Compressing objects: 100% (2058/2058), done.remote: Total 23983 (delta 3212), reused 3376 (delta 2387), pack-reused 19530接收对象中: 100% (23983/23983), 264.01 MiB | 8.81 MiB/s, 完成.处理 delta 中: 100% (17761/17761), 完成.检查连接... 完成。

In [ ]

# 安装其他依赖%cd /home/aistudio/PaddleDetection/!pip install -r requirements.txt # 编译安装paddledet!python setup.py install# 安装模型压缩的工具库,提供剪裁、量化、蒸馏、和模型结构搜索等模型压缩策略!pip install paddleslim

注:更多安装教程请参考安装文档

3. 数据准备

3.1 数据集介绍

本案例使用数据集来源于 中国交通标志数据集的PascalVOC版本。该数据集数据分为三类:warning,prohibitory,mandatory,共13,829张图片。这里按7:1:2 分割训练集、验证集和测试集,其中包含9,680张训练集图片,1,382张验证集图片,2,767张测试集图片,部分图片如 图2 所示:

@@##@@@@##@@@@##@@@@##@@图2 数据集示例(可点击放大)

源数据格式为VOC格式,存储格式如下:

dataset    ├── Annotations    │   ├── 000000.xml    │   ├── 000001.xml    │   ├── 000002.xml    │   |   ...    ├── Images    │   ├── 000000.jpg    │   ├── 000001.jpg    │   ├── 000002.jpg    │   |   ...├── label_list.txt (必须提供)├── train.txt (训练数据集文件列表, ./Images/000000.jpg ./Annotations/xxx1.xml)├── valid.txt (测试数据集文件列表)

通过如下命令将图片格式处理为COCO格式,执行一次即可。

In [3]

# 首先解压数据集%cd /home/aistudio# 创建解压目录!mkdir dataset# 解压数据集!unzip -d dataset -q /home/aistudio/data/data51578/CCTSDB_VOC.zip# -d: 指定解压目录# -q: 不输出解压详情
/home/aistudio

3.2 数据集转为COCO格式

In [4]

# 训练集%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/dataset/         --voc_anno_list /home/aistudio/dataset/train_list.txt         --voc_label_list /home/aistudio/dataset/labels.txt         --voc_out_name /home/aistudio/dataset/coco_train.json
/home/aistudio/PaddleDetectionStart converting !100%|████████████████████████████████████| 9680/9680 [00:00<00:00, 16720.55it/s]

In [5]

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

In [6]

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

代码执行完成后数据集文件组织结构为:

    ├── coco_train.json    ├── coco_val.json    ├── coco_test.json    │    ...    ├── Images    │   ├── 000000.jpg    │   ├── 000001.jpg    │   ├── 000002.jpg    │   ├── ...

4. 模型选择

4.1 PP-PicoDet介绍

本次任务要求速度快和精度高,因此我们选择PaddleDetection提出的全新轻量级系列模型PP-PicoDet,模型有如下特点:

更高的mAP: 第一个在1M参数量之内mAP(0.5:0.95)超越30+(输入416像素时)。更快的预测速度: 网络预测在ARM CPU下可达150FPS。部署友好: 支持PaddleLite/MNN/NCNN/OpenVINO等预测库,支持转出ONNX,提供了C++/Python/Android的demo。先进的算法: 我们在现有SOTA算法中进行了创新, 包括:ESNet, CSP-PAN, SimOTA等等。【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟图3 PP-PicoDet与其他模型比较

4.2 PP-PicoDet预训练模型

PP-PicoDet提供了多种在COCO数据上的预训练模型,如下表所示:

模型 输入尺寸 mAPval
0.5:0.95 mAPval
0.5 参数量
(M) FLOPS
(G) 预测时延CPU
(ms) 预测时延Lite
(ms) 权重下载 配置文件 导出模型

PicoDet-XS320*32023.536.10.700.673.9ms7.81msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-XS416*41626.239.30.701.136.1ms12.38msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-S320*32029.143.41.180.974.8ms9.56msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-S416*41632.547.61.181.656.6ms15.20msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-M320*32034.450.03.462.578.2ms17.68msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-M416*41637.553.43.464.3412.7ms28.39msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-L320*32036.152.05.804.2011.5ms25.21msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-L416*41639.455.75.807.1020.7ms42.23msmodel | logconfigw/ 后处理 | w/o 后处理PicoDet-L640*64042.659.25.8016.8162.5ms108.1msmodel | logconfigw/ 后处理 | w/o 后处理表1 PP-PicoDet预训练模型

5. 模型训练

5.1 修改训练配置文件

本项目采用PP-PicoDet作为交通标志识别的模型,模型训练需要经过几个步骤:

首先修改configs/datasets/coco_detection.yml

数据集包含的类别数:num_classes包含训练集、验证集、测试集的图片路径image_dir、标注json文件路径anno_path、数据集路径dataset_dir

metric: COCOnum_classes: 3TrainDataset:  !COCODataSet    image_dir: JPEGImages    anno_path: coco_train.json    dataset_dir: /home/aistudio/dataset    data_fields: ['image', 'gt_bbox', 'gt_class', 'is_crowd']EvalDataset:  !COCODataSet    image_dir: JPEGImages    anno_path: coco_val.json    dataset_dir: /home/aistudio/datasetTestDataset:  !ImageFolder    anno_path: coco_test.json #labels.txt # also support txt (like VOC's label_list.txt)    dataset_dir: /home/aistudio/dataset # if set, anno_path will be 'dataset_dir/anno_path'

然后修改configs/picodet/picodet_l_640_coco_lcnet.yml

预训练模型:pretrain_weights

训练超参数:epoch、batch_size、base_lr

详细配置文件改动和说明。

学习率换算方法: lr_new = lr_default * (batch_size_new * gpu_number_new) / (batch_size_default * gpu_number_default)

_BASE_: [  '../datasets/coco_detection.yml',  '../runtime.yml',  '_base_/picodet_v2.yml',  '_base_/optimizer_300e.yml',  '_base_/picodet_640_reader.yml',]pretrain_weights: https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/legendary_models/PPLCNet_x2_0_pretrained.pdparamsweights: output/picodet_l_640_coco/best_modelfind_unused_parameters: Trueuse_ema: trueepoch: 200snapshot_epoch: 10LCNet:  scale: 2.0  feature_maps: [3, 4, 5]LCPAN:  out_channels: 160PicoHeadV2:  conv_feat:    name: PicoFeat    feat_in: 160    feat_out: 160    num_convs: 4    num_fpn_stride: 4    norm_type: bn    share_cls_reg: True    use_se: True  feat_in_chan: 160LearningRate:  base_lr: 0.015   #0.06  schedulers:  - !CosineDecay    max_epochs: 300  - !LinearWarmup    start_factor: 0.1    steps: 300TrainReader:  batch_size: 12

最后启动训练

图像转图像AI 图像转图像AI

利用AI轻松变形、风格化和重绘任何图像

图像转图像AI 65 查看详情 图像转图像AI

PaddleDetection提供了单卡/多卡训练模型,满足用户多种训练需求,具体代码如下:

5.2 开始训练

In [ ]

# 单卡GPU上训练!export CUDA_VISIBLE_DEVICES=0 !python tools/train.py -c configs/picodet/picodet_l_640_coco_lcnet.yml                        --use_vdl True --eval#中断后可使用 -r 继续训练# !export CUDA_VISIBLE_DEVICES=0 # !python tools/train.py -c configs/picodet/picodet_l_640_coco_lcnet.yml #                        -r output/picodet_l_640_coco_lcnet/75.pdparams #                        --use_vdl True --eval

5.3 数据可视化

@@##@@loss图@@##@@bbox-mAP图@@##@@loss_bbox图

5.4 训练轮次对比

在不区分图片大小的情况下(area=all):

训练轮次 mAP(.50:0.95) mAP(.50) mAR(.50:0.95) averge FPS

49轮0.8040.9910.83424.0659轮0.8050.9900.83625.0569轮0.8060.9890.83625.09best_model0.8090.9890.83925.85

6. 模型评估

使用训练好的模型在验证集上进行评估,具体代码如下:

In [3]

# 评估!export CUDA_VISIBLE_DEVICES=0!python tools/eval.py -c configs/picodet/picodet_l_640_coco_lcnet.yml               -o weights=output/picodet_l_640_coco_lcnet/best_model.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:W0523 21:37:33.806679   663 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1W0523 21:37:33.811025   663 device_context.cc:465] device: 0, cuDNN Version: 7.6.loading annotations into memory...Done (t=0.01s)creating index...index created![05/23 21:37:37] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_l_640_coco_lcnet/best_model.pdparams[05/23 21:37:39] ppdet.engine INFO: Eval iter: 0[05/23 21:38:10] ppdet.engine INFO: Eval iter: 100[05/23 21:38:32] ppdet.metrics.metrics INFO: The bbox result is saved to bbox.json.loading annotations into memory...Done (t=0.59s)creating index...index created![05/23 21:38:32] ppdet.metrics.coco_utils INFO: Start evaluate...Loading and preparing results...DONE (t=0.49s)creating index...index created!Running per image evaluation...Evaluate annotation type *bbox*DONE (t=2.98s).Accumulating evaluation results...DONE (t=0.53s). Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.809 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.989 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.961 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.769 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.861 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.934 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.649 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.839 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.839 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.807 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.887 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.944[05/23 21:38:37] ppdet.engine INFO: Total sample number: 1382, averge FPS: 25.858773913913232

使用数据集中9,680张图片(整个数据集的70%)训练的模型,在包含1,382张图片的验证集上评估,效果如下,mAP(0.5)=98.9%,mAR(0.5:0.95)=83.9%

【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟图5 模型在验证集上评估结果

在包含2,677张图片的测试集上评估,效果如下,mAP(0.5)=98.9%,mAR(0.5:0.95)=84.8%

更换评估数据集可修改configs/datasets/coco_detection.yml中EvalDataset下anno_path的值,如coco_test.json

【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟图6 模型在测试集上评估结果

7. 模型预测

加载训练好的模型,置信度阈值设置为0.5,执行下行命令对验证集或测试集图片进行预测:

In [5]

!export CUDA_VISIBLE_DEVICES=0'''    -c:指定模型配置文件    --infer_img:测试图片    --output_dir:结果输出位置    --draw_threshold:置信度阈值    -o weights:加载训练好的模型'''!python tools/infer.py -c configs/picodet/picodet_l_640_coco_lcnet.yml                     --infer_img=/home/aistudio/dataset/JPEGImages/008839.jpg                     --output_dir=infer_output/                     --draw_threshold=0.5                     -o weights=output/picodet_l_640_coco_lcnet/best_model.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:W0523 22:12:12.803400  3736 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1W0523 22:12:12.807762  3736 device_context.cc:465] device: 0, cuDNN Version: 7.6.[05/23 22:12:14] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_l_640_coco_lcnet/best_model.pdparamsloading annotations into memory...Done (t=0.01s)creating index...index created!100%|█████████████████████████████████████████████| 1/1 [00:00<00:00,  3.99it/s][05/23 22:12:15] ppdet.engine INFO: Detection bbox results save in infer_output/008839.jpg

7.1 预测效果

原图结果图@@##@@@@##@@@@##@@@@##@@@@##@@@@##@@@@##@@@@##@@表2 交通标记识别效果图(点图放大)

8. 模型导出

在模型训练过程中保存的模型文件是包含前向预测和反向传播的过程,在实际的工业部署则不需要反向传播,因此需要将模型进行导成部署需要的模型格式。 执行下面命令,即可导出模型

In [6]

!export CUDA_VISIBLE_DEVICES=0!python tools/export_model.py       -c configs/picodet/picodet_l_640_coco_lcnet.yml       -o weights=output/picodet_l_640_coco_lcnet/best_model.pdparams       --output_dir=inference_model
/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/23 22:13:23] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_l_640_coco_lcnet/best_model.pdparamsloading annotations into memory...Done (t=0.01s)creating index...index created![05/23 22:13:23] ppdet.engine INFO: Export inference config file to inference_model/picodet_l_640_coco_lcnet/infer_cfg.ymlW0523 22:13:27.917946  3852 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1W0523 22:13:27.918013  3852 device_context.cc:465] device: 0, cuDNN Version: 7.6.[05/23 22:13:30] ppdet.engine INFO: Export model and saved in inference_model/picodet_l_640_coco_lcnet

预测模型会导出到inference_model/目录下,包括model.pdmodel、model.pdiparams、model.pdiparams.info和infer_cfg.yml四个文件,分别表示模型的网络结构、模型权重、模型权重名称和模型的配置文件(包括数据预处理参数等)的流程配置文件。

更多关于模型导出的文档,请参考模型导出文档

9. 模型推理

使用以下命令对导出的推理模型进行预测,详细教程请参考Python端预测部署:

In [29]

!export CUDA_VISIBLE_DEVICES=0'''    --model_dir: 上述导出的模型路径    --image_file:需要测试的图片    --image_dir:也可以指定要测试的文件夹路径    --device:运行时的设备,可选择CPU/GPU/XPU,默认为CPU    --output_dir:可视化结果保存的根目录,默认为output/'''!python deploy/python/infer.py         --model_dir=./inference_model/picodet_l_640_coco_lcnet         --image_file=/home/aistudio/dataset/JPEGImages/008327.jpg         --device=GPU
-----------  Running Arguments -----------action_file: Nonebatch_size: 1camera_id: -1cpu_threads: 1device: GPUenable_mkldnn: Falseenable_mkldnn_bfloat16: Falseimage_dir: Noneimage_file: /home/aistudio/dataset/JPEGImages/008327.jpgmodel_dir: ./inference_model/picodet_l_640_coco_lcnetoutput_dir: outputrandom_pad: Falsereid_batch_size: 50reid_model_dir: Nonerun_benchmark: Falserun_mode: paddlesave_images: Falsesave_mot_txt_per_img: Falsesave_mot_txts: Falsescaled: Falsethreshold: 0.5tracker_config: Nonetrt_calib_mode: Falsetrt_max_shape: 1280trt_min_shape: 1trt_opt_shape: 640use_dark: Trueuse_gpu: Falsevideo_file: Nonewindow_size: 50-----------------------------------------------------  Model Configuration -----------Model Arch: GFLTransform Order: --transform op: Resize--transform op: NormalizeImage--transform op: Permute--------------------------------------------class_id:0, confidence:0.9360, left_top:[716.70,76.82],right_bottom:[761.55,118.69]class_id:0, confidence:0.9119, left_top:[649.82,103.49],right_bottom:[678.15,139.18]class_id:0, confidence:0.6749, left_top:[572.66,129.77],right_bottom:[588.33,145.87]save result to: output/008327.jpgTest iter 0------------------ Inference Time Info ----------------------total_time(ms): 1701.7, img_num: 1average latency time(ms): 1701.70, QPS: 0.587648preprocess_time(ms): 1690.10, inference_time(ms): 11.50, postprocess_time(ms): 0.10

10. 模型量化训练

10.1 修改量化训练配置文件

通过模型量化可以提升模型速度。

我们在之前训练好的模型基础上进行量化训练,执行如下代码开始量化训练:

1)我们需要修改’configs/slim/quant/picodet_s_quant.yml’量化配置文件,将pretrain_weights参数改为量化前训练好的模型。

2)如果模型报错,调小picodet_s_quant.yml文件中的batch_size,并同时根据batch_size调整学习率lr。

#pretrain_weights: https://paddledet.bj.bcebos.com/models/picodet_s_320_coco.pdparamspretrain_weights: /home/aistudio/PaddleDetection/output/picodet_l_640_coco_lcnet/best_model.pdparamsslim: QATQAT:  quant_config: {    'activation_preprocess_type': 'PACT',    'weight_quantize_type': 'channel_wise_abs_max',     'activation_quantize_type': 'moving_average_abs_max',    'weight_bits': 8, 'activation_bits':8, 'dtype': 'int8', 'window_size': 10000, 'moving_rate': 0.9,    'quantizable_layer_type': ['Conv2D', 'Linear']}  print_model: Falseepoch: 50LearningRate:  base_lr: 0.000025 #0.001  schedulers:  - !PiecewiseDecay    gamma: 0.1    milestones:    - 30    - 40  - !LinearWarmup    start_factor: 0.    steps: 100TrainReader:  batch_size:  12 #96

10.2 开始量化训练

In [ ]

# 动态量化训练,单卡训练'''    -c: 指定模型配置文件    --slim_config: 量化配置文件'''!export CUDA_VISIBLE_DEVICES=0!python tools/train.py             -c configs/picodet/picodet_l_640_coco_lcnet.yml             --slim_config configs/slim/quant/picodet_s_quant.yml --eval# 如中断 可用-r参数继续量化训练# !python tools/train.py #             -c configs/picodet/picodet_l_640_coco_lcnet.yml #             --slim_config configs/slim/quant/picodet_s_quant.yml #             -r output/picodet_s_quant/34.pdparams --eval

10.3 模型评估及效果对比

In [21]

# 量化训练结束,同上可进行模型评估,只是需要增加slim_config!export CUDA_VISIBLE_DEVICES=0!python tools/eval.py -c configs/picodet/picodet_l_640_coco_lcnet.yml              --slim_config configs/slim/quant/picodet_s_quant.yml              -o weights=output/picodet_s_quant/best_model
/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 22:59:59.601784  7220 device_context.cc:447] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 10.1W0523 22:59:59.606324  7220 device_context.cc:465] device: 0, cuDNN Version: 7.6.[05-23 23:00:01 MainThread @logger.py:242] Argv: tools/eval.py -c configs/picodet/picodet_l_640_coco_lcnet.yml --slim_config configs/slim/quant/picodet_s_quant.yml -o weights=output/picodet_s_quant/best_model[05-23 23:00:01 MainThread @utils.py:79] WRN paddlepaddle version: 2.2.2. The dynamic graph version of PARL is under development, not fully tested and supported[05/23 23:00:04] ppdet.utils.checkpoint INFO: Finish loading model weights: output/picodet_s_quant/best_model.pdparamsloading annotations into memory...Done (t=0.01s)creating index...index created![05/23 23:00:09] ppdet.engine INFO: Eval iter: 0[05/23 23:00:41] ppdet.engine INFO: Eval iter: 100[05/23 23:01:06] ppdet.metrics.metrics INFO: The bbox result is saved to bbox.json.loading annotations into memory...Done (t=0.01s)creating index...index created![05/23 23:01:06] ppdet.metrics.coco_utils INFO: Start evaluate...Loading and preparing results...DONE (t=0.66s)creating index...index created!Running per image evaluation...Evaluate annotation type *bbox*DONE (t=3.38s).Accumulating evaluation results...DONE (t=0.64s). Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.773 Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.984 Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.935 Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.732 Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.821 Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.920 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.624 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.805 Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.805 Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.772 Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.852 Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.932[05/23 23:01:10] ppdet.engine INFO: Total sample number: 1382, averge FPS: 23.959119777169736

训练的量化模型,在 area=all 的情况下不同轮次的效果:

训练轮次 mAP(.50:0.95) mAP(.50) mAR(.50:0.95) averge FPS

10轮0.7570.9810.79325.09820轮0.7670.9810.80022.03930轮0.7710.9840.80525.15440轮0.7720.9840.80521.953best_model0.7730.9840.80523.959

10.4 使用量化模型预测

In [ ]

!export CUDA_VISIBLE_DEVICES=0# 使用量化模型预测!python tools/infer.py -c configs/picodet/picodet_l_640_coco_lcnet.yml                       --slim_config configs/slim/quant/picodet_s_quant.yml                       --infer_img=/home/aistudio/dataset/JPEGImages/008839.jpg                       --output_dir=slim_infer_output                       --draw_threshold=0.5                       -o weights=output/picodet_s_quant/best_model.pdparams

In [19]

import cv2import matplotlib.pyplot as pltimport numpy as npimage = cv2.imread('slim_infer_output/008839.jpg')plt.figure(figsize=(7,7))plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))plt.show()

10.5 量化模型导出

In [ ]

# 模型导出!export CUDA_VISIBLE_DEVICES=0!python tools/export_model.py       -c configs/picodet/picodet_l_640_coco_lcnet.yml       --slim_config configs/slim/quant/picodet_s_quant.yml       -o weights=output/picodet_s_quant/best_model.pdparams       --output_dir=inference_model# 将inference模型配置转化为json格式#!python deploy/lite/convert_yml_to_json.py inference_model/picodet_s_quant/infer_cfg.yml

In [25]

# 量化后的模型导出!ls -lh inference_model/picodet_s_quant/
总用量 29M-rw-r--r-- 1 aistudio aistudio 1.1K 5月  23 22:43 infer_cfg.json-rw-r--r-- 1 aistudio aistudio  509 5月  23 23:02 infer_cfg.yml-rw-r--r-- 1 aistudio aistudio  23M 5月  23 23:02 model.pdiparams-rw-r--r-- 1 aistudio aistudio 193K 5月  23 23:02 model.pdiparams.info-rw-r--r-- 1 aistudio aistudio 6.1M 5月  23 23:02 model.pdmodel

10.6 量化模型推理

In [30]

!export CUDA_VISIBLE_DEVICES=0# 量化后模型推理!python deploy/python/infer.py         --model_dir=./inference_model/picodet_s_quant         --image_file=/home/aistudio/dataset/JPEGImages/008327.jpg         --device=GPU
-----------  Running Arguments -----------action_file: Nonebatch_size: 1camera_id: -1cpu_threads: 1device: GPUenable_mkldnn: Falseenable_mkldnn_bfloat16: Falseimage_dir: Noneimage_file: /home/aistudio/dataset/JPEGImages/008327.jpgmodel_dir: ./inference_model/picodet_s_quantoutput_dir: outputrandom_pad: Falsereid_batch_size: 50reid_model_dir: Nonerun_benchmark: Falserun_mode: paddlesave_images: Falsesave_mot_txt_per_img: Falsesave_mot_txts: Falsescaled: Falsethreshold: 0.5tracker_config: Nonetrt_calib_mode: Falsetrt_max_shape: 1280trt_min_shape: 1trt_opt_shape: 640use_dark: Trueuse_gpu: Falsevideo_file: Nonewindow_size: 50-----------------------------------------------------  Model Configuration -----------Model Arch: GFLTransform Order: --transform op: Resize--transform op: NormalizeImage--transform op: Permute--------------------------------------------class_id:0, confidence:0.9245, left_top:[716.23,76.58],right_bottom:[762.66,119.49]class_id:0, confidence:0.9099, left_top:[648.96,104.52],right_bottom:[678.67,139.30]class_id:0, confidence:0.6850, left_top:[572.70,129.55],right_bottom:[589.45,146.79]save result to: output/008327.jpgTest iter 0------------------ Inference Time Info ----------------------total_time(ms): 1740.3, img_num: 1average latency time(ms): 1740.30, QPS: 0.574614preprocess_time(ms): 1724.70, inference_time(ms): 15.50, postprocess_time(ms): 0.10

【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟【校园AI Day-AI workshop】交通信号标志图像分类 - 创想鸟

以上就是【校园AI Day-AI workshop】交通信号标志图像分类的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/318948.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年11月5日 09:03:43
下一篇 2025年11月5日 09:06:07

相关推荐

  • Uniapp 中如何不拉伸不裁剪地展示图片?

    灵活展示图片:如何不拉伸不裁剪 在界面设计中,常常需要以原尺寸展示用户上传的图片。本文将介绍一种在 uniapp 框架中实现该功能的简单方法。 对于不同尺寸的图片,可以采用以下处理方式: 极端宽高比:撑满屏幕宽度或高度,再等比缩放居中。非极端宽高比:居中显示,若能撑满则撑满。 然而,如果需要不拉伸不…

    2025年12月24日
    400
  • 如何让小说网站控制台显示乱码,同时网页内容正常显示?

    如何在不影响用户界面的情况下实现控制台乱码? 当在小说网站上下载小说时,大家可能会遇到一个问题:网站上的文本在网页内正常显示,但是在控制台中却是乱码。如何实现此类操作,从而在不影响用户界面(UI)的情况下保持控制台乱码呢? 答案在于使用自定义字体。网站可以通过在服务器端配置自定义字体,并通过在客户端…

    2025年12月24日
    800
  • 如何在地图上轻松创建气泡信息框?

    地图上气泡信息框的巧妙生成 地图上气泡信息框是一种常用的交互功能,它简便易用,能够为用户提供额外信息。本文将探讨如何借助地图库的功能轻松创建这一功能。 利用地图库的原生功能 大多数地图库,如高德地图,都提供了现成的信息窗体和右键菜单功能。这些功能可以通过以下途径实现: 高德地图 JS API 参考文…

    2025年12月24日
    400
  • 如何使用 scroll-behavior 属性实现元素scrollLeft变化时的平滑动画?

    如何实现元素scrollleft变化时的平滑动画效果? 在许多网页应用中,滚动容器的水平滚动条(scrollleft)需要频繁使用。为了让滚动动作更加自然,你希望给scrollleft的变化添加动画效果。 解决方案:scroll-behavior 属性 要实现scrollleft变化时的平滑动画效果…

    2025年12月24日
    000
  • 如何为滚动元素添加平滑过渡,使滚动条滑动时更自然流畅?

    给滚动元素平滑过渡 如何在滚动条属性(scrollleft)发生改变时为元素添加平滑的过渡效果? 解决方案:scroll-behavior 属性 为滚动容器设置 scroll-behavior 属性可以实现平滑滚动。 html 代码: click the button to slide right!…

    2025年12月24日
    500
  • 如何选择元素个数不固定的指定类名子元素?

    灵活选择元素个数不固定的指定类名子元素 在网页布局中,有时需要选择特定类名的子元素,但这些元素的数量并不固定。例如,下面这段 html 代码中,activebar 和 item 元素的数量均不固定: *n *n 如果需要选择第一个 item元素,可以使用 css 选择器 :nth-child()。该…

    2025年12月24日
    200
  • 使用 SVG 如何实现自定义宽度、间距和半径的虚线边框?

    使用 svg 实现自定义虚线边框 如何实现一个具有自定义宽度、间距和半径的虚线边框是一个常见的前端开发问题。传统的解决方案通常涉及使用 border-image 引入切片图片,但是这种方法存在引入外部资源、性能低下的缺点。 为了避免上述问题,可以使用 svg(可缩放矢量图形)来创建纯代码实现。一种方…

    2025年12月24日
    100
  • 如何解决本地图片在使用 mask JS 库时出现的跨域错误?

    如何跨越localhost使用本地图片? 问题: 在本地使用mask js库时,引入本地图片会报跨域错误。 解决方案: 要解决此问题,需要使用本地服务器启动文件,以http或https协议访问图片,而不是使用file://协议。例如: python -m http.server 8000 然后,可以…

    2025年12月24日
    200
  • 旋转长方形后,如何计算其相对于画布左上角的轴距?

    绘制长方形并旋转,计算旋转后轴距 在拥有 1920×1080 画布中,放置一个宽高为 200×20 的长方形,其坐标位于 (100, 100)。当以任意角度旋转长方形时,如何计算它相对于画布左上角的 x、y 轴距? 以下代码提供了一个计算旋转后长方形轴距的解决方案: const x = 200;co…

    2025年12月24日
    000
  • 旋转长方形后,如何计算它与画布左上角的xy轴距?

    旋转后长方形在画布上的xy轴距计算 在画布中添加一个长方形,并将其旋转任意角度,如何计算旋转后的长方形与画布左上角之间的xy轴距? 问题分解: 要计算旋转后长方形的xy轴距,需要考虑旋转对长方形宽高和位置的影响。首先,旋转会改变长方形的长和宽,其次,旋转会改变长方形的中心点位置。 求解方法: 计算旋…

    2025年12月24日
    000
  • 旋转长方形后如何计算其在画布上的轴距?

    旋转长方形后计算轴距 假设长方形的宽、高分别为 200 和 20,初始坐标为 (100, 100),我们将它旋转一个任意角度。根据旋转矩阵公式,旋转后的新坐标 (x’, y’) 可以通过以下公式计算: x’ = x * cos(θ) – y * sin(θ)y’ = x * …

    2025年12月24日
    000
  • 如何让“元素跟随文本高度,而不是撑高父容器?

    如何让 元素跟随文本高度,而不是撑高父容器 在页面布局中,经常遇到父容器高度被子元素撑开的问题。在图例所示的案例中,父容器被较高的图片撑开,而文本的高度没有被考虑。本问答将提供纯css解决方案,让图片跟随文本高度,确保父容器的高度不会被图片影响。 解决方法 为了解决这个问题,需要将图片从文档流中脱离…

    2025年12月24日
    000
  • 如何计算旋转后长方形在画布上的轴距?

    旋转后长方形与画布轴距计算 在给定的画布中,有一个长方形,在随机旋转一定角度后,如何计算其在画布上的轴距,即距离左上角的距离? 以下提供一种计算长方形相对于画布左上角的新轴距的方法: const x = 200; // 初始 x 坐标const y = 90; // 初始 y 坐标const w =…

    2025年12月24日
    200
  • CSS元素设置em和transition后,为何载入页面无放大效果?

    css元素设置em和transition后,为何载入无放大效果 很多开发者在设置了em和transition后,却发现元素载入页面时无放大效果。本文将解答这一问题。 原问题:在视频演示中,将元素设置如下,载入页面会有放大效果。然而,在个人尝试中,并未出现该效果。这是由于macos和windows系统…

    2025年12月24日
    200
  • 为什么 CSS mask 属性未请求指定图片?

    解决 css mask 属性未请求图片的问题 在使用 css mask 属性时,指定了图片地址,但网络面板显示未请求获取该图片,这可能是由于浏览器兼容性问题造成的。 问题 如下代码所示: 立即学习“前端免费学习笔记(深入)”; icon [data-icon=”cloud”] { –icon-cl…

    2025年12月24日
    200
  • 如何利用 CSS 选中激活标签并影响相邻元素的样式?

    如何利用 css 选中激活标签并影响相邻元素? 为了实现激活标签影响相邻元素的样式需求,可以通过 :has 选择器来实现。以下是如何具体操作: 对于激活标签相邻后的元素,可以在 css 中使用以下代码进行设置: li:has(+li.active) { border-radius: 0 0 10px…

    2025年12月24日
    100
  • 如何模拟Windows 10 设置界面中的鼠标悬浮放大效果?

    win10设置界面的鼠标移动显示周边的样式(探照灯效果)的实现方式 在windows设置界面的鼠标悬浮效果中,光标周围会显示一个放大区域。在前端开发中,可以通过多种方式实现类似的效果。 使用css 使用css的transform和box-shadow属性。通过将transform: scale(1.…

    2025年12月24日
    200
  • 如何计算旋转后的长方形在画布上的 XY 轴距?

    旋转长方形后计算其画布xy轴距 在创建的画布上添加了一个长方形,并提供其宽、高和初始坐标。为了视觉化旋转效果,还提供了一些旋转特定角度后的图片。 问题是如何计算任意角度旋转后,这个长方形的xy轴距。这涉及到使用三角学来计算旋转后的坐标。 以下是一个 javascript 代码示例,用于计算旋转后长方…

    2025年12月24日
    000
  • 为什么我的 Safari 自定义样式表在百度页面上失效了?

    为什么在 Safari 中自定义样式表未能正常工作? 在 Safari 的偏好设置中设置自定义样式表后,您对其进行测试却发现效果不同。在您自己的网页中,样式有效,而在百度页面中却失效。 造成这种情况的原因是,第一个访问的项目使用了文件协议,可以访问本地目录中的图片文件。而第二个访问的百度使用了 ht…

    2025年12月24日
    000
  • 如何用前端实现 Windows 10 设置界面的鼠标移动探照灯效果?

    如何在前端实现 Windows 10 设置界面中的鼠标移动探照灯效果 想要在前端开发中实现 Windows 10 设置界面中类似的鼠标移动探照灯效果,可以通过以下途径: CSS 解决方案 DEMO 1: Windows 10 网格悬停效果:https://codepen.io/tr4553r7/pe…

    2025年12月24日
    000

发表回复

登录后才能评论
关注微信