使用yolov5实现人脸是否佩戴口罩检测,未带口罩报警,需要输入标注好的数据集。
数据采集(不需要做)-> 数据标注 -> 数据处理 -> 模型训练 -> 模型检测
一、未标注数据集
80张图片,jpg格式,分为戴口罩和未戴口罩。
二、labelimg数据标注
标注标签:未戴口罩 为“0”,戴口罩为“1”
查看当前虚拟环境有哪些?
(base) C:\Users\Administrator>conda env list
# conda environments:
#
base * D:\anaconda
AI_trainer D:\anaconda\envs\AI_trainer
doccano D:\anaconda\envs\doccano
第1步:创建 labelimg虚拟环境:(3.8)
(base) C:\Users\xuna>conda create -n labelimg python=3.8
Retrieving notices: ...working... done
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 23.5.2
latest version: 24.3.0
Please update conda by running
$ conda update -n base -c defaults conda
Or to minimize the number of packages updated during conda update use
conda install conda=24.3.0
## Package Plan ##
environment location: D:\Anaconda\envs\labelimg
added / updated specs:
- python=3.8
The following packages will be downloaded:
package | build
---------------------------|-----------------
openssl-3.0.13 | h2bbff1b_0 7.4 MB
pip-23.3.1 | py38haa95532_0 2.8 MB
python-3.8.19 | h1aa4202_0 18.9 MB
setuptools-68.2.2 | py38haa95532_0 933 KB
wheel-0.41.2 | py38haa95532_0 126 KB
------------------------------------------------------------
Total: 30.2 MB
The following NEW packages will be INSTALLED:
ca-certificates pkgs/main/win-64::ca-certificates-2024.3.11-haa95532_0
libffi pkgs/main/win-64::libffi-3.4.4-hd77b12b_0
openssl pkgs/main/win-64::openssl-3.0.13-h2bbff1b_0
pip pkgs/main/win-64::pip-23.3.1-py38haa95532_0
python pkgs/main/win-64::python-3.8.19-h1aa4202_0
setuptools pkgs/main/win-64::setuptools-68.2.2-py38haa95532_0
sqlite pkgs/main/win-64::sqlite-3.41.2-h2bbff1b_0
vc pkgs/main/win-64::vc-14.2-h21ff451_1
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
wheel pkgs/main/win-64::wheel-0.41.2-py38haa95532_0
Proceed ([y]/n)? y
键盘输入“y”
第2步:切换虚拟环境(不要忘记切换环境,base下的python版本高,会导致labelimg闪退)
(base) C:\Users\xuna>conda activate labelimg
(labelimg) C:\Users\xuna>
第3步:安装labelimg
pip install labelimg -i https://pypi.tuna.tsinghua.edu.cn/simple
(labelimg) C:\Users\xuna>pip install labelimg -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting labelimg
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/c5/fb/9947097363fbbfde3921f7cf7ce9800c89f909d26a506145aec37c75cda7/labelImg-1.8.6.tar.gz (247 kB)
Preparing metadata (setup.py) ... done
Collecting pyqt5 (from labelimg)
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ca/ac/596e8ca16fd0634542d874c0d79219fc527ea7de73a5000092f60ecbf6e9/PyQt5-5.15.10-cp37-abi3-win_amd64.whl (6.8 MB)
Collecting lxml (from labelimg)
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a7/86/4d1d4013dddc1a9844413f6ee89d3384ae90ef7f43dfbf0ed649092f376b/lxml-5.2.1-cp38-cp38-win_amd64.whl (3.8 MB)
---------------------------------------- 3.8/3.8 MB 1.8 MB/s eta 0:00:00
Collecting PyQt5-sip<13,>=12.13 (from pyqt5->labelimg)
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/88/cd/dd21cdb92d053ca71c02c75ab7bd32874b82b33bef61d6d70b5d898e684b/PyQt5_sip-12.13.0-cp38-cp38-win_amd64.whl (78 kB)
---------------------------------------- 78.3/78.3 kB 4.5 MB/s eta 0:00:00
Collecting PyQt5-Qt5>=5.15.2 (from pyqt5->labelimg)
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/37/97/5d3b222b924fa2ed4c2488925155cd0b03fd5d09ee1cfcf7c553c11c9f66/PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
Building wheels for collected packages: labelimg
Building wheel for labelimg (setup.py) ... done
Created wheel for labelimg: filename=labelImg-1.8.6-py2.py3-none-any.whl size=261580 sha256=334ad8c530a87ee8303e4b99cb81c2c51498fafc577d324ba82ac89e339193af
Stored in directory: c:\users\xuna\appdata\local\pip\cache\wheels\6e\a6\57\87059c70d0f25650e60d741c9815f089df3645aa8766a47b6c
Successfully built labelimg
Installing collected packages: PyQt5-Qt5, PyQt5-sip, lxml, pyqt5, labelimg
Successfully installed PyQt5-Qt5-5.15.2 PyQt5-sip-12.13.0 labelimg-1.8.6 lxml-5.2.1 pyqt5-5.15.10
安装成功的标注:(出现了Successfully)
第4步:启动labelimg工具:输入labelimg,点击回车
打开images文件夹
注:images文件夹的路径保证不能存在中文。
错误路径:
正确路径:
选择Open Dir导入数据集文件夹,标注格式改为YOLO.
三、标注后数据集导出和存储
标注好的数据,存放在labels文件夹
保存格式为yolo格式
四、打开标注好的 yolo数据
images:原图像数据集
labels:标注完成的yolo格式的数据
- 打开labelimg,选择 Open Dir打开 images文件夹。
- 选择 Change Save Dir 导入 labels文件夹。
- 选择 "Next Image"即可以看到标注好的图片。
五、生生互评
1、随意乱评,评价人为0分。
2、人脸标注,不包括耳朵、遮挡区域。
3、不合格:标注不贴合、标签错误等,一张只要存在1项错误,即标注错误,扣1分。
4、口罩佩戴不正确视为未佩戴口罩,标签为0。