open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.29k stars 9.42k forks source link

Tracing Forward Function #8538

Open avickars opened 2 years ago

avickars commented 2 years ago

I am looking to optimize the data pipeline of the Mask RCNN model with a Swin backbone (this one to be specific: https://github.com/open-mmlab/mmdetection/blob/master/configs/swin/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py) to apply the transformations on GPU using pytorch. To do this I need to adjust the forward function of model but am having trouble tracing it through the model. I am not focusing much on tracing the actual pipeline since I can just adjust the results of the optimized version to match as needed. But will need to adjust the model itself.

So far I've been able to trace the forward function from:

Here (https://github.com/open-mmlab/mmdetection/blob/master/mmdet/models/detectors/mask_rcnn.py) -> some stuff in btw that I haven't been able to trace -> here(https://github.com/open-mmlab/mmdetection/blob/3b72b12fe9b14de906d1363982b9fba05e7d47c1/mmdet/models/detectors/two_stage.py#L173) -> some stuff in btw that I haven't been able to trace -> here (https://github.com/open-mmlab/mmdetection/blob/3b72b12fe9b14de906d1363982b9fba05e7d47c1/mmdet/models/detectors/base.py#L112).

The order in above might be incorrect. If anyone is able to offer guidance on how input is flowing through the forward pass of the model it would be greatly appreciated! As I am pretty stuck due to the massive amount of inheritance going on.

BIGWangYuDong commented 1 year ago

Seems your tracing is right during inference. Right now, it is suggested to use MMDet -3.x, which is more convenient for users. The two stage detector will first feed into backbone and fpn, and then the features will feed into rpnhead, and the results will then feed into roihead.