I am trying to understand usage of nn.Identity , but unable to understand what pytorch document referring with following example nn.Identity
seed =4
m = nn.Identity()
input = torch.randn(4,4)
output = m(input)
print(output)
print(output.size())
What nn.Identity is doing here ?
tensor([[-0.2381, -0.0488, 1.2883, -2.0334],
[-0.7297, -0.8721, 0.7086, 0.3899],
[ 0.6550, 1.4832, 0.3744, -1.2825],
[ 2.3327, 0.5004, -0.8785, 0.5100]])
torch.Size([4, 4])
Without identiy
seed =4
input = torch.randn(4,4)
output = input
print(output)
print(output.size())
tensor([[-0.0255, -0.5771, -0.5268, -0.6201],
[ 1.0814, 0.4274, 0.6822, 0.2369],
[ 0.0251, -1.1992, -0.9557, 0.9640],
[-0.2789, -2.4326, -2.4736, 0.2777]])
torch.Size([4, 4])
seed =4
m = nn.Identity()
input = torch.randn(4,4)
output = m(input)
print(f'input {input}')
print(f'output {output}')
input tensor([[-1.3704, -0.4062, -0.5499, 1.8572],
[ 0.3674, 0.4486, -0.3362, -1.4035],
[ 0.1322, 0.2116, -0.1157, 1.0715],
[ 0.8215, 0.1549, 0.8935, -0.1930]])
output tensor([[-1.3704, -0.4062, -0.5499, 1.8572],
[ 0.3674, 0.4486, -0.3362, -1.4035],
[ 0.1322, 0.2116, -0.1157, 1.0715],
[ 0.8215, 0.1549, 0.8935, -0.1930]])