Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Calabaza amarga
yolo3-pytorch
提交
f1ea22d7
Y
yolo3-pytorch
项目概览
Calabaza amarga
/
yolo3-pytorch
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yolo3-pytorch
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f1ea22d7
编写于
6月 05, 2020
作者:
B
Bubbliiiing
提交者:
GitHub
6月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update yolo_training.py
上级
a537cb43
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
10 deletion
+38
-10
nets/yolo_training.py
nets/yolo_training.py
+38
-10
未找到文件。
nets/yolo_training.py
浏览文件 @
f1ea22d7
...
...
@@ -9,6 +9,33 @@ from matplotlib.colors import rgb_to_hsv, hsv_to_rgb
from
PIL
import
Image
from
utils.utils
import
bbox_iou
def
jaccard
(
_box_a
,
_box_b
):
b1_x1
,
b1_x2
=
_box_a
[:,
0
]
-
_box_a
[:,
2
]
/
2
,
_box_a
[:,
0
]
+
_box_a
[:,
2
]
/
2
b1_y1
,
b1_y2
=
_box_a
[:,
1
]
-
_box_a
[:,
3
]
/
2
,
_box_a
[:,
1
]
+
_box_a
[:,
3
]
/
2
b2_x1
,
b2_x2
=
_box_b
[:,
0
]
-
_box_b
[:,
2
]
/
2
,
_box_b
[:,
0
]
+
_box_b
[:,
2
]
/
2
b2_y1
,
b2_y2
=
_box_b
[:,
1
]
-
_box_b
[:,
3
]
/
2
,
_box_b
[:,
1
]
+
_box_b
[:,
3
]
/
2
box_a
=
torch
.
zeros_like
(
_box_a
)
box_b
=
torch
.
zeros_like
(
_box_b
)
box_a
[:,
0
],
box_a
[:,
1
],
box_a
[:,
2
],
box_a
[:,
3
]
=
b1_x1
,
b1_y1
,
b1_x2
,
b1_y2
box_b
[:,
0
],
box_b
[:,
1
],
box_b
[:,
2
],
box_b
[:,
3
]
=
b2_x1
,
b2_y1
,
b2_x2
,
b2_y2
A
=
box_a
.
size
(
0
)
B
=
box_b
.
size
(
0
)
max_xy
=
torch
.
min
(
box_a
[:,
2
:].
unsqueeze
(
1
).
expand
(
A
,
B
,
2
),
box_b
[:,
2
:].
unsqueeze
(
0
).
expand
(
A
,
B
,
2
))
min_xy
=
torch
.
max
(
box_a
[:,
:
2
].
unsqueeze
(
1
).
expand
(
A
,
B
,
2
),
box_b
[:,
:
2
].
unsqueeze
(
0
).
expand
(
A
,
B
,
2
))
inter
=
torch
.
clamp
((
max_xy
-
min_xy
),
min
=
0
)
inter
=
inter
[:,
:,
0
]
*
inter
[:,
:,
1
]
# 计算先验框和真实框各自的面积
area_a
=
((
box_a
[:,
2
]
-
box_a
[:,
0
])
*
(
box_a
[:,
3
]
-
box_a
[:,
1
])).
unsqueeze
(
1
).
expand_as
(
inter
)
# [A,B]
area_b
=
((
box_b
[:,
2
]
-
box_b
[:,
0
])
*
(
box_b
[:,
3
]
-
box_b
[:,
1
])).
unsqueeze
(
0
).
expand_as
(
inter
)
# [A,B]
# 求IOU
union
=
area_a
+
area_b
-
inter
return
inter
/
union
# [A,B]
def
clip_by_tensor
(
t
,
t_min
,
t_max
):
t
=
t
.
float
()
...
...
@@ -219,16 +246,17 @@ class YOLOLoss(nn.Module):
pred_boxes_for_ignore
=
pred_boxes
[
i
]
pred_boxes_for_ignore
=
pred_boxes_for_ignore
.
view
(
-
1
,
4
)
for
t
in
range
(
target
[
i
].
shape
[
0
]):
gx
=
target
[
i
][
t
,
0
]
*
in_w
gy
=
target
[
i
][
t
,
1
]
*
in_h
gw
=
target
[
i
][
t
,
2
]
*
in_w
gh
=
target
[
i
][
t
,
3
]
*
in_h
gt_box
=
torch
.
FloatTensor
(
np
.
array
([
gx
,
gy
,
gw
,
gh
])).
unsqueeze
(
0
).
type
(
FloatTensor
)
anch_ious
=
bbox_iou
(
gt_box
,
pred_boxes_for_ignore
,
x1y1x2y2
=
False
)
anch_ious
=
anch_ious
.
view
(
pred_boxes
[
i
].
size
()[:
3
])
noobj_mask
[
i
][
anch_ious
>
self
.
ignore_threshold
]
=
0
if
len
(
target
[
i
])
>
0
:
gx
=
target
[
i
][:,
0
:
1
]
*
in_w
gy
=
target
[
i
][:,
1
:
2
]
*
in_h
gw
=
target
[
i
][:,
2
:
3
]
*
in_w
gh
=
target
[
i
][:,
3
:
4
]
*
in_h
gt_box
=
torch
.
FloatTensor
(
np
.
concatenate
([
gx
,
gy
,
gw
,
gh
],
-
1
)).
type
(
FloatTensor
)
anch_ious
=
jaccard
(
gt_box
,
pred_boxes_for_ignore
)
for
t
in
range
(
target
[
i
].
shape
[
0
]):
anch_iou
=
anch_ious
[
t
].
view
(
pred_boxes
[
i
].
size
()[:
3
])
noobj_mask
[
i
][
anch_iou
>
self
.
ignore_threshold
]
=
0
# print(torch.max(anch_ious))
return
noobj_mask
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录