|
|
import torch |
|
|
from ..utils.post_processing import load_predictions, save_predictions |
|
|
|
|
|
|
|
|
class BaseDetector(torch.nn.Module): |
|
|
"""Base class for detectors.""" |
|
|
|
|
|
def __init__(self): |
|
|
super(BaseDetector, self).__init__() |
|
|
|
|
|
def forward( |
|
|
self, |
|
|
inputs, |
|
|
masks, |
|
|
metas, |
|
|
gt_segments=None, |
|
|
gt_labels=None, |
|
|
return_loss=True, |
|
|
infer_cfg=None, |
|
|
post_cfg=None, |
|
|
**kwargs |
|
|
): |
|
|
if return_loss: |
|
|
return self.forward_train(inputs, masks, metas, gt_segments=gt_segments, gt_labels=gt_labels, **kwargs) |
|
|
else: |
|
|
return self.forward_detection(inputs, masks, metas, infer_cfg, post_cfg, **kwargs) |
|
|
|
|
|
def forward_detection(self, inputs, masks, metas, infer_cfg, post_cfg, **kwargs): |
|
|
|
|
|
if infer_cfg.load_from_raw_predictions: |
|
|
predictions = load_predictions(metas, infer_cfg) |
|
|
else: |
|
|
predictions = self.forward_test(inputs, masks, metas, infer_cfg) |
|
|
|
|
|
if infer_cfg.save_raw_prediction: |
|
|
save_predictions(predictions, metas, infer_cfg.folder) |
|
|
|
|
|
|
|
|
results = self.post_processing(predictions, metas, post_cfg, **kwargs) |
|
|
return results |
|
|
|