Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
8fa37240
提交
8fa37240
authored
6月 16, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
kmean_anchors() update
上级
bdd9fee8
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
8 行删除
+21
-8
utils.py
utils/utils.py
+21
-8
没有找到文件。
utils/utils.py
浏览文件 @
8fa37240
...
@@ -16,6 +16,7 @@ import numpy as np
...
@@ -16,6 +16,7 @@ import numpy as np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torchvision
import
torchvision
import
yaml
from
scipy.signal
import
butter
,
filtfilt
from
scipy.signal
import
butter
,
filtfilt
from
tqdm
import
tqdm
from
tqdm
import
tqdm
...
@@ -686,12 +687,23 @@ def coco_single_class_labels(path='../coco/labels/train2014/', label_class=43):
...
@@ -686,12 +687,23 @@ def coco_single_class_labels(path='../coco/labels/train2014/', label_class=43):
shutil
.
copyfile
(
src
=
img_file
,
dst
=
'new/images/'
+
Path
(
file
)
.
name
.
replace
(
'txt'
,
'jpg'
))
# copy images
shutil
.
copyfile
(
src
=
img_file
,
dst
=
'new/images/'
+
Path
(
file
)
.
name
.
replace
(
'txt'
,
'jpg'
))
# copy images
def
kmean_anchors
(
path
=
'./data/coco128.txt'
,
n
=
9
,
img_size
=
(
640
,
640
),
thr
=
0.20
,
gen
=
1000
):
def
kmean_anchors
(
path
=
'./data/coco128.yaml'
,
n
=
9
,
img_size
=
(
640
,
640
),
thr
=
0.20
,
gen
=
1000
):
# Creates kmeans anchors for use in *.cfg files: from utils.utils import *; _ = kmean_anchors()
""" Creates kmeans-evolved anchors from training dataset
# n: number of anchors
# img_size: (min, max) image size used for multi-scale training (can be same values)
Arguments:
# thr: IoU threshold hyperparameter used for training (0.0 - 1.0)
path: path to dataset *.yaml
# gen: generations to evolve anchors using genetic algorithm
n: number of anchors
img_size: (min, max) image size used for multi-scale training (can be same values)
thr: IoU threshold hyperparameter used for training (0.0 - 1.0)
gen: generations to evolve anchors using genetic algorithm
Return:
k: kmeans evolved anchors
Usage:
from utils.utils import *; _ = kmean_anchors()
"""
from
utils.datasets
import
LoadImagesAndLabels
from
utils.datasets
import
LoadImagesAndLabels
def
print_results
(
k
):
def
print_results
(
k
):
...
@@ -727,7 +739,9 @@ def kmean_anchors(path='./data/coco128.txt', n=9, img_size=(640, 640), thr=0.20,
...
@@ -727,7 +739,9 @@ def kmean_anchors(path='./data/coco128.txt', n=9, img_size=(640, 640), thr=0.20,
# Get label wh
# Get label wh
wh
=
[]
wh
=
[]
dataset
=
LoadImagesAndLabels
(
path
,
augment
=
True
,
rect
=
True
)
with
open
(
path
)
as
f
:
data_dict
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
# model dict
dataset
=
LoadImagesAndLabels
(
data_dict
[
'train'
],
augment
=
True
,
rect
=
True
)
nr
=
1
if
img_size
[
0
]
==
img_size
[
1
]
else
3
# number augmentation repetitions
nr
=
1
if
img_size
[
0
]
==
img_size
[
1
]
else
3
# number augmentation repetitions
for
s
,
l
in
zip
(
dataset
.
shapes
,
dataset
.
labels
):
for
s
,
l
in
zip
(
dataset
.
shapes
,
dataset
.
labels
):
# wh.append(l[:, 3:5] * (s / s.max())) # image normalized to letterbox normalized wh
# wh.append(l[:, 3:5] * (s / s.max())) # image normalized to letterbox normalized wh
...
@@ -771,7 +785,6 @@ def kmean_anchors(path='./data/coco128.txt', n=9, img_size=(640, 640), thr=0.20,
...
@@ -771,7 +785,6 @@ def kmean_anchors(path='./data/coco128.txt', n=9, img_size=(640, 640), thr=0.20,
f
,
k
=
fg
,
kg
.
copy
()
f
,
k
=
fg
,
kg
.
copy
()
print_results
(
k
)
print_results
(
k
)
k
=
print_results
(
k
)
k
=
print_results
(
k
)
return
k
return
k
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论