Yolo v5程序学习3

这篇还是common.py


class Focus(nn.Module):
    """Focuses spatial information into channel space using slicing and convolution for efficient feature extraction."""

    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):
        """Initializes Focus module to concentrate width-height info into channel space with configurable convolution
        parameters.
        """
        super().__init__()
        self.conv = Conv(c1 * 4, c2, k, s, p, g, act=act)
        # self.contract = Contract(gain=2)

    def forward(self, x):
        """Processes input through Focus mechanism, reshaping (b,c,w,h) to (b,4c,w/2,h/2) then applies convolution."""
        return self.conv(torch.cat((x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]), 1))
        # return self.conv(self.contract(x))
x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]

以6*6举例

A = np.arange(36).reshape(6, 6)
A = torch.from_numpy(A)
C1 = A[..., ::2, ::2]
C2 = A[..., 1::2, ::2]
C3 = A[..., ::2, 1::2]
C4 = A[..., 1::2, 1::2]
C5 = torch.cat((C1, C2, C3, C4), 1)

A

C1——[…, ::2, ::2]

显然是从0开始每行每列间隔1位提取

C2——[…, 1::2, ::2]

从1行开始每行每列间隔1位提取

C3——[…, ::2, 1::2]

从1列开始每行每列间隔1位提取

C4——[…, 1::2, 1::2]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值