当前位置:网站首页>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
边栏推荐
- 进程管理基础
- pgpool-II和pgpoolAdmin的使用
- ODBC database connection of MFC windows programming [147] (with source code)
- Linear list --- circular linked list
- Detailed explanation of line segment tree (including tested code implementation)
- The boss is quarantined
- Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
- Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
- Why am I warned that the 'CMAKE_ TOOLCHAIN_ FILE' variable is not used by the project?
- MATLB|具有储能的经济调度及机会约束和鲁棒优化
猜你喜欢
Ali yunyili: how does yunyuansheng solve the problem of reducing costs and improving efficiency?
C语言练习题_1
C#/VB.NET 删除Word文档中的水印
Use of fiddler
Pioneer of Web3: virtual human
unity 自定义webgl打包模板
牛客编程题--必刷101之双指针篇
Processus général de requête pour PostgreSQL
AWS学习笔记(一)
Station B's June ranking list - feigua data up main growth ranking list (BiliBili platform) is released!
随机推荐
Chang'an chain learning notes - certificate model of certificate research
用全连接+softmax对图片的feature进行分类
unity 自定义webgl打包模板
ODBC database connection of MFC windows programming [147] (with source code)
牛客编程题--必刷101之双指针篇
普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
STM32 project -- Topic sharing (part)
所谓的消费互联网仅仅只是做行业信息的撮合和对接,并不改变产业本身
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
本周 火火火火 的开源项目!
Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
C#/VB.NET 删除Word文檔中的水印
3--新唐nuc980 kernel支持jffs2, Jffs2文件系统制作, 内核挂载jffs2, uboot网口设置,uboot支持tftp
写作系列之contribution
【森城市】GIS数据漫谈(二)
Application analysis of face recognition
MES管理系统的应用和好处有哪些
Go swagger use
Work of safety inspection
Draco - glTF模型压缩利器