Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
13530402
Unverified
提交
13530402
authored
8月 28, 2022
作者:
Glenn Jocher
提交者:
GitHub
8月 28, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix AutoAnchor MPS bug (#9188)
Resolves
https://github.com/ultralytics/yolov5/issues/8862
Signed-off-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
Signed-off-by:
Glenn Jocher
<
glenn.jocher@ultralytics.com
>
上级
53711bac
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
5 行增加
和
6 行删除
+5
-6
autoanchor.py
utils/autoanchor.py
+5
-6
没有找到文件。
utils/autoanchor.py
浏览文件 @
13530402
...
@@ -10,6 +10,7 @@ import torch
...
@@ -10,6 +10,7 @@ import torch
import
yaml
import
yaml
from
tqdm
import
tqdm
from
tqdm
import
tqdm
from
utils
import
TryExcept
from
utils.general
import
LOGGER
,
colorstr
from
utils.general
import
LOGGER
,
colorstr
PREFIX
=
colorstr
(
'AutoAnchor: '
)
PREFIX
=
colorstr
(
'AutoAnchor: '
)
...
@@ -25,6 +26,7 @@ def check_anchor_order(m):
...
@@ -25,6 +26,7 @@ def check_anchor_order(m):
m
.
anchors
[:]
=
m
.
anchors
.
flip
(
0
)
m
.
anchors
[:]
=
m
.
anchors
.
flip
(
0
)
@TryExcept
(
f
'{PREFIX}ERROR:'
)
def
check_anchors
(
dataset
,
model
,
thr
=
4.0
,
imgsz
=
640
):
def
check_anchors
(
dataset
,
model
,
thr
=
4.0
,
imgsz
=
640
):
# Check anchor fit to data, recompute if necessary
# Check anchor fit to data, recompute if necessary
m
=
model
.
module
.
model
[
-
1
]
if
hasattr
(
model
,
'module'
)
else
model
.
model
[
-
1
]
# Detect()
m
=
model
.
module
.
model
[
-
1
]
if
hasattr
(
model
,
'module'
)
else
model
.
model
[
-
1
]
# Detect()
...
@@ -49,10 +51,7 @@ def check_anchors(dataset, model, thr=4.0, imgsz=640):
...
@@ -49,10 +51,7 @@ def check_anchors(dataset, model, thr=4.0, imgsz=640):
else
:
else
:
LOGGER
.
info
(
f
'{s}Anchors are a poor fit to dataset ⚠️, attempting to improve...'
)
LOGGER
.
info
(
f
'{s}Anchors are a poor fit to dataset ⚠️, attempting to improve...'
)
na
=
m
.
anchors
.
numel
()
//
2
# number of anchors
na
=
m
.
anchors
.
numel
()
//
2
# number of anchors
try
:
anchors
=
kmean_anchors
(
dataset
,
n
=
na
,
img_size
=
imgsz
,
thr
=
thr
,
gen
=
1000
,
verbose
=
False
)
anchors
=
kmean_anchors
(
dataset
,
n
=
na
,
img_size
=
imgsz
,
thr
=
thr
,
gen
=
1000
,
verbose
=
False
)
except
Exception
as
e
:
LOGGER
.
info
(
f
'{PREFIX}ERROR: {e}'
)
new_bpr
=
metric
(
anchors
)[
0
]
new_bpr
=
metric
(
anchors
)[
0
]
if
new_bpr
>
bpr
:
# replace anchors
if
new_bpr
>
bpr
:
# replace anchors
anchors
=
torch
.
tensor
(
anchors
,
device
=
m
.
anchors
.
device
)
.
type_as
(
m
.
anchors
)
anchors
=
torch
.
tensor
(
anchors
,
device
=
m
.
anchors
.
device
)
.
type_as
(
m
.
anchors
)
...
@@ -124,7 +123,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
...
@@ -124,7 +123,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
i
=
(
wh0
<
3.0
)
.
any
(
1
)
.
sum
()
i
=
(
wh0
<
3.0
)
.
any
(
1
)
.
sum
()
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
)]
.
astype
(
np
.
float32
)
# filter > 2 pixels
# wh = wh * (npr.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1
# wh = wh * (npr.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1
# Kmeans init
# Kmeans init
...
@@ -167,4 +166,4 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
...
@@ -167,4 +166,4 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
if
verbose
:
if
verbose
:
print_results
(
k
,
verbose
)
print_results
(
k
,
verbose
)
return
print_results
(
k
)
return
print_results
(
k
)
.
astype
(
np
.
float32
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论