Inputting an image to a bunch of stacked ResNet blocks vs stacked Convolutional blocks

Mona_Jalal: <p>I am confused as to why we want to feed an image to a set of stacked resnet blocks versus feeding it to a bunch of convolutional blocks as we do so traditionally?</p>
<p>Also, how should we stack resnet blocks to each other? Is there any code sample or paper that does this?</p>
<p>I drew this diagram for illustration:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/3/9/39a0097da79fa37cddc801d6a13e39ce54d1bbb1.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/39a0097da79fa37cddc801d6a13e39ce54d1bbb1" title="Screen Shot 2021-08-23 at 11.34.33 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/39a0097da79fa37cddc801d6a13e39ce54d1bbb1_2_690x236.jpeg" alt="Screen Shot 2021-08-23 at 11.34.33 PM" data-base62-sha1="8dM5O2R2fM518oM2kT45g4FdaTf" width="690" height="236" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/39a0097da79fa37cddc801d6a13e39ce54d1bbb1_2_690x236.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/39a0097da79fa37cddc801d6a13e39ce54d1bbb1_2_1035x354.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/3/9/39a0097da79fa37cddc801d6a13e39ce54d1bbb1_2_1380x472.jpeg 2x" data-dominant-color="DFE2EB"><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">Screen Shot 2021-08-23 at 11.34.33 PM</span><span class="informations">2876×984 136 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>

ptrblck: <p>Wouldn’t this be the classical ResNet architecture as seen e.g. <a href="https://github.com/pytorch/vision/blob/7947fc8fb38b1d3a2aca03f22a2e6a3caa63f2a0/torchvision/models/resnet.py#L237-L240">here</a>?<br>
Depending on the flavor of the ResNet you could be using <code>Bottleneck</code> or <code>BasicBlock</code> as part of the “ResNet Blocks”.</p>

Mona_Jalal: <p>I am actually not sure what is meant by “ResNet block” here.</p>

ptrblck: <p>If this model is taken from another research paper, I would expect a definition of the “ResNet Block”, but my best guess would be e.g.:</p>
<pre><code class="lang-python">model = models.resnet18()
print(model.layer1)
&gt; Sequential(
  (0): BasicBlock(
    (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (1): BasicBlock(
    (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    (relu): ReLU(inplace=True)
    (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
)
</code></pre>

Mona_Jalal: <p>Thanks a lot for your response. Just checking if is this your definition of “ResNet block” as well?</p>
<p><a href="https://d2l.ai/chapter_convolutional-modern/resnet.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://d2l.ai/chapter_convolutional-modern/resnet.html</a></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/3/d3ae71879a2a4a55508c20215670276788925840.png" data-download-href="https://discuss.pytorch.org/uploads/default/d3ae71879a2a4a55508c20215670276788925840" title="Screen Shot 2021-08-24 at 12.20.39 AM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/3/d3ae71879a2a4a55508c20215670276788925840_2_690x437.png" alt="Screen Shot 2021-08-24 at 12.20.39 AM" data-base62-sha1="ucCumm8tnfICIUaGwl152EowNwY" width="690" height="437" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/3/d3ae71879a2a4a55508c20215670276788925840_2_690x437.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/3/d3ae71879a2a4a55508c20215670276788925840_2_1035x655.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/d/3/d3ae71879a2a4a55508c20215670276788925840_2_1380x874.png 2x" data-dominant-color="E5EAEE"><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">Screen Shot 2021-08-24 at 12.20.39 AM</span><span class="informations">1604×1016 56.7 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>

ptrblck: <p>The figure would represent the <a href="https://github.com/pytorch/vision/blob/7947fc8fb38b1d3a2aca03f22a2e6a3caa63f2a0/torchvision/models/resnet.py#L37-L83"><code>BasicBlock</code></a>.</p>