'Conv2d with out_channels=2 producing output with 1 channel

As I understand, out_channels should decide the number of channels in output (I am new to pytorch). I am running this code:

import torch
from torch import nn

img = torch.tensor([[[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]]])
torchDetector = nn.Conv2d(in_channels=2,out_channels=2, kernel_size=(2, 2),bias=False, stride=1, padding=0)
filter = torch.tensor([[[[1,1],[1,1]],[[-1,-1],[-1,-1]]]])
torchDetector.weight = nn.Parameter(filter, requires_grad=False)
torchDetected = torchDetector(img)

print(torchDetected)

and expecting a result with 2 channels, but getting 1 channel:

tensor([[[[0, 0, 0],
          [0, 0, 0],
          [0, 0, 0]]]])

I was expecting this result:

tensor([[[[ 8.,  8.,  8.],
          [ 8.,  8.,  8.],
          [ 8.,  8.,  8.]],

         [[-8., -8., -8.],
          [-8., -8., -8.],
          [-8., -8., -8.]]]])

What am I missing?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source