Skip to content

Commit 7f9facc

Browse files
author
Collin Zhang
authored
Implementation of YOLACT forward_dummy to enable get_flops (#6079)
* update forward_dummy * improve code * fix lint * include forward_dummy in unit test * remove hardcode * fix lint * fix bug * change simple_test to forward * update forward_dummy * fix problems * add test comment * fix lint
1 parent 8a67e53 commit 7f9facc

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

mmdet/models/dense_heads/yolact_head.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ def _init_layers(self):
663663
protonets = protonets[:-1]
664664
return nn.Sequential(*protonets)
665665

666+
def forward_dummy(self, x):
667+
prototypes = self.protonet(x)
668+
return prototypes
669+
666670
def forward(self, x, coeff_pred, bboxes, img_meta, sampling_results=None):
667671
"""Forward feature from the upstream network to get prototypes and
668672
linearly combine the prototypes, using masks coefficients, into

mmdet/models/detectors/yolact.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def forward_dummy(self, img):
3030
3131
See `mmdetection/tools/analysis_tools/get_flops.py`
3232
"""
33-
raise NotImplementedError
33+
feat = self.extract_feat(img)
34+
bbox_outs = self.bbox_head(feat)
35+
prototypes = self.mask_head.forward_dummy(feat[0])
36+
return (bbox_outs, prototypes)
3437

3538
def forward_train(self,
3639
img,

tests/test_models/test_forward.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ def test_yolact_forward():
541541
return_loss=True)
542542
assert isinstance(losses, dict)
543543

544+
# Test forward dummy for get_flops
545+
detector.forward_dummy(imgs)
546+
544547
# Test forward test
545548
detector.eval()
546549
with torch.no_grad():

0 commit comments

Comments
 (0)