# Convolution operator with groups for taking each convolved result

**URL:** <https://discuss.pytorch.org/t/convolution-operator-with-groups-for-taking-each-convolved-result/714>\
**Category:** Uncategorized\
**Created:** [February 25, 2017, 2:42am UTC](https://discuss.pytorch.org/t/convolution-operator-with-groups-for-taking-each-convolved-result/714 "2017-02-25T02:42:28Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [April 18, 2018, 8:43pm UTC](https://discuss.pytorch.org/t/convolution-operator-with-groups-for-taking-each-convolved-result/714/9 "2018-04-18T20:43:07Z")

</div>

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

```auto
# 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

---

_[View the full topic](https://discuss.pytorch.org/t/convolution-operator-with-groups-for-taking-each-convolved-result/714)._
