Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

[OTE / XAI] Handle two stage detector in the inferrer.py #104

Merged
merged 7 commits into from
Dec 13, 2022
Prev Previous commit
Next Next commit
handle two stage detectorin the inferrer.py
  • Loading branch information
dongkwan-kim01 committed Dec 12, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 381c3b092cafb729f67f82d59cd89660961f7182
14 changes: 12 additions & 2 deletions mpa/det/inferrer.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
from mpa.registry import STAGES
from .stage import DetectionStage
from mpa.utils.logger import get_logger
from mpa.modules.hooks.auxiliary_hooks import DetSaliencyMapHook
from mpa.modules.hooks.auxiliary_hooks import DetSaliencyMapHook, SaliencyMapHook


logger = get_logger()
@@ -164,8 +164,18 @@ def dummy_dump_features_hook(mod, inp, out):
# Use a single gpu for testing. Set in both mm_val_dataloader and eval_model
if is_module_wrapper(model):
model = model.module

# Class-wise Saliency map for Single-Stage Detector, otherwise use class-ignore saliency map.
if not dump_saliency_map:
saliency_hook = nullcontext()
elif hasattr(model, 'bbox_head'):
saliency_hook = DetSaliencyMapHook(eval_model.module)
else:
saliency_hook = SaliencyMapHook(eval_model.module.backbone)

# Inference with hooks
with eval_model.module.backbone.register_forward_hook(feature_vector_hook):
with DetSaliencyMapHook(eval_model.module) if dump_saliency_map else nullcontext() as saliency_hook:
with saliency_hook:
eval_predictions = single_gpu_test(eval_model, data_loader)
saliency_maps = saliency_hook.records if dump_saliency_map else [None] * len(self.dataset)