在卷积神经网络中,经常会涉及到特征图之间的合并
合并的方法一般有两种,一种是concat,一种是add
add: 在图像通道数不变的情况下,将两张特征图的数值相加,优点是可以减少运算量
concat:在保留特征图内各通道数值不变的情况下,将通道直接叠加,相当于是把两张特征图打包成一个了,其实里面还各是各的
talk is cheap, show me the code
>>> import torch
>>> img1 = torch.randn(2, 3, 58, 58)
>>> img2 = torch.randn(2, 3, 58, 58)
>>> img3 = img1 + img2
>>> img4 = torch.cat((img1, img2), dim=1)
>>> img3.size()
torch.Size([2, 3, 58, 58])
>>> img4.size()
torch.Size([2, 6, 58, 58])
>>>