Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
2e5c67e5
Unverified
提交
2e5c67e5
authored
2月 17, 2022
作者:
Glenn Jocher
提交者:
GitHub
2月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Robust `scipy.cluster.vq.kmeans` too few points (#6668)
* Handle `scipy.cluster.vq.kmeans` too few points Resolves #6664 * Update autoanchor.py * Cleanup
上级
7b80545e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
7 行增加
和
6 行删除
+7
-6
autoanchor.py
utils/autoanchor.py
+7
-6
没有找到文件。
utils/autoanchor.py
浏览文件 @
2e5c67e5
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
"""
"""
Auto
-a
nchor utils
Auto
A
nchor utils
"""
"""
import
random
import
random
...
@@ -81,6 +81,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
...
@@ -81,6 +81,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
"""
"""
from
scipy.cluster.vq
import
kmeans
from
scipy.cluster.vq
import
kmeans
npr
=
np
.
random
thr
=
1
/
thr
thr
=
1
/
thr
def
metric
(
k
,
wh
):
# compute metrics
def
metric
(
k
,
wh
):
# compute metrics
...
@@ -121,14 +122,15 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
...
@@ -121,14 +122,15 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
if
i
:
if
i
:
LOGGER
.
info
(
f
'{PREFIX}WARNING: Extremely small objects found. {i} of {len(wh0)} labels are < 3 pixels in size.'
)
LOGGER
.
info
(
f
'{PREFIX}WARNING: Extremely small objects found. {i} of {len(wh0)} labels are < 3 pixels in size.'
)
wh
=
wh0
[(
wh0
>=
2.0
)
.
any
(
1
)]
# filter > 2 pixels
wh
=
wh0
[(
wh0
>=
2.0
)
.
any
(
1
)]
# filter > 2 pixels
# wh = wh * (np
.random
.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1
# wh = wh * (np
r
.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1
# Kmeans calculation
# Kmeans calculation
LOGGER
.
info
(
f
'{PREFIX}Running kmeans for {n} anchors on {len(wh)} points...'
)
LOGGER
.
info
(
f
'{PREFIX}Running kmeans for {n} anchors on {len(wh)} points...'
)
s
=
wh
.
std
(
0
)
# sigmas for whitening
s
=
wh
.
std
(
0
)
# sigmas for whitening
k
,
dist
=
kmeans
(
wh
/
s
,
n
,
iter
=
30
)
# points, mean distance
k
=
kmeans
(
wh
/
s
,
n
,
iter
=
30
)[
0
]
*
s
# points
assert
len
(
k
)
==
n
,
f
'{PREFIX}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}'
if
len
(
k
)
!=
n
:
# kmeans may return fewer points than requested if wh is insufficient or too similar
k
*=
s
LOGGER
.
warning
(
f
'{PREFIX}WARNING: scipy.cluster.vq.kmeans returned only {len(k)} of {n} requested points'
)
k
=
np
.
sort
(
npr
.
rand
(
n
*
2
))
.
reshape
(
n
,
2
)
*
img_size
# random init
wh
=
torch
.
tensor
(
wh
,
dtype
=
torch
.
float32
)
# filtered
wh
=
torch
.
tensor
(
wh
,
dtype
=
torch
.
float32
)
# filtered
wh0
=
torch
.
tensor
(
wh0
,
dtype
=
torch
.
float32
)
# unfiltered
wh0
=
torch
.
tensor
(
wh0
,
dtype
=
torch
.
float32
)
# unfiltered
k
=
print_results
(
k
,
verbose
=
False
)
k
=
print_results
(
k
,
verbose
=
False
)
...
@@ -146,7 +148,6 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
...
@@ -146,7 +148,6 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
# fig.savefig('wh.png', dpi=200)
# fig.savefig('wh.png', dpi=200)
# Evolve
# Evolve
npr
=
np
.
random
f
,
sh
,
mp
,
s
=
anchor_fitness
(
k
),
k
.
shape
,
0.9
,
0.1
# fitness, generations, mutation prob, sigma
f
,
sh
,
mp
,
s
=
anchor_fitness
(
k
),
k
.
shape
,
0.9
,
0.1
# fitness, generations, mutation prob, sigma
pbar
=
tqdm
(
range
(
gen
),
desc
=
f
'{PREFIX}Evolving anchors with Genetic Algorithm:'
)
# progress bar
pbar
=
tqdm
(
range
(
gen
),
desc
=
f
'{PREFIX}Evolving anchors with Genetic Algorithm:'
)
# progress bar
for
_
in
pbar
:
for
_
in
pbar
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论