# Get the input channels for the conv2d from previous layer?

**URL:** <https://discuss.pytorch.org/t/get-the-input-channels-for-the-conv2d-from-previous-layer/78510>\
**Category:** vision\
**Created:** [April 26, 2020, 12:45pm UTC](https://discuss.pytorch.org/t/get-the-input-channels-for-the-conv2d-from-previous-layer/78510 "2020-04-26T12:45:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aayush\_Garg](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aayush_garg/32/23363_2.png) [@Aayush\_Garg](https://discuss.pytorch.org/u/Aayush_Garg)\
**Post date:** [April 26, 2020, 12:45pm UTC](https://discuss.pytorch.org/t/get-the-input-channels-for-the-conv2d-from-previous-layer/78510/1 "2020-04-26T12:45:13Z")

</div>

Hi guys,  
I was wondering if there are many convolutional layers (conv1 --\> conv2 ). How can we get the input channels parameter for the conv2 from the conv1 output channel?

```auto
class MyModel(nn.Module):
  def __init__ (self, in_ch, num_features, out_ch2):
    super(MyModel, self). __init__ ()
    self.conv1 = nn.Conv2D(in_channels,num_features)
    self.conv2 = nn.Conv2D(in_channnels_from_out_channels_of_conv1,out_ch2)

```

Can I get the out\_channels from the conv1 layer and use it as in\_ch for conv2?

---

<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 27, 2020, 1:51am UTC](https://discuss.pytorch.org/t/get-the-input-channels-for-the-conv2d-from-previous-layer/78510/2 "2020-04-27T01:51:06Z")

</div>

Yes, you can directly access this property via:

```python
self.conv1.out_channels

```

For your code snippet, this should work:

```python
self.conv1 = nn.Conv2D(in_channels,num_features)
self.conv2 = nn.Conv2D(self.conv1.out_channels,out_ch2)

```

---

<div class="post-metadata">

**Author:** ![Aayush\_Garg](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aayush_garg/32/23363_2.png) [@Aayush\_Garg](https://discuss.pytorch.org/u/Aayush_Garg)\
**Post date:** [April 27, 2020, 3:17am UTC](https://discuss.pytorch.org/t/get-the-input-channels-for-the-conv2d-from-previous-layer/78510/3 "2020-04-27T03:17:45Z")

</div>

@ptrblck Thanks, I dont think I framed my question correctly earlier.

Actually what I am looking for is something this

```auto
# Class for a single Block
class SingleBlock(nn.Module):

  def __init__ (self, in_channels, num_channels, drop_out=0.2):
    super(SingleBlock, self). __init__ ()

    self.conv = conv3X3(in_channels, num_channels)
# self.outchannels = self.conv.out_channels

# def get_out_channels(self):
# return _outchannels
  
  def forward(self, x):
    concat = x
    out = self.conv(out)
    out = torch.cat((out,concat), axis=1)

    ## Only while Q.C. to see output shape
    # out = self.lrelu(out)

    return out

# Q. C. single SingleBlock
qc_toggle = 1
if qc_toggle == 1:
  
  # print the model summary (Not exactly great)
  temp_block = DenseBlock(3,32)
  print(temp_block)

```

When I make this network I want to access the out\_channels in this (after the torch.cat) so that I can use it in some other place.

Can I do some get function or is there any property to get the out\_channels in this network?
