Convolution operator with groups for taking each convolved result

Let’s create a small example and have a look at the order:

# Set R=100, G=200, B=300
x = torch.FloatTensor([100, 200, 300]).view(1, -1, 1, 1)
x = Variable(x)

conv = nn.Conv2d(in_channels=3,
                 out_channels=6,
                 kernel_size=1,
                 stride=1,
                 padding=0,
                 groups=3,
                 bias=False)

# Set Conv weight to [0, 1, 2, 3, 4 ,5]
conv.weight.data = torch.arange(6).view(-1, 1, 1, 1)
output = conv(x)
print(output)
> Variable containing:
(0 ,0 ,.,.) = 
     0

(0 ,1 ,.,.) = 
   100

(0 ,2 ,.,.) = 
   400

(0 ,3 ,.,.) = 
   600

(0 ,4 ,.,.) = 
  1200

(0 ,5 ,.,.) = 
  1500
[torch.FloatTensor of size (1,6,1,1)]

The only way to get this result is the second guess.

J1 = F1 * R = 0 * 100 = 0
J2 = F2 * R = 1 = 100 = 100
J3 = F3 * G = 2 * 200 = 400
J4 = F4 * G = 3 * 200 = 600
J5 = F5 * B = 4 * 300 = 1200
J6 = F6 * B = 5 * 300 = 1500

12 Likes