Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
skyous c0cbd64445 | 1 year ago | |
---|---|---|
md_show | 1 year ago | |
model_utils | 1 year ago | |
pycocotools | 1 year ago | |
src | 1 year ago | |
README.md | 1 year ago | |
default_config.yaml | 1 year ago | |
eval.py | 1 year ago | |
requirements.txt | 1 year ago | |
show_image.py | 1 year ago | |
test.py | 1 year ago | |
train.py | 1 year ago |
本项目通过使用mindspore框架、公开的口罩数据集,从头开始训练yolov4模型,复现口罩识别原理,上手简单易懂。使用自己训练好的模型也可以对自己的的数据进行口罩识别。
[插入口罩识别图像]
想法来源:
随着2023年的到来,世界也已经进入了后疫情时代,估计恢复到前疫情时代的管控也不远了。为了纪念疫情时代勤奋带口罩的自己,于是想用国产的mindspore进行口罩识别项目的开发,也顺便学习目标检测算法的使用。
目前的相关项目:
项目具体实现步骤:
由于数据集比较小,直接使用启智平台的调试模式,单卡昇腾910只要2小时即可完成训练。又或者使用本人上传的模型进行预测也可。
git clone https://openi.pcl.ac.cn/skyous/skyou202302021644323.git
cd ./基于yolov4的口罩识别
数据集大小只有10M,一下提供昇思大模型链接和启智平台链接,任选一个即可
git clone https://source-xihe.mindspore.cn/skyous/coco_mask.git
cd ./coco_mask
tar -xf coco_mask.tar.gz
解压出coco_dataset
文件夹。
下载页面
下载得到coco_mask.tar.gz
,解压即可得到coco_dataset
文件夹
tar -xf coco_mask.tar.gz
解压出coco_dataset
文件夹。
.
├── coco_dataset
│ ├── annotations
│ │ ├── train.json
│ │ └── val.json
│ ├── test_coco
│ │ ├── b059_1580797702173.jpg
│ │ ├── ...
│ │ └── d150_1580791063974.jpg
│ ├── train_coco
│ │ ├── b012_1580797660271.jpg
│ │ ├── ...
│ │ └── d90_1580791027740.jpg
│ └── val_coco
│ ├── b059_1580797702173.jpg
│ ├── ...
│ └── d150_1580791063974.jpg
请务必清除coco_dataset
的路径,下面步骤在训练和推理过程中需要用到!鄙人的数据集路径为../coco_dataset
。
涉及文件:./default_config.yaml
,如果你不知道如何配置,默认即可。
从头开始训练:
python ./train.py --data_dir ../coco_dataset
如果你不想从头开始训练,可以直接下载已经训练过的模型,对图片进行推理即可,下载链接
python test.py --test_data_dir ../coco_dataset/test_coco/ --pretrained ./outputs/2023-02-02_time_17_19_19/ckpt_0/best_map.ckpt --test_ignore_threshold 0.20
输出结果
2023-02-03 09:56:07,046:INFO:Creating Network....
2023-02-03 09:56:09,132:INFO:./outputs/2023-02-02_time_17_19_19/ckpt_0/best_map.ckpt
2023-02-03 09:56:11,196:INFO:load_model ./outputs/2023-02-02_time_17_19_19/ckpt_0/best_map.ckpt success
2023-02-03 09:56:11,210:INFO:testing shape : [608, 608]
2023-02-03 09:56:11,211:INFO:totol 26 images to eval
2023-02-03 09:56:11,221:INFO:Start inference....
[WARNING] ME(131213:281473401502400,MainProcess):2023-02-03-09:56:57.830.991 [mindspore/parallel/_utils.py:210] You are suggested to use mindspore.context.set_auto_parallel_context(parameter_broadcast=True) or mindspore.common.set_seed() to share parameters among multi-devices.
2023-02-03 09:56:59,017:INFO:Processing... 0.00%
2023-02-03 09:57:00,626:INFO:Calculating mAP...
2023-02-03 09:57:00,644:INFO:result file path: ./outputs/2023-02-03_time_09_56_07/predict_2023_02_03_09_57_00.json
python eval.py --pretrained ./outputs/2023-02-02_time_17_19_19/ckpt_0/best_map.ckpt --data_dir ../coco_dataset
结果输出:
=============coco eval reulst=========
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.540
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.829
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.682
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.696
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.602
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.396
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.278
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.596
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.596
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.713
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.662
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.441
2023-02-03 11:09:22,802:INFO:testing cost time 0.02 h
python show_image.py --imgs_path ../coco_dataset/test_coco/ --json_path ./outputs/2023-02-03_time_09_37_55/predict_2023_02_03_09_38_51.json --outpath ./predict_img
难点主要在数据如何进行预处理。
mindspore在model zoo上面有许多模型代码可以直接采用,直接跑通后再进行二次开发能够走少很多弯路。
为什么使用yolov4而不是yolov5:完全是由于鄙人学识太浅,当初连yolov4和yolov5的区别还不清楚就做了这个项目,按道理来说,yolov5和yolov4在此项目的开发应该基本没有太大差别。
鄙人由于一个比赛的兴趣,刚入门目标检测不到一个月,所以有些细节上面说的不对的,请多多包含。
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》