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。
参考链接:
yolov5中的Focus模块的理解_阿菜的博客-CSDN博客blog.csdn.net/qq_39056987/article/details/112712817