Evaluate Pedestrain Detection metrics
| 34 | PERSON_CLASSES = ['background', 'person'] |
| 35 | |
| 36 | class PedDetEvaluator(DatasetEvaluator): |
| 37 | """ |
| 38 | Evaluate Pedestrain Detection metrics |
| 39 | """ |
| 40 | |
| 41 | def __init__( |
| 42 | self, |
| 43 | dataset_name, |
| 44 | config, |
| 45 | distributed=True, |
| 46 | output_dir=None, |
| 47 | ): |
| 48 | """ |
| 49 | Args: |
| 50 | dataset_name (str): name of the dataset to be evaluated. |
| 51 | distributed (bool): if True, will collect results from all ranks for evaluation. |
| 52 | Otherwise, will evaluate the results in the current process. |
| 53 | output_dir (str): an output directory to dump results. |
| 54 | num_classes, ignore_label: deprecated argument |
| 55 | """ |
| 56 | self._logger = logging.getLogger(__name__) |
| 57 | |
| 58 | self._dataset_name = dataset_name |
| 59 | self._distributed = distributed |
| 60 | self._output_dir = output_dir |
| 61 | |
| 62 | self._cpu_device = torch.device("cpu") |
| 63 | self._thr = config.tester.kwargs.pos_thr |
| 64 | # self._gt_path = config.tester.kwargs.gt_path if config.tester.kwargs.gt_path.startswith('/mnt') or 's3://' in config.tester.kwargs.gt_path else str((Path(peddet_dataset.__file__).parent / 'resources' / config.tester.kwargs.gt_path).resolve()) |
| 65 | self._gt_path = config.tester.kwargs.gt_path |
| 66 | |
| 67 | def reset(self): |
| 68 | self._predictions = [] |
| 69 | |
| 70 | def process(self, inputs, outputs): |
| 71 | """ |
| 72 | Args: |
| 73 | inputs: the inputs to a model |
| 74 | It is a list of dicts. Each dict corresponds to an image and |
| 75 | contains keys like "height", "width", "file_name". |
| 76 | outputs: the outputs of a model. It is list of dicts with key "logits" and "bbox" |
| 77 | """ |
| 78 | orig_target_sizes = inputs["orig_size"] |
| 79 | filtered_outputs = [self.deplicate(r, self._thr) for r in outputs] |
| 80 | results = [{k:v.cpu().numpy() for k, v in r.items()} for r in filtered_outputs] |
| 81 | dtboxes = [np.hstack([r['boxes'], r['scores'][:, np.newaxis]]) for r in results] |
| 82 | dtboxes = [self.boxes_dump(db) for db in dtboxes] |
| 83 | filenames = inputs['filename'] |
| 84 | res = [{'ID':name, 'dtboxes':db} for name, db in zip(filenames, dtboxes)] |
| 85 | assert len(res) == len(outputs) |
| 86 | self._predictions.extend(res) |
| 87 | |
| 88 | def deplicate(self, record, thr): |
| 89 | |
| 90 | assert 'scores' in record |
| 91 | names = [k for (k, v) in record.items()] |
| 92 | flag = record['scores'] >= thr |
| 93 | for name in names: |