The difference between convolution concat and add

Concat is to superimpose on the channel, directly put the second one under the first one, channel*2.

And add is the addition of values, and the channel remains unchanged.

for example:

x = torch.randn(2,2)
y = torch.rand(2,2)
print(x)
print(y)
print(x+y)

tensor([[-2.2214, -0.4907],
        [-0.3435, -1.0568]])
tensor([[0.7421, 0.0207],
        [0.6029, 0.9172]])
tensor([[-1.4793, -0.4700],
        [ 0.2594, -0.1396]])
y.add_(x)
print(y)

tensor([[-1.4793, -0.4700],
        [ 0.2594, -0.1396]])

Concat:

z = torch.cat([x,y],0) # dim = 0,沿着第一个维度
print(z)

tensor([[-2.2214, -0.4907],
        [-0.3435, -1.0568],
        [-1.4793, -0.4700],
        [ 0.2594, -0.1396]])

z = torch.cat([x,y],1) # dim = 1,沿着第二个维度
print(z)

tensor([[-2.2214, -0.4907, -1.4793, -0.4700],
        [-0.3435, -1.0568,  0.2594, -0.1396]])

Guess you like

Origin blog.csdn.net/m0_59967951/article/details/126481341