当前位置:网站首页>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
边栏推荐
- Penetrate the whole intranet through socks agent
- Sophon AutoCV:助力AI工业化生产,实现视觉智能感知
- Is it safe to open an account and register stocks for stock speculation? Is there any risk? Is it reliable?
- Memory management chapter of Kobayashi coding
- 项目中遇到的问题 u-parse 组件渲染问题
- Login and connect CDB and PDB
- node_exporter内存使用率不显示
- 彻底理解为什么网络 I/O 会被阻塞?
- 音视频包的pts,dts,duration的由来.
- Gimp 2.10 tutorial "suggestions collection"
猜你喜欢
LeetCode 6109. 知道秘密的人数
Find the first k small element select_ k
The 2022 China Xinchuang Ecological Market Research and model selection evaluation report released that Huayun data was selected as the mainstream manufacturer of Xinchuang IT infrastructure!
吴恩达团队2022机器学习课程,来啦
Record eval() and no in pytoch_ grad()
Sophon autocv: help AI industrial production and realize visual intelligent perception
小林coding的内存管理章节
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
Let more young people from Hong Kong and Macao know about Nansha's characteristic cultural and creative products! "Nansha kylin" officially appeared
About Estimation with Cross-Validation
随机推荐
快速生成ipa包
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
vulnhub之darkhole_2
写作写作写作写作
Is it safe to open an account, register and dig money? Is there any risk? Is it reliable?
Copy the linked list with random pointer in the "Li Kou brush question plan"
从类生成XML架构
热通孔的有效放置如何改善PCB设计中的热管理?
Einstein sum einsum
About Statistical Power(统计功效)
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
多线程(一) 进程与线程
About statistical power
图片数据不够?我做了一个免费的图像增强软件
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
使用Jmeter虚拟化table失败
从XML架构生成类
nacos -分布式事务-Seata** linux安装jdk ,mysql5.7启动nacos配置ideal 调用接口配合 (保姆级细节教程)
金太阳开户安全吗?万一免5开户能办理吗?
【在优麒麟上使用Electron开发桌面应】