当前位置:网站首页>widerperson数据集转化为YOLO格式
widerperson数据集转化为YOLO格式
2022-07-06 19:03:00 【-添砖Java】
- 先按照train.txt和val.txt中的内容,将训练集图片和注释全部放在train文件夹下,验证集也是一样。
import os
from pathlib import Path
from PIL import Image
import csv
import shutil
# coding=utf-8
def check_charset(file_path):
import chardet
with open(file_path, "rb") as f:
data = f.read(4)
charset = chardet.detect(data)['encoding']
return charset
def convert(size, box0, box1, box2, box3):
dw = 1. / size[0]
dh = 1. / size[1]
x = (box0 + box2) / 2 * dw
y = (box1 + box3) / 2 * dh
w = (box2 - box0) * dw
h = (box3 - box1) * dh
return (x, y, w, h)
if __name__ == '__main__':
path = 'F:\dataset\WiderPerson/train.txt'
with open(path, 'r') as f:
img_ids = [x for x in f.read().splitlines()]
for img_id in img_ids: # '000040'
img_path = 'F:\dataset\WiderPerson\Images/' + img_id + '.jpg'
with Image.open(img_path) as Img:
img_size = Img.size
ans = ''
label_path = img_path.replace('Images', 'Annotations') + '.txt'
outpath = 'train/' + img_id + '.txt'
with open(label_path, encoding=check_charset(label_path)) as file:
line = file.readline()
count = int(line.split('\n')[0]) # 里面行人个数
line = file.readline()
while line:
cls = int(line.split(' ')[0])
if cls == 1 or cls == 2 or cls == 3:
xmin = float(line.split(' ')[1])
ymin = float(line.split(' ')[2])
xmax = float(line.split(' ')[3])
ymax = float(line.split(' ')[4].split('\n')[0])
print(img_size[0], img_size[1], xmin, ymin, xmax, ymax)
bb = convert(img_size, xmin, ymin, xmax, ymax)
ans = ans + '1' + ' ' + ' '.join(str(a) for a in bb) + '\n'
line = file.readline()
with open(outpath, 'w') as outfile:
outfile.write(ans)
shutil.copy(img_path, 'train/' + img_id + '.jpg')
- 将图片和注释分开,放在各自的文件夹中
import shutil
import os
if __name__ == '__main__':
label_path=r"train/"
imgids = os.listdir(label_path)
print(len(imgids))
n=0
for i in imgids:
n += 1
img_ids_path = label_path.replace('labels', 'images')+ i[0:6] +'.txt'
To_imgpath=r'train\anno/'
print(img_ids_path,To_imgpath,n)
shutil.copy(img_ids_path, To_imgpath)
OK!!!
参考博客:https://blog.csdn.net/qq_44224801/article/details/123480032
参考博客:https://blog.csdn.net/wukong168/article/details/122697243
边栏推荐
- [C # notes] reading and writing of the contents of text files
- 【论文阅读|深读】DNGR:Deep Neural Networks for Learning Graph Representations
- wzoi 1~200
- Use of fiddler
- CDB PDB user rights management
- Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
- Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集
- Data connection mode in low code platform (Part 1)
- postgresql之整体查询大致过程
- leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
猜你喜欢

【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs

go swagger使用

1个月增长900w+播放!总结B站顶流恰饭的2个新趋势
![[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks](/img/06/17acf9958228cce5d80ada3275ad24.png)
[paper reading | deep reading] anrl: attributed network representation learning via deep neural networks
![leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]](/img/0d/e07fe970167368040eb09b05c3682e.png)
leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]

postgresql之integerset

Decryption function calculates "task state and lifecycle management" of asynchronous task capability
![[Mori city] random talk on GIS data (II)](/img/5a/dfa04e3edee5aa6afa56dfe614d59f.jpg)
[Mori city] random talk on GIS data (II)

慧通编程入门课程 - 2A闯关

人脸识别应用解析
随机推荐
go swagger使用
Pgadmin4 of PostgreSQL graphical interface tool
遇到慢SQL该怎么办?(下)
Lumion 11.0软件安装包下载及安装教程
6-6漏洞利用-SSH安全防御
安全交付工程师
Halcon instance to opencvsharp (C openCV) implementation -- bottle mouth defect detection (with source code)
3D laser slam: time synchronization of livox lidar hardware
Web3对法律的需求
[C # notes] use file stream to copy files
Detailed explanation of line segment tree (including tested code implementation)
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
QPushButton-》函数精解
安全巡检的工作
MES管理系统的应用和好处有哪些
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
unity 自定义webgl打包模板
PostgreSQL图形化界面工具之pgAdmin4
Gee upgrade can realize one piece of run tasks
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module