Convolution operator with groups for taking each convolved result
In my case, I want to take each convolution output. In traditional convolution networks, if we assume that input channel (R,G,B) is 3 and output channel (J1, J2) is 2, <SCODE>J1 = F1 * R + F2 * G + F3 * B
J1 = F4 * R + F5 * G + F6 * B
<ECODE> where F1,F2,… denotes filters (say 3x3 filters) and * denotes convolution operator. In my case, I want to manipulate the each convolved result. So I want to take the followings, not output images: <SCODE>F1 * R, F2 * G, F3 * B,
F4 * R, F5 * G, F6 * B
<ECODE>
Ja-Keoung_Koo
apaszke
Thanks you for kind reply! <SCODE>       self.weight = Parameter(torch.Tensor(
            out_channels, in_channels // groups, *kernel_size))<ECODE>
Ja-Keoung_Koo
apaszke
Thanks to this Q&A, it helps me to understand groups operation.
siki
juliohm
In a backprop context, you’d use groupwise convolution to either make the model splittable into more than one GPU (since the groups won’t have to “cross” data), or to force the training to split channels into different groupings of features (you can google on this, there are some nice explanations available). In a more general context, you could find any number of applications, lets say for simplicity that you just want to blur each R, G and B channel separately with a blur kernel and want RGB output (and you definitely don’t want to blur R with G etc.).
hinken
Quick follow-up: What is the order of the channels in the output image? Assuming input is RGB image and output is 6 channels (as in OP) is the order:
Yohan_Sumathipala
Let’s create a small example and have a look at the order: <SCODE># 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)]
<ECODE> The only way to get this result is the second guess.
ptrblck
Thanks so much, this is super helpful!
Yohan_Sumathipala
I try the following codes: <SCODE>import torch
from torch import nn

# Set (RGB)*2 = (0, 100, 200), (300, 400, 500)
x = (torch.arange(6, dtype=torch.double)*100).view(1, -1, 1, 1)

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

# Set Conv weight to 1
conv.weight.data = torch.ones(6, dtype=torch.double).view(2, 3, 1, 1)

output = conv(x)

print(output)
<ECODE> output = (500, 5000). The result seems to be your Guess 2, RR GG BB.
ixez