赞
踩
四步教你完成YOLO v8 安全帽检测!!!
(首先你自己有python 3.7及以上版本)
第一步:pip install ultralytics
C:\Users\Administrator>pip install ultralytics
Collecting ultralytics
Downloading ultralytics-8.0.151-py3-none-any.whl (616 kB)
|████████████████████████████████| 616 kB 12 kB/s
Requirement already satisfied: pillow>=7.1.2 in c:\python\python37\lib\site-packages (from ultralytics) (8.1.1)
Requirement already satisfied: scipy>=1.4.1 in c:\python\python37\lib\site-packages (from ultralytics) (1.6.1)
Collecting opencv-python>=4.6.0
Downloading opencv_python-4.9.0.80-cp37-abi3-win_amd64.whl (38.6 MB)
| | 40 kB 9.5 kB/s eta 1:07:27
第二步:pip freeze
确保安装完成ultralytics库
ultralytics==8.0.145
urllib3==1.26.3
第三步:运行 yolo_train.py
D:\==\safehat>python yolo_train.py
Ultralytics YOLOv8.0.145 Python-3.7.2 torch-1.8.0+cpu CPU (AMD E2-3200 APU with Radeon(tm) HD Graphics)
WARNING Upgrade to torch>=2.0.0 for deterministic training.
engine\trainer: task=detect, mode=train, model=yolov8n.pt, data=safehat.yaml, epochs=100, patience=50, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=None, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, show=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, vid_stride=1, line_width=None, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, boxes=True, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, mosaic=1.0, mixup=0.0, copy_paste=0.0, cfg=None, tracker=botsort.yaml, save_dir=runs\detect\train
=====================
yolo_train.py代码如下:
from ultralytics import YOLO
model = YOLO('yolov8n.pt') #加载模型
model.train(data = 'safehat.yaml',epochs=1)
model.val()
======================
训练完成后,会在train文件下生成weight文件夹,下面有两个文件best.pt和 last.pt
第四步:运行# python yolo_test.py
=====================
yolo_test.py代码如下:
from ultralytics import YOLO
model = YOLO('best.pt')
model.predict( '1.jpg', save = True)
model.predict( '2.jpg', save = True)
model.predict('3.jpg',save = True, classes = [0, 2], line_width = 30)
#model.predict('myself2.jpg',save = True, classes = [0, 2], line_width = 30)
======================
会在runs文件夹下生成结果图片
============================================
2024.2.28更新训练结果
===========================================
==================================================
注意:文件目录下,一定有以下几个文件,特别是红框标准:
不然运行会报错!!!
===================================================
训练好的模型与代码集
如下:
========================================
2024.2.28更新训练集下载链接:
https://www.kaggle.com/datasets/snehilsanyal/construction-site-safety-image-dataset-roboflow
===========================================
参考文章链接如下;
=================2024.2.29 1个积分下载链接=======================
为了方便大家,特提供下载链接(1积分)
https://download.csdn.net/download/paul123456789io/88888856
============================================================
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。