Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
78fd0776
Unverified
提交
78fd0776
authored
4月 22, 2021
作者:
Glenn Jocher
提交者:
GitHub
4月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
VisDrone2019-DET Dataset Auto-Download (#2882)
* VisDrone Dataset Auto-Download * add visdrone.yaml * cleanup * add VisDrone2019-DET-test-dev * cleanup VOC
上级
d48a34dc
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
144 行增加
和
78 行删除
+144
-78
argoverse_hd.yaml
data/argoverse_hd.yaml
+1
-1
coco.yaml
data/coco.yaml
+1
-1
coco128.yaml
data/coco128.yaml
+1
-1
get_argoverse_hd.sh
data/scripts/get_argoverse_hd.sh
+1
-1
get_coco.sh
data/scripts/get_coco.sh
+1
-1
get_voc.sh
data/scripts/get_voc.sh
+45
-68
visdrone.yaml
data/visdrone.yaml
+65
-0
voc.yaml
data/voc.yaml
+1
-1
general.py
utils/general.py
+28
-4
没有找到文件。
data/argoverse_hd.yaml
浏览文件 @
78fd0776
# Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/
# Train command: python train.py --data argoverse_hd.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /argoverse
# /yolov5
...
...
data/coco.yaml
浏览文件 @
78fd0776
# COCO 2017 dataset http://cocodataset.org
# Train command: python train.py --data coco.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /coco
# /yolov5
...
...
data/coco128.yaml
浏览文件 @
78fd0776
# COCO 2017 dataset http://cocodataset.org - first 128 training images
# Train command: python train.py --data coco128.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /coco128
# /yolov5
...
...
data/scripts/get_argoverse_hd.sh
浏览文件 @
78fd0776
...
...
@@ -2,7 +2,7 @@
# Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/
# Download command: bash data/scripts/get_argoverse_hd.sh
# Train command: python train.py --data argoverse_hd.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /argoverse
# /yolov5
...
...
data/scripts/get_coco.sh
浏览文件 @
78fd0776
...
...
@@ -2,7 +2,7 @@
# COCO 2017 dataset http://cocodataset.org
# Download command: bash data/scripts/get_coco.sh
# Train command: python train.py --data coco.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /coco
# /yolov5
...
...
data/scripts/get_voc.sh
浏览文件 @
78fd0776
...
...
@@ -2,7 +2,7 @@
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/
# Download command: bash data/scripts/get_voc.sh
# Train command: python train.py --data voc.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /VOC
# /yolov5
...
...
@@ -29,34 +29,27 @@ echo "Completed in" $runtime "seconds"
echo
"Splitting dataset..."
python3 -
"
$@
"
<<
END
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
import xml.etree.ElementTree as ET
from os import getcwd
sets = [('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog",
"horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
def convert_box(size, box):
dw = 1. / (size[0])
dh = 1. / (size[1])
x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2]
return x * dw, y * dh, w * dw, h * dh
def convert(size, box):
dw = 1./(size[0])
dh = 1./(size[1])
x = (box[0] + box[1])/2.0 - 1
y = (box[2] + box[3])/2.0 - 1
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
def convert_annotation(year, image_id):
in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'
%
(year, image_id))
out_file = open('VOCdevkit/VOC%s/labels/%s.txt'
%
(year, image_id), 'w')
tree
=
ET.parse(in_file)
in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'
%
(year, image_id))
out_file = open('VOCdevkit/VOC%s/labels/%s.txt'
%
(year, image_id), 'w')
tree
=
ET.parse(in_file)
root = tree.getroot()
size = root.find('size')
w = int(size.find('width').text)
...
...
@@ -65,74 +58,58 @@ def convert_annotation(year, image_id):
for obj in root.iter('object'):
difficult = obj.find('difficult').text
cls = obj.find('name').text
if cls not in classes or int(difficult)
==
1:
if cls not in classes or int(difficult)
==
1:
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
float(xmlbox.find('ymax').text))
bb = convert_box((w, h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
wd = getcwd()
cwd = getcwd()
for year, image_set in sets:
if not os.path.exists('VOCdevkit/VOC%s/labels/'
%(year)
):
os.makedirs('VOCdevkit/VOC%s/labels/'
%(year)
)
image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'
%
(year, image_set)).read().strip().split()
list_file = open('%s_%s.txt'
%
(year, image_set), 'w')
if not os.path.exists('VOCdevkit/VOC%s/labels/'
% year
):
os.makedirs('VOCdevkit/VOC%s/labels/'
% year
)
image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'
%
(year, image_set)).read().strip().split()
list_file = open('%s_%s.txt'
%
(year, image_set), 'w')
for image_id in image_ids:
list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'
%(
wd, year, image_id))
list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'
% (c
wd, year, image_id))
convert_annotation(year, image_id)
list_file.close()
END
cat
2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt
>
train.txt
cat
2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt
>
train.all.txt
python3 -
"
$@
"
<<
END
mkdir
../VOC ../VOC/images ../VOC/images/train ../VOC/images/val
mkdir
../VOC/labels ../VOC/labels/train ../VOC/labels/val
import shutil
python3 -
"
$@
"
<<
END
import os
os.system('mkdir ../VOC/')
os.system('mkdir ../VOC/images')
os.system('mkdir ../VOC/images/train')
os.system('mkdir ../VOC/images/val')
os.system('mkdir ../VOC/labels')
os.system('mkdir ../VOC/labels/train')
os.system('mkdir ../VOC/labels/val')
import os
print(os.path.exists('../tmp/train.txt'))
f = open('../tmp/train.txt', 'r')
lines = f.readlines()
for line in lines:
line = "/".join(line.split('/')[-5:]).strip()
if (os.path.exists("../" + line)):
os.system("cp ../"+ line + " ../VOC/images/train")
line = line.replace('JPEGImages', 'labels')
line = line.replace('jpg', 'txt')
if (os.path.exists("../" + line)):
os.system("cp ../"+ line + " ../VOC/labels/train")
with open('../tmp/train.txt', 'r') as f:
for line in f.readlines():
line = "/".join(line.split('/')[-5:]).strip()
if os.path.exists("../" + line):
os.system("cp ../" + line + " ../VOC/images/train")
line = line.replace('JPEGImages', 'labels').replace('jpg', 'txt')
if os.path.exists("../" + line):
os.system("cp ../" + line + " ../VOC/labels/train")
print(os.path.exists('../tmp/2007_test.txt'))
f = open('../tmp/2007_test.txt', 'r')
lines = f.readlines()
for line in lines:
line = "/".join(line.split('/')[-5:]).strip()
if (os.path.exists("../" + line)):
os.system("cp ../"+ line + " ../VOC/images/val")
line = line.replace('JPEGImages', 'labels')
line = line.replace('jpg', 'txt')
if (os.path.exists("../" + line)):
os.system("cp ../"+ line + " ../VOC/labels/val")
with open('../tmp/2007_test.txt', 'r') as f:
for line in f.readlines():
line = "/".join(line.split('/')[-5:]).strip()
if os.path.exists("../" + line):
os.system("cp ../" + line + " ../VOC/images/val")
line = line.replace('JPEGImages', 'labels').replace('jpg', 'txt')
if os.path.exists("../" + line):
os.system("cp ../" + line + " ../VOC/labels/val")
END
rm
-rf
../tmp
# remove temporary directory
...
...
data/visdrone.yaml
0 → 100644
浏览文件 @
78fd0776
# VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset
# Train command: python train.py --data visdrone.yaml
# Default dataset location is next to YOLOv5:
# /parent_folder
# /VisDrone
# /yolov5
# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train
:
../VisDrone/VisDrone2019-DET-train/images
# 6471 images
val
:
../VisDrone/VisDrone2019-DET-val/images
# 548 images
test
:
../VisDrone/VisDrone2019-DET-test-dev/images
# 1610 images
# number of classes
nc
:
10
# class names
names
:
[
'
pedestrian'
,
'
people'
,
'
bicycle'
,
'
car'
,
'
van'
,
'
truck'
,
'
tricycle'
,
'
awning-tricycle'
,
'
bus'
,
'
motor'
]
# download command/URL (optional) --------------------------------------------------------------------------------------
download
:
|
import os
from pathlib import Path
from utils.general import download
def visdrone2yolo(dir):
from PIL import Image
from tqdm import tqdm
def convert_box(size, box):
# Convert VisDrone box to YOLO xywh box
dw = 1. / size[0]
dh = 1. / size[1]
return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh
(dir / 'labels').mkdir(parents=True, exist_ok=True) # make labels directory
pbar = tqdm((dir / 'annotations').glob('*.txt'), desc=f'Converting {dir}')
for f in pbar:
img_size = Image.open((dir / 'images' / f.name).with_suffix('.jpg')).size
lines = []
with open(f, 'r') as file: # read annotation.txt
for row in [x.split(',') for x in file.read().strip().splitlines()]:
if row[4] == '0': # VisDrone 'ignored regions' class 0
continue
cls = int(row[5]) - 1
box = convert_box(img_size, tuple(map(int, row[:4])))
lines.append(f"{cls} {' '.join(f'{x:.6f}' for x in box)}\n")
with open(str(f).replace(os.sep + 'annotations' + os.sep, os.sep + 'labels' + os.sep), 'w') as fl:
fl.writelines(lines) # write label.txt
# Download
dir = Path('../VisDrone') # dataset directory
urls = ['https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-train.zip',
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-val.zip',
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-dev.zip'
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-challenge.zip']
download(urls, dir=dir)
# Convert
for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev':
visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels
data/voc.yaml
浏览文件 @
78fd0776
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/
# Train command: python train.py --data voc.yaml
# Default dataset location is next to
/yolo
v5:
# Default dataset location is next to
YOLO
v5:
# /parent_folder
# /VOC
# /yolov5
...
...
utils/general.py
浏览文件 @
78fd0776
...
...
@@ -9,6 +9,8 @@ import random
import
re
import
subprocess
import
time
from
itertools
import
repeat
from
multiprocessing.pool
import
ThreadPool
from
pathlib
import
Path
import
cv2
...
...
@@ -161,18 +163,40 @@ def check_dataset(dict):
if
not
all
(
x
.
exists
()
for
x
in
val
):
print
(
'
\n
WARNING: Dataset not found, nonexistent paths:
%
s'
%
[
str
(
x
)
for
x
in
val
if
not
x
.
exists
()])
if
s
and
len
(
s
):
# download script
print
(
'Downloading
%
s ...'
%
s
)
if
s
.
startswith
(
'http'
)
and
s
.
endswith
(
'.zip'
):
# URL
f
=
Path
(
s
)
.
name
# filename
print
(
f
'Downloading {s} ...'
)
torch
.
hub
.
download_url_to_file
(
s
,
f
)
r
=
os
.
system
(
'unzip -q
%
s -d ../ && rm
%
s'
%
(
f
,
f
))
# unzip
else
:
# bash script
r
=
os
.
system
(
f
'unzip -q {f} -d ../ && rm {f}'
)
# unzip
elif
s
.
startswith
(
'bash '
):
# bash script
print
(
f
'Running {s} ...'
)
r
=
os
.
system
(
s
)
print
(
'Dataset autodownload
%
s
\n
'
%
(
'success'
if
r
==
0
else
'failure'
))
# analyze return value
else
:
# python script
r
=
exec
(
s
)
# return None
print
(
'Dataset autodownload
%
s
\n
'
%
(
'success'
if
r
in
(
0
,
None
)
else
'failure'
))
# print result
else
:
raise
Exception
(
'Dataset not found.'
)
def
download
(
url
,
dir
=
'.'
,
multi_thread
=
False
):
# Multi-threaded file download function
def
download_one
(
url
,
dir
):
# Download 1 file
f
=
dir
/
Path
(
url
)
.
name
# filename
print
(
f
'Downloading {url} to {f}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
f
,
progress
=
True
)
# download
if
f
.
suffix
==
'.zip'
:
os
.
system
(
f
'unzip -qo {f} -d {dir} && rm {f}'
)
# unzip -quiet -overwrite
dir
=
Path
(
dir
)
dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# make directory
if
multi_thread
:
ThreadPool
(
8
)
.
imap
(
lambda
x
:
download_one
(
*
x
),
zip
(
url
,
repeat
(
dir
)))
# 8 threads
else
:
for
u
in
tuple
(
url
)
if
isinstance
(
url
,
str
)
else
url
:
download_one
(
u
,
dir
)
def
make_divisible
(
x
,
divisor
):
# Returns x evenly divisible by divisor
return
math
.
ceil
(
x
/
divisor
)
*
divisor
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论