当前位置:网站首页>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
边栏推荐
- Summer Challenge database Xueba notes (Part 2)~
- STM32项目 -- 选题分享(部分)
- leetcode:736. LISP syntax parsing [flowery + stack + status enumaotu + slots]
- CDB PDB 用户权限管理
- unity 自定义webgl打包模板
- 3D laser slam: time synchronization of livox lidar hardware
- MetaForce原力元宇宙佛萨奇2.0智能合约系统开发(源码部署)
- What to do when encountering slow SQL? (next)
- 真实项目,用微信小程序开门编码实现(完结)
- 普通测试年薪15w,测试开发年薪30w+,二者差距在哪?
猜你喜欢
【论文阅读|深读】 GraphSAGE:Inductive Representation Learning on Large Graphs
如何从0到1构建32Core树莓派集群
6-6漏洞利用-SSH安全防御
Collection recommandée!! Quel plug - in de gestion d'état flutter est le plus fort? Regardez le classement des manons de l'île, s'il vous plaît!
postgresql之整體查詢大致過程
Cloud Mail .NET Edition
Web3对法律的需求
FLIR blackfly s usb3 industrial camera: how to use counters and timers
C语言练习题_1
一文读懂Faster RCNN
随机推荐
unity 自定义webgl打包模板
Metaforce force meta universe development and construction - fossage 2.0 system development
MFC Windows 程序设计[147]之ODBC数据库连接(附源码)
The boss is quarantined
unity webgl自适应网页尺寸
你不可不知道的Selenium 8种元素定位方法,简单且实用
Argo workflows source code analysis
6-6 vulnerability exploitation SSH security defense
数论 --- 快速幂、快速幂求逆元
Difference and the difference between array and array structure and linked list
Douban average 9 x. Five God books in the distributed field!
15million employees are easy to manage, and the cloud native database gaussdb makes HR office more efficient
慧通编程入门课程 - 2A闯关
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
3 -- Xintang nuc980 kernel supports JFFS2, JFFS2 file system production, kernel mount JFFS2, uboot network port settings, and uboot supports TFTP
The cities research center of New York University recruits master of science and postdoctoral students
【论文阅读|深读】ANRL: Attributed Network Representation Learning via Deep Neural Networks
运维管理系统有哪些特色
PCL 常用拟合模型及使用方法
Google Earth Engine(GEE)——Landsat 全球土地调查 1975年数据集