Why these two models(fasterrcnn_resnet50_fpn ) perfomance differently?

jim8790125: <p>I built a fasterrcnn_resnet50_fpn by myself, originally I want to change anchor size, while after I keep same anchor size as official tutoril model<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/0/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206.png" data-download-href="https://discuss.pytorch.org/uploads/default/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206_2_690x387.png" alt="image" data-base62-sha1="dODPYHHmGq6n6UnZZ32b7z2SCJU" width="690" height="387" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206_2_690x387.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206_2_1035x580.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/0/60d5c54045e59f015f5f8dfbc2dc23b9bdf00206.png 2x" data-dominant-color="EEEFF1"><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">1088×611 60.1 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>
(<a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial — PyTorch Tutorials 2.2.0+cu121 documentation</a>)</p>
<p>I found there are some different outcome.</p>
<p>The model I built:<br>
######################################################<br>
from torchvision.models.detection.faster_rcnn import FasterRCNN<br>
from torchvision.models.detection.rpn import AnchorGenerator<br>
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone<br>
import torchvision</p>
<h1><a name="backbone-resnet_fpn_backboneresnet50-pretrainedtrue-backboneout_channels-256-anchor_sizes-16-24-32-40-48-aspect_ratios-05-10-20-lenanchor_sizes-anchor_generator-anchorgeneratoranchor_sizes-aspect_ratios-model_define-fasterrcnnbackbone-num_classes2rpn_anchor_generatoranchor_generator-in-model-architecture-i-cant-find-any-difference-between-these-two-model-while-the-outcoms-are-1" class="anchor" href="#backbone-resnet_fpn_backboneresnet50-pretrainedtrue-backboneout_channels-256-anchor_sizes-16-24-32-40-48-aspect_ratios-05-10-20-lenanchor_sizes-anchor_generator-anchorgeneratoranchor_sizes-aspect_ratios-model_define-fasterrcnnbackbone-num_classes2rpn_anchor_generatoranchor_generator-in-model-architecture-i-cant-find-any-difference-between-these-two-model-while-the-outcoms-are-1"></a>backbone = resnet_fpn_backbone(‘resnet50’, pretrained=True)<br>
backbone.out_channels = 256<br>
anchor_sizes = ((16,), (24,), (32,), (40,), (48,))<br>
aspect_ratios = ((0.5, 1.0, 2.0),) * len(anchor_sizes)<br>
anchor_generator = AnchorGenerator(anchor_sizes, aspect_ratios)<br>
model_define = FasterRCNN(backbone, num_classes=2,rpn_anchor_generator=anchor_generator)<br>
#####################################################################<br>
In model architecture, I can’t find any difference between these two model, while the outcoms are:</h1>
<p><em>(from my model)</em></p>
<p>Epoch: [19]  [0/5]  eta: 0:00:19  lr: 0.000000  loss: 0.7908 (0.7908)  loss_classifier: 0.0189 (0.0189)  loss_box_reg: 0.0000 (0.0000)  loss_objectness: 0.5276 (0.5276)  loss_rpn_box_reg: 0.2442 (0.2442)  time: 3.9512  data: 3.1582  max mem: 6999<br>
Epoch: [19]  [4/5]  eta: 0:00:01  lr: 0.000000  loss: 0.7908 (0.8584)  loss_classifier: 0.0268 (0.0330)  loss_box_reg: 0.0001 (0.0001)  loss_objectness: 0.5352 (0.5403)  loss_rpn_box_reg: 0.2442 (0.2850)  time: 1.4091  data: 0.6444  max mem: 6999</p>
<p>IoU metric: bbox<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000</p>
<p>=================================================================<br>
<em>(from official tutorial model)</em></p>
<p>Epoch: [19]  [0/5]  eta: 0:00:08  lr: 0.000000  loss: 0.5121 (0.5121)  loss_classifier: 0.0884 (0.0884)  loss_box_reg: 0.0598 (0.0598)  loss_objectness: 0.1395 (0.1395)  loss_rpn_box_reg: 0.2244 (0.2244)  time: 1.7792  data: 1.3481  max mem: 1985<br>
Epoch: [19]  [4/5]  eta: 0:00:00  lr: 0.000000  loss: 0.3280 (0.3655)  loss_classifier: 0.0746 (0.0719)  loss_box_reg: 0.0558 (0.0446)  loss_objectness: 0.0961 (0.1129)  loss_rpn_box_reg: 0.1067 (0.1361)  time: 0.8701  data: 0.5613  max mem: 1985</p>
<h1><a name="iou-metric-bbox-average-precision-ap-iou050095-area-all-maxdets100-0046-average-precision-ap-iou050-area-all-maxdets100-0152-average-precision-ap-iou075-area-all-maxdets100-0010-average-precision-ap-iou050095-area-small-maxdets100-0049-average-precision-ap-iou050095-areamedium-maxdets100-0090-average-precision-ap-iou050095-area-large-maxdets100-1000-average-recall-ar-iou050095-area-all-maxdets-1-0077-average-recall-ar-iou050095-area-all-maxdets-10-0219-average-recall-ar-iou050095-area-all-maxdets100-0296-average-recall-ar-iou050095-area-small-maxdets100-0336-average-recall-ar-iou050095-areamedium-maxdets100-0122-average-recall-ar-iou050095-area-large-maxdets100-1000-2" class="anchor" href="#iou-metric-bbox-average-precision-ap-iou050095-area-all-maxdets100-0046-average-precision-ap-iou050-area-all-maxdets100-0152-average-precision-ap-iou075-area-all-maxdets100-0010-average-precision-ap-iou050095-area-small-maxdets100-0049-average-precision-ap-iou050095-areamedium-maxdets100-0090-average-precision-ap-iou050095-area-large-maxdets100-1000-average-recall-ar-iou050095-area-all-maxdets-1-0077-average-recall-ar-iou050095-area-all-maxdets-10-0219-average-recall-ar-iou050095-area-all-maxdets100-0296-average-recall-ar-iou050095-area-small-maxdets100-0336-average-recall-ar-iou050095-areamedium-maxdets100-0122-average-recall-ar-iou050095-area-large-maxdets100-1000-2"></a>IoU metric: bbox<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.046<br>
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = 0.152<br>
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = 0.010<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.049<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.090<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = 0.077<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = 0.219<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.296<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.336<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.122<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000</h1>
<p>I try many times, while the outcomes from my model are always same like this:</p>
<h1><a name="iou-metric-bbox-average-precision-ap-iou050095-area-all-maxdets100-0000-average-precision-ap-iou050-area-all-maxdets100-0000-average-precision-ap-iou075-area-all-maxdets100-0000-average-precision-ap-iou050095-area-small-maxdets100-0000-average-precision-ap-iou050095-areamedium-maxdets100-0000-average-precision-ap-iou050095-area-large-maxdets100-1000-average-recall-ar-iou050095-area-all-maxdets-1-0000-average-recall-ar-iou050095-area-all-maxdets-10-0000-average-recall-ar-iou050095-area-all-maxdets100-0000-average-recall-ar-iou050095-area-small-maxdets100-0000-average-recall-ar-iou050095-areamedium-maxdets100-0000-average-recall-ar-iou050095-area-large-maxdets100-1000-3" class="anchor" href="#iou-metric-bbox-average-precision-ap-iou050095-area-all-maxdets100-0000-average-precision-ap-iou050-area-all-maxdets100-0000-average-precision-ap-iou075-area-all-maxdets100-0000-average-precision-ap-iou050095-area-small-maxdets100-0000-average-precision-ap-iou050095-areamedium-maxdets100-0000-average-precision-ap-iou050095-area-large-maxdets100-1000-average-recall-ar-iou050095-area-all-maxdets-1-0000-average-recall-ar-iou050095-area-all-maxdets-10-0000-average-recall-ar-iou050095-area-all-maxdets100-0000-average-recall-ar-iou050095-area-small-maxdets100-0000-average-recall-ar-iou050095-areamedium-maxdets100-0000-average-recall-ar-iou050095-area-large-maxdets100-1000-3"></a>============================================================<br>
IoU metric: bbox<br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.000<br>
Average Precision  (AP) @[ IoU=0.50      | area=   all | maxDets=100 ] = <strong>0.000</strong><br>
Average Precision  (AP) @[ IoU=0.75      | area=   all | maxDets=100 ] = <strong>0.000</strong><br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = <strong>0.000</strong><br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] =<strong>0.000</strong><br>
Average Precision  (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000<br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=  1 ] = <strong>0.000</strong><br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets= 10 ] = <strong>0.000</strong><br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = <strong>0.000</strong><br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = <strong>0.000</strong><br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = <strong>0.000</strong><br>
Average Recall     (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000</h1>
<p>Plz help me, I’m so confused <img src="https://discuss.pytorch.org/images/emoji/apple/joy.png?v=12" title=":joy:" class="emoji" alt=":joy:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/crazy_face.png?v=12" title=":crazy_face:" class="emoji" alt=":crazy_face:" loading="lazy" width="20" height="20"> <img src="https://discuss.pytorch.org/images/emoji/apple/thinking.png?v=12" title=":thinking:" class="emoji" alt=":thinking:" loading="lazy" width="20" height="20"></p>

ptrblck: <p>Could you explain a bit what you’ve changed in your custom model?</p>
<p>PS: You can post code snippets by wrapping them into three backticks ```, which would make debugging a lot easier. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>