every blog every motto: There’s only one corner of the universe you can be sure of improving, and that’s your own self.
https://blog.csdn.net/weixin_39190382?type=blog
记录对unfold和fold的理解
def unfold(input, kernel_size, dilation=1, padding=0, stride=1):
"""
input: tensor数据,四维, Batchsize, channel, height, width
kernel_size: 核大小,决定输出tensor的数目。稍微详细讲
dilation: 输出形式是否有间隔,稍后详细讲。
padding:一般是没有用的必要
stride: 核的滑动步长。稍后详细讲
"""
若kernel_size=2,stride=2,则如下图所示,
直观理解:就是从HW面挑选一个一个的“长条”,这个“长条”的长宽由kernel_size指定。
实际项目中的案例和维度变换
# (32,256,56,56) -> (32,1024,784)
x = F.unfold(x, kernel_size=2, dilation=1, stride=2)
说明:
(B, C, H, W) -> (B, C * ∏ \prod ∏ kernel_size, L),其中L由下图公式得到:
2. 更进一步,
fold即为上述的逆过程
[1] https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html#torch.nn.Unfold
[2] https://blog.csdn.net/qq_42518956/article/details/104669625