4、Focus模組-in YOLO
作者:由 LayH 發表于 農業時間:2021-08-05
YOLO裡面輸入的影象會先進入Focus模組,該模組主要是實現
沒有資訊丟失的下采樣
。
很形象的一張圖:
class
Focus
(
nn
。
Module
):
“”“Focus width and height information into channel space。”“”
def
__init__
(
self
,
in_channels
,
out_channels
,
ksize
=
1
,
stride
=
1
,
act
=
“silu”
):
super
()
。
__init__
()
self
。
conv
=
BaseConv
(
in_channels
*
4
,
out_channels
,
ksize
,
stride
,
act
=
act
)
def
forward
(
self
,
x
):
# shape of x (b,c,w,h) -> y(b,4c,w/2,h/2)
patch_top_left
=
x
[
。。。
,
::
2
,
::
2
]
patch_top_right
=
x
[
。。。
,
::
2
,
1
::
2
]
patch_bot_left
=
x
[
。。。
,
1
::
2
,
::
2
]
patch_bot_right
=
x
[
。。。
,
1
::
2
,
1
::
2
]
x
=
torch
。
cat
(
(
patch_top_left
,
patch_bot_left
,
patch_top_right
,
patch_bot_right
,
),
dim
=
1
,
)
return
self
。
conv
(
x
)
上面的實現是來自YOLOX。
參考連結: