当前位置:网站首页>Pytorch yolov5 training custom data
Pytorch yolov5 training custom data
2022-07-05 18:23:00 【mtl1994】
pytorch yolov5 Training custom data
List of articles
Preface
Environmental Science
python: 3.9.7
torch: 1.10.2
labelimg: 1.8.6
#yolov5 https://github.com/ultralytics/yolov5
#pytorch https://pytorch.org/
#labelimg https://github.com/tzutalin/labelImg
paddleocr There are three models det testing cls Direction rec distinguish
One 、 Create an environment
install miniconda
https://blog.csdn.net/mtl1994/article/details/114968140
Create an environment
#linux It needs to be done first source conda create -n pytorch_yolov5 python=3.9.7 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
Enter the environment after installation
conda activate pytorch_yolov5
Two 、 Installation environment
pytorch
# Select corresponding cuda/cpu edition pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
yolov5
# Download source code git clone https://github.com/ultralytics/yolov5 # clone cd yolov5 # Installation dependency python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
Test it
import torch # Model model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # or yolov5n - yolov5x6, custom # Images img = 'https://ultralytics.com/images/zidane.jpg' # or file, Path, PIL, OpenCV, numpy, list # Inference results = model(img) # Results results.print() # or .show(), .save(), .crop(), .pandas(), etc.
Choose a model
https://github.com/ultralytics/yolov5/releases
Model parameters
The model I use is
yolov5x
3、 ... and 、 Mark the picture
I use labelimg
# install
pip install labelimg
# open
labelimg
After marking, there will be two directories 、 A save picture 、 A deposit txt
Four 、 Training
1. Segmentation data
def make_datasets(txt_path, img_path, out="./out", split_rate=0.05):
txt_dir = Path(txt_path)
img_dir = Path(img_path)
out_dir = Path(out)
dataset = []
train_label = out_dir / "labels/train2007/"
train_image = out_dir / "images/train2007/"
test_label = out_dir / "labels/test2007/"
test_image = out_dir / "images/test2007/"
train_label.mkdir(parents=True, exist_ok=True)
train_image.mkdir(parents=True, exist_ok=True)
test_label.mkdir(parents=True, exist_ok=True)
test_image.mkdir(parents=True, exist_ok=True)
"""
Filter empty txt
"""
for item in txt_dir.rglob("*.txt"):
if item.read_text() != "":
dataset.append(item)
"""
Split training set , Verification set
"""
tv = random.sample(dataset, int(len(dataset) * split_rate))
"""
Assembly data
"""
print(len(dataset))
for item in dataset:
for jpg in img_dir.rglob(item.stem + ".jpg"):
if item in tv:
print(jpg, test_image / jpg.name)
# jpg.replace(test_image / jpg.name)
shutil.copy(str(jpg), test_image / jpg.name)
shutil.copy(str(item), test_label / item.name)
# item.replace(test_label / item.name)
else:
print(jpg, train_image / jpg.name)
# jpg.replace(train_image / jpg.name)
# item.replace(train_label / item.name)
shutil.copy(str(jpg), train_image / jpg.name)
shutil.copy(str(item), train_label / item.name)
After execution , Directory structure
2. Modify the training model yml
3. Start training
nohup python train.py --img 640 --batch 32 --epochs 600 --data voc.yaml --weights yolov5s.pt --device 0,1,2,3 &
The training results are saved in runs/train/
In the incremental running directory , for example runs/train/exp2
,runs/train/exp3
5、 ... and 、 Trained models , With new data, we need to continue training
1. Use transfer learning
Designated during training weights by The output of the last training
6、 ... and 、 Common commands
1. Training
nohup python train.py --img 640 --batch 32 --epochs 600 --data wp_voc.yaml --weights runs/train/exp27/weights/best.pt --device 0,1,2,3 &
2. distinguish
python detect.py --weights runs/train/exp6/weights/best.pt --source ../datasets/infer/2022-2-24/
3. export onnx
python export.py --weights yolov5s.pt --img 640 --batch 1 # export at 640x640 with batch size 1
summary
边栏推荐
- Nanjing University: Discussion on the training program of digital talents in the new era
- 登录连接 CDB 和 PDB
- [paddlepaddle] paddedetection face recognition custom data set
- Trust counts the number of occurrences of words in the file
- 如何获取飞机穿过雷达两端的坐标
- 通过SOCKS代理渗透整个内网
- Clickhouse (03) how to install and deploy Clickhouse
- 小白入门NAS—快速搭建私有云教程系列(一)[通俗易懂]
- Copy the linked list with random pointer in the "Li Kou brush question plan"
- ConvMAE(2022-05)
猜你喜欢
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]
buuctf-pwn write-ups (9)
pytorch yolov5 训练自定义数据
U-Net: Convolutional Networks for Biomedical Images Segmentation
nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
《2022中国信创生态市场研究及选型评估报告》发布 华云数据入选信创IT基础设施主流厂商!
图片数据不够?我做了一个免费的图像增强软件
Failed to virtualize table with JMeter
《力扣刷题计划》复制带随机指针的链表
随机推荐
Star Ring Technology launched transwarp Navier, a data element circulation platform, to help enterprises achieve secure data circulation and collaboration under privacy protection
JVM third talk -- JVM performance tuning practice and high-frequency interview question record
LeetCode 6109. 知道秘密的人数
ConvMAE(2022-05)
模拟百囚徒问题
图片数据不够?我做了一个免费的图像增强软件
Record a case of using WinDbg to analyze memory "leakage"
使用JMeter录制脚本并调试
Numerical calculation method chapter8 Numerical solutions of ordinary differential equations
个人对卷积神经网络的理解
记录Pytorch中的eval()和no_grad()
Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
Maximum artificial island [how to make all nodes of a connected component record the total number of nodes? + number the connected component]
Einstein sum einsum
[utiliser Electron pour développer le Bureau sur youkirin devrait]
LeetCode 6109. Number of people who know the secret
分享:中兴 远航 30 pro root 解锁BL magisk ZTE 7532N 8040N 9041N 刷机 刷面具原厂刷机包 root方法下载
使用Jmeter虚拟化table失败
The 11th China cloud computing standards and Applications Conference | cloud computing national standards and white paper series release, and Huayun data fully participated in the preparation
English sentence pattern reference