Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
54652fe3
提交
54652fe3
authored
4月 30, 2021
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Objects365 update
上级
801b4698
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
12 行删除
+24
-12
get_objects365.py
data/scripts/get_objects365.py
+21
-9
general.py
utils/general.py
+3
-3
没有找到文件。
data/scripts/get_objects365.py
浏览文件 @
54652fe3
...
@@ -7,22 +7,34 @@
...
@@ -7,22 +7,34 @@
# /images
# /images
# /labels
# /labels
from
pycocotools.coco
import
COCO
from
pycocotools.coco
import
COCO
coco
=
COCO
(
"zhiyuan_objv2_train.json"
)
from
utils.general
import
download
,
Path
cats
=
coco
.
loadCats
(
coco
.
getCatIds
())
nms
=
[
cat
[
"name"
]
for
cat
in
cats
]
# Make Directories
print
(
"COCO categories:
\n
{}
\n
"
.
format
(
" "
.
join
(
nms
)))
dir
=
Path
(
'../datasets/objects365'
)
# dataset directory
for
categoryId
,
cat
in
enumerate
(
nms
):
for
p
in
'images'
,
'labels'
:
(
dir
/
p
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
for
q
in
'train'
,
'val'
:
(
dir
/
p
/
q
)
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# Download
url
=
"https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365
%
E6
%95%
B0
%
E6
%8
D
%
AE
%
E9
%9
B
%86
/train/"
download
(
url
+
'zhiyuan_objv2_train.tar.gz'
,
dir
=
dir
,
threads
=
8
)
# annotations json
download
([
url
+
f
for
f
in
[
f
'patch{i}.tar.gz'
for
i
in
range
(
51
)]],
dir
=
dir
/
'images'
/
'train'
,
threads
=
8
)
# Labels
coco
=
COCO
(
dir
/
'zhiyuan_objv2_train.json'
)
names
=
[
x
[
"name"
]
for
x
in
coco
.
loadCats
(
coco
.
getCatIds
())]
for
categoryId
,
cat
in
enumerate
(
names
):
catIds
=
coco
.
getCatIds
(
catNms
=
[
cat
])
catIds
=
coco
.
getCatIds
(
catNms
=
[
cat
])
imgIds
=
coco
.
getImgIds
(
catIds
=
catIds
)
imgIds
=
coco
.
getImgIds
(
catIds
=
catIds
)
print
(
cat
)
# Create a subfolder in this directory called "labels". This is where the annotations will be saved in YOLO format
for
im
in
coco
.
loadImgs
(
imgIds
):
for
im
in
coco
.
loadImgs
(
imgIds
):
width
,
height
=
im
[
"width"
],
im
[
"height"
]
width
,
height
=
im
[
"width"
],
im
[
"height"
]
path
=
im
[
"file_name"
]
.
split
(
"/"
)[
-
1
]
# image filename
path
=
Path
(
im
[
"file_name"
])
# image filename
try
:
try
:
with
open
(
"labels/train/"
+
path
.
replace
(
".jpg"
,
".txt"
),
"a+"
)
as
file
:
with
open
(
dir
/
'labels'
/
'train'
/
path
.
with_suffix
(
'.txt'
)
.
name
,
'a'
)
as
file
:
annIds
=
coco
.
getAnnIds
(
imgIds
=
im
[
"id"
],
catIds
=
catIds
,
iscrowd
=
None
)
annIds
=
coco
.
getAnnIds
(
imgIds
=
im
[
"id"
],
catIds
=
catIds
,
iscrowd
=
None
)
for
a
in
coco
.
loadAnns
(
annIds
):
for
a
in
coco
.
loadAnns
(
annIds
):
x
,
y
,
w
,
h
=
a
[
'bbox'
]
# bounding box in xywh (xy top-left corner)
x
,
y
,
w
,
h
=
a
[
'bbox'
]
# bounding box in xywh (xy top-left corner)
...
...
utils/general.py
浏览文件 @
54652fe3
...
@@ -183,7 +183,7 @@ def check_dataset(dict):
...
@@ -183,7 +183,7 @@ def check_dataset(dict):
raise
Exception
(
'Dataset not found.'
)
raise
Exception
(
'Dataset not found.'
)
def
download
(
url
,
dir
=
'.'
,
multi_thread
=
False
):
def
download
(
url
,
dir
=
'.'
,
threads
=
1
):
# Multi-threaded file download and unzip function
# Multi-threaded file download and unzip function
def
download_one
(
url
,
dir
):
def
download_one
(
url
,
dir
):
# Download 1 file
# Download 1 file
...
@@ -200,8 +200,8 @@ def download(url, dir='.', multi_thread=False):
...
@@ -200,8 +200,8 @@ def download(url, dir='.', multi_thread=False):
dir
=
Path
(
dir
)
dir
=
Path
(
dir
)
dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# make directory
dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
# make directory
if
multi_thread
:
if
threads
>
1
:
ThreadPool
(
8
)
.
imap
(
lambda
x
:
download_one
(
*
x
),
zip
(
url
,
repeat
(
dir
)))
# 8 threads
ThreadPool
(
threads
)
.
imap
(
lambda
x
:
download_one
(
*
x
),
zip
(
url
,
repeat
(
dir
)))
# multi-threaded
else
:
else
:
for
u
in
tuple
(
url
)
if
isinstance
(
url
,
str
)
else
url
:
for
u
in
tuple
(
url
)
if
isinstance
(
url
,
str
)
else
url
:
download_one
(
u
,
dir
)
download_one
(
u
,
dir
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论