前言
- 由于本人水平有限,難免出現(xiàn)錯漏,敬請批評改正。
- 更多精彩內(nèi)容,可點擊進(jìn)入YOLO系列專欄或我的個人主頁查看
- YOLOv5:添加SE、CBAM、CoordAtt、ECA注意力機(jī)制
- YOLOv5:yolov5s.yaml配置文件解讀、增加小目標(biāo)檢測層
- YOLOv5:IoU、GIoU、DIoU、CIoU、EIoU
- YOLOv7訓(xùn)練自己的數(shù)據(jù)集(口罩檢測)
- YOLOv8訓(xùn)練自己的數(shù)據(jù)集(足球檢測)
- 玩轉(zhuǎn)Jetson Nano(五):TensorRT加速YOLOv5目標(biāo)檢測
前提條件
- 熟悉Python
相關(guān)介紹
- Python是一種跨平臺的計算機(jī)程序設(shè)計語言。是一個高層次的結(jié)合了解釋性、編譯性、互動性和面向?qū)ο蟮哪_本語言。最初被設(shè)計用于編寫自動化腳本(shell),隨著版本的不斷更新和語言新功能的添加,越多被用于獨立的、大型項目的開發(fā)。
- PyTorch 是一個深度學(xué)習(xí)框架,封裝好了很多網(wǎng)絡(luò)和深度學(xué)習(xí)相關(guān)的工具方便我們調(diào)用,而不用我們一個個去單獨寫了。它分為 CPU 和 GPU 版本,其他框架還有 TensorFlow、Caffe 等。PyTorch 是由 Facebook 人工智能研究院(FAIR)基于 Torch 推出的,它是一個基于 Python 的可續(xù)計算包,提供兩個高級功能:1、具有強(qiáng)大的 GPU 加速的張量計算(如 NumPy);2、構(gòu)建深度神經(jīng)網(wǎng)絡(luò)時的自動微分機(jī)制。
- YOLOv5是一種單階段目標(biāo)檢測算法,該算法在YOLOv4的基礎(chǔ)上添加了一些新的改進(jìn)思路,使其速度與精度都得到了極大的性能提升。它是一個在COCO數(shù)據(jù)集上預(yù)訓(xùn)練的物體檢測架構(gòu)和模型系列,代表了Ultralytics對未來視覺AI方法的開源研究,其中包含了經(jīng)過數(shù)千小時的研究和開發(fā)而形成的經(jīng)驗教訓(xùn)和最佳實踐。
- 實例分割是指將圖片中屬于物體類別的像素識別出來并作分類。1 實例分割是視覺經(jīng)典四個任務(wù)中相對最難的一個,它既具備語義分割(Semantic Segmentation)的特點,需要做到像素層面上的分類,也具備目標(biāo)檢測(Object Detection)的一部分特點,即需要定位出不同實例,即使它們是同一種類。
- 本文數(shù)據(jù)集免費獲取鏈接:https://download.csdn.net/download/FriendshipTang/88118028
- 同時,也可以在本文開頭獲取,如下圖所示。
![]()
使用YOLOv5-7.0版本訓(xùn)練自己的實例分割模型
YOLOv5項目官方源地址
https://github.com/ultralytics/yolov5.git
下載yolov5-7.0版源碼
解壓
目錄結(jié)構(gòu)
準(zhǔn)備實例分割數(shù)據(jù)集
在./data目錄下,新建myseg.yaml配置文件
內(nèi)容如下:
# YOLOv5 ?? by Ultralytics, AGPL-3.0 license
# COCO128-seg dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Example usage: python train.py --data coco128.yaml
# parent
# ├── yolov5
# └── datasets
# └── coco128-seg ← downloads here (7 MB)
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: ../datasets/myseg # dataset root dir
train: ../myseg/trainset/images # train images (relative to 'path') 128 images
val: ../myseg/valset/images # val images (relative to 'path') 128 images
test: ../myseg/testset/images # test images (optional)
# Classes
names:
0: background
1: car
2: traffic_sign
3: lane_lines
4: person
5: motorcyclist
6: cyclist
訓(xùn)練分割模型
python segment/train.py --data data/myseg.yaml --weights yolov5s-seg.pt --img 640 --batch-size 16
注:如果報顯存溢出錯誤,可將batch-size調(diào)小。
解決‘ImportError: Failed to initialize: Bad git executable.’
Traceback (most recent call last):
File "segment/train.py", line 66, in <module>
GIT_INFO = check_git_info()
File "D:\anaconda3\envs\test2\lib\contextlib.py", line 75, in inner
return func(*args, **kwds)
File "E:\mytest\yolov5-master\utils\general.py", line 360, in check_git_info
import git
File "D:\anaconda3\envs\test2\lib\site-packages\git\__init__.py", line 91, in <module>
raise ImportError("Failed to initialize: {0}".format(exc)) from exc
ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:
- be included in your $PATH
- be set via $GIT_PYTHON_GIT_EXECUTABLE
- explicitly set via git.refresh()
All git commands will error until this is rectified.
This initial warning can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
- quiet|q|silence|s|none|n|0: for no warning or exception
- warn|w|warning|1: for a printed warning
- error|e|raise|r|2: for a raised exception
Example:
export GIT_PYTHON_REFRESH=quiet
解決方法
在train.py代碼中,import os 后面添加了一行
os.environ["GIT_PYTHON_REFRESH"] = "quiet"
驗證分割模型
python segment/val.py --weights runs\train-seg\exp\weights\best.pt --data data/myseg.yaml --img 640
BoxPR_curve
MaskPR_curve
測試分割模型
python segment/predict.py --weights runs/train-seg/exp/weights/best.pt --source test.jpg --img 640
文章來源:http://www.zghlxwxcb.cn/news/detail-615539.html
參考
[1] https://github.com/ultralytics/yolov5文章來源地址http://www.zghlxwxcb.cn/news/detail-615539.html
- 由于本人水平有限,難免出現(xiàn)錯漏,敬請批評改正。
- 更多精彩內(nèi)容,可點擊進(jìn)入YOLO系列專欄或我的個人主頁查看
- YOLOv5:添加SE、CBAM、CoordAtt、ECA注意力機(jī)制
- YOLOv5:yolov5s.yaml配置文件解讀、增加小目標(biāo)檢測層
- YOLOv5:IoU、GIoU、DIoU、CIoU、EIoU
- YOLOv7訓(xùn)練自己的數(shù)據(jù)集(口罩檢測)
- YOLOv8訓(xùn)練自己的數(shù)據(jù)集(足球檢測)
- 玩轉(zhuǎn)Jetson Nano(五):TensorRT加速YOLOv5目標(biāo)檢測
到了這里,關(guān)于YOLOv5:使用7.0版本訓(xùn)練自己的實例分割模型(車輛、行人、路標(biāo)、車道線等實例分割)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!