当前位置:网站首页>Convert widerperson dataset to Yolo format
Convert widerperson dataset to Yolo format
2022-07-07 02:41:00 【-Brick adding Java】
- First according to train.txt and val.txt The content in , Put all the training set pictures and comments on train Under the folder , The same is true of validation sets .
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]) # Number of pedestrians inside
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')
- Separate the picture from the notes , Put them in their respective folders
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!!!
Reference blog :https://blog.csdn.net/qq_44224801/article/details/123480032
Reference blog :https://blog.csdn.net/wukong168/article/details/122697243
边栏推荐
- Unity custom webgl packaging template
- 真实项目,用微信小程序开门编码实现(完结)
- C#/VB.NET 删除Word文檔中的水印
- [leetcode]Search for a Range
- MySQL
- The panel floating with the mouse in unity can adapt to the size of text content
- Hash table and full comments
- MySQL - common functions - string functions
- postgresql之integerset
- MySQL --- 常用函数 - 字符串函数
猜你喜欢
数论 --- 快速幂、快速幂求逆元
C语言练习题_1
Lombok同时使⽤@Data和@Builder 的坑
如何设计好接口测试用例?教你几个小技巧,轻松稿定
Application analysis of face recognition
This week's hot open source project!
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
Overall query process of PostgreSQL
Electrical engineering and automation
6-6 vulnerability exploitation SSH security defense
随机推荐
Cloud Mail .NET Edition
运维管理系统有哪些特色
本周 火火火火 的开源项目!
【Node学习笔记】chokidar模块实现文件监听
MATLB|具有储能的经济调度及机会约束和鲁棒优化
MySQL
The boss is quarantined
安全巡检的工作
【软件测试】最全面试问题和回答,全文背熟不拿下offer算我输
leetcode:5. Longest palindrome substring [DP + holding the tail of timeout]
NuScenes数据集关于Radar数据的统计
wzoi 1~200
How do I dump SoapClient requests for debugging- How to dump SoapClient request for debug?
C#/VB.NET 删除Word文档中的水印
What are the applications and benefits of MES management system
MySQL
一本揭秘字节万台节点ClickHouse背后技术实现的白皮书来了!
postgresql之整體查詢大致過程
fiddler的使用
unity webgl自适应网页尺寸