How to compute the model complexity of FasterRCNNFPN pretrained from torchvision?

pvtien96: <p>I got the pretrained FASTERRCNN_RESNET50_FPN model from pytorch (torchvision).<br>
Now I want to compute the model’s complexity (number of parameters and FLOPs) as reported from torchvsion:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/c/2cd715d1cbf5d428d687550e93243e4079e6d02e.png" data-download-href="https://discuss.pytorch.org/uploads/default/2cd715d1cbf5d428d687550e93243e4079e6d02e" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cd715d1cbf5d428d687550e93243e4079e6d02e_2_690x382.png" alt="image" data-base62-sha1="6oFPfMcU1ioeGlGpTJyWSWbPNcG" width="690" height="382" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cd715d1cbf5d428d687550e93243e4079e6d02e_2_690x382.png, https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cd715d1cbf5d428d687550e93243e4079e6d02e_2_1035x573.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/2/c/2cd715d1cbf5d428d687550e93243e4079e6d02e_2_1380x764.png 2x" data-dominant-color="F3F3F4"><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">image</span><span class="informations">1854×1028 121 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>
<p>How to do this? Normally with classification model (e.g. resnet50), we can use tools such as <code>thop</code> or <code>ptflop</code>. But the main concern is: What is the correct input image size (width &amp; height, channel=3 for sure)? From my reading, FasterCNN accepts unfixed input image size, but I’ve not found the step where the image is resized during forward. Personally, I think the image will be passed to the backbone firstly (which is resnet50), so I chose input image size = (224,224) (same as imagenet’s). But when trying this with <code>ptflop</code>, the output FLOPs is very unstable.</p>
<p>Any recommendation is appreciated! Thanks in advance!</p>

pvtien96: <p>The number of parameters is invariant with input size.<br>
For the computational complexity (e.g, MACs), <code>torchvision</code> set default value for their models as follows:</p>
<pre><code class="lang-auto">detection_models_input_dims = {
    "fasterrcnn_mobilenet_v3_large_320_fpn": (320, 320),
    "fasterrcnn_mobilenet_v3_large_fpn": (800, 800),
    "fasterrcnn_resnet50_fpn": (800, 800),
    "fasterrcnn_resnet50_fpn_v2": (800, 800),
    "fcos_resnet50_fpn": (800, 800),
    "keypointrcnn_resnet50_fpn": (1333, 1333),
    "maskrcnn_resnet50_fpn": (800, 800),
    "maskrcnn_resnet50_fpn_v2": (800, 800),
    "retinanet_resnet50_fpn": (800, 800),
    "retinanet_resnet50_fpn_v2": (800, 800),
    "ssd300_vgg16": (300, 300),
    "ssdlite320_mobilenet_v3_large": (320, 320),
}
</code></pre>
<p>This can be verified here: <a href="https://github.com/pytorch/vision/blob/25c8a3a2cc2699e4e261b9e0777a6dc5badb5f9f/test/test_extended_models.py#L158" class="inline-onebox" rel="noopener nofollow ugc">vision/test/test_extended_models.py at 25c8a3a2cc2699e4e261b9e0777a6dc5badb5f9f · pytorch/vision · GitHub</a></p>
<p>More discussion <a href="https://github.com/pytorch/vision/pull/6936" rel="noopener nofollow ugc">https://github.com/pytorch/vision/pull/6936</a></p>
<p>Running <code>ptflop</code> with an input size of (800, 800) yields identical numbers as reported by <code>torchvision</code>.</p>