#run training example(1p) on Ascend/GPU by python command
python train.py \
--device_target="Ascend" \ # Ascend or GPU
--data_dir=xxx/dataset \
--is_distributed=0 \
--yolov5_version='yolov5s' \
--lr=0.01 \
--max_epoch=320 \
--warmup_epochs=4 > log.txt 2>&1 &
# run 1p by shell script, please change `device_target` in config file to run on Ascend/GPU, and change `T_max`, `max_epoch`, `warmup_epochs` refer to contents of notes
bash run_standalone_train.sh [DATASET_PATH]
# For Ascend device, distributed training example(8p) by shell script
bash run_distribute_train.sh [DATASET_PATH] [RANK_TABLE_FILE]
# For GPU device, distributed training example(8p) by shell script
bash run_distribute_train_gpu.sh [DATASET_PATH] [RANK_SIZE]
# run evaluation on Ascend/GPU by python command
python eval.py \
--device_target="Ascend" \ # Ascend or GPU
--data_dir=xxx/dataset \
--yolov5_version='yolov5s' \
--pretrained="***/*.ckpt" \
--eval_shape=640 > log.txt 2>&1 &
# run evaluation by shell script, please change `device_target` in config file to run on Ascend/GPU
bash run_eval.sh [DATASET_PATH] [CHECKPOINT_PATH]
DVPP is mandatory, and must choose from [“DVPP”, “CPU”], it’s case-insensitive. The DVPP hardware restricts width 16-alignment and height even-alignment. Therefore, the network needs to use the CPU operator to process images.
DATA_PATH is mandatory, path of the dataset containing images.
ANN_FILE is mandatory, path to annotation file.
DEVICE_ID is optional, default value is 0.
result
推断结果保存在当前路径中,您可以在acc.log文件中找到类似的结果。
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.369
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.573
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.395
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.218
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.418
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.482
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.298
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.501
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.557
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.395
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.619
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.677
基于mindspore的口罩识别项目
=======
Contents
YOLOv5 Description
YOLOv5于2020年4月发布,在COCO数据集上实现了最先进的目标检测性能。这是YoloV3的一个重要改进,主干中新架构的实施和颈部的修改使mAP(平均平均精度)提高了10%,FPS(每秒帧数)提高了12%。
code
Model Architecture
YOLOv5网络主要由作为主干的CSP和Focus、空间金字塔池(SPP)附加模块、PANet路径聚合颈部和YOLOv 3头部组成。CSP是一种新型的主干,可以增强CNN的学习能力。在CSP上添加空间金字塔池块,以增加感受野并分离出最重要的上下文特征。与YOLOv3中用于目标检测的特征金字塔网络(FPN)不同,PANet被用作不同检测器级别的参数聚合方法。更具体地说,CSPDarknet53包含5个CSP模块,它们使用卷积C,内核大小k=3x3,步长s=2x2;在PANet和SPP中,应用**1x1、5x5、9x9、13x13最大池。
Dataset
Dataset used: 数据集
数据集由小组成员自行制作和标注。
Quick Start
通过官方网站安装MindSpore后,您可以按照以下步骤开始训练和评估:
请注意default_config。yaml是8p上yolov5s的默认参数。Ascend和GPU上的batchsize和lr不同,请参阅scripts/run_distribute_train中的设置。sh或scripts/run_distribute_train_gpUsh。
Script Description
Script and Sample Code
Training Process
Training
For Ascend device, standalone training can be started like this:
在GPU上运行training 1p时,应微调参数
上面的python命令将在后台运行,您可以通过文件“log.txt”查看结果。
培训后,默认情况下,您将在outputs文件夹下获得一些检查点文件。loss值将按以下方式实现:
Evaluation Process
Evaluation
在运行下面的命令之前,请检查用于评估的检查点路径。以下脚本中使用的文件yolov5.ckpt是最后保存的检查点文件,但我们将其重命名为“yolov5.ckpt”。
上面的python命令将在后台运行。您可以通过文件“log.txt”查看结果。测试数据集的mAP如下:
Inference Process
Export MindIR
ckpt_file参数是必需的,
file_format
应在[“AIR”,“MINDIR”]中Infer on Ascend310
在执行推断之前,必须通过
export导出mindir文件。py
脚本。我们只提供了一个使用MINDIR模型进行推理的示例。 当前batch_Size只能设置为1。DVPP
is mandatory, and must choose from [“DVPP”, “CPU”], it’s case-insensitive. The DVPP hardware restricts width 16-alignment and height even-alignment. Therefore, the network needs to use the CPU operator to process images.DATA_PATH
is mandatory, path of the dataset containing images.ANN_FILE
is mandatory, path to annotation file.DEVICE_ID
is optional, default value is 0.result
推断结果保存在当前路径中,您可以在acc.log文件中找到类似的结果。
optimization
Attention Mechanism
本次任务对主干网络中加入了SE注意力机制,用于提高其精准度.
Loss Function
损失函数方面原本的YOLOv5使用的是GIOU_Loss,而我们将其改为CIOU_Loss,以提高边界框定位的精度,最终提高预测精度,其实现代码如下。