Iterate/repeat convolution layer twice or thrice

aatiibutt: <p>Hi. I am reproducing a model, depicted in the following.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/3/932601d2a6039d45f95e5621de04a01f0844c590.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/932601d2a6039d45f95e5621de04a01f0844c590" title="model"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/3/932601d2a6039d45f95e5621de04a01f0844c590_2_690x271.jpeg" alt="model" data-base62-sha1="kZJCjJjfxUQVF2uy5QYWvhI33y0" width="690" height="271" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/3/932601d2a6039d45f95e5621de04a01f0844c590_2_690x271.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/9/3/932601d2a6039d45f95e5621de04a01f0844c590_2_1035x406.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/9/3/932601d2a6039d45f95e5621de04a01f0844c590.jpeg 2x" data-dominant-color="C5EBCF"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">model</span><span class="informations">1180×465 83.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
I have created a simple model for it as shown below, but i need help in “How to iterate the convolutional layer twice or thrice as shown in above figure”<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/d/6d7c91b3740561688f6222fd845499087818cacc.png" data-download-href="https://discuss.pytorch.org/uploads/default/6d7c91b3740561688f6222fd845499087818cacc" title="Capture-1"><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/d/6d7c91b3740561688f6222fd845499087818cacc.png" alt="Capture-1" data-base62-sha1="fCyVOiAMUplIHVuRsAWcTFCo5mA" width="370" height="500" data-dominant-color="EFF0F0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Capture-1</span><span class="informations">546×737 15.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Nikronic: <p>Hi,</p>
<p>I think by the repetition, they mean having same blocks connected to each other sequentially rather than passing input to a conv layer multiple times.<br>
In the latter case, for instance, if you have a 3-channel input, then after first conv block, you will get 64-channel tensor. Then how can one use same conv block which only accepts 3-channel input for your current tensor which has 64-channels after first iteration? Do they provided any information about it?<br>
The reason I think they just meant to have same block is that they wanted to simply model structure in the given table. Altought you can make sure if they provided information about model size or number of parameters.</p>
<p>Bests</p>

Hmrishav_Bandyopadhy: <p>Hi,<br>
In case of implementing repetitive blocks, you can set up an entry block and sequential repetitive blocks after the entry block. Implementing it as a module would be :</p>
<pre><code class="lang-auto">class Conv_rep(nn.Module):
      def __init__(self, in_channels, out_channels,num_reps, kernel_size=3, stride=1,
                 padding=1, dilation=1, bias=False):
               
           super(Conv_rep,self).__init__(in_channels, out_channels,num_reps, kernel_size, 
                                       stride, padding, dilation,bias)

           self.conv_entry=nn.Conv2d(in_channels=in_channels,out_channels=out_channels,
                           kernel_size=kernel_size,stride=stride,padding=padding)
           self.conv_rep=nn.Conv2d(in_channels=out_channels,out_channels=out_channels,
                           kernel_size=kernel_size,stride=stride,padding=padding)
           self.num_reps=num_reps
      
      def forward(self,x):
           
           x_rep=self.conv_entry(x)
           
           for i in range(1,self.num_rep):
                   x_rep=self.conv_rep(x_rep)
           return x_rep
</code></pre>
<p>Note that I haven’t added activations or Batch Normalization as nothing of that sort was mentioned, but you should add them according to your model and use-case [as I see you haven’t used activations in your ‘Net’ module]</p>

aatiibutt: <p>Thank Dear <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

aatiibutt: <p>Thanks Dear <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>