卷积 concat和add的区别

concat即在通道上进行叠加,直接把第二个放到第一个下面,channel*2。

而add是值相加,channel不变。

举个例子:

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]])

猜你喜欢

转载自blog.csdn.net/m0_59967951/article/details/126481341