Exemplo n.º 1
0
    def _reset_dataset_evaluators(self):
        """reset validation dataset evaluator to be run in EVAL_PERIOD steps"""
        assert (not self.trainer.distributed_backend
                or self.trainer.distributed_backend.lower() in [
                    "ddp",
                    "ddp_cpu",
                ]), ("Only DDP and DDP_CPU distributed backend are supported")

        def _get_inference_dir_name(base_dir, inference_type, dataset_name,
                                    model_tag: ModelTag):
            next_eval_iter = self.trainer.global_step + self.cfg.TEST.EVAL_PERIOD
            if self.trainer.global_step == 0:
                next_eval_iter -= 1
            return os.path.join(
                base_dir,
                inference_type,
                model_tag,
                str(next_eval_iter),
                dataset_name,
            )

        for tag, dataset_evaluators in self.dataset_evaluators.items():
            dataset_evaluators.clear()
            assert self.cfg.OUTPUT_DIR, "Expect output_dir to be specified in config"
            for dataset_name in self.cfg.DATASETS.TEST:
                # setup evaluator for each dataset
                output_folder = _get_inference_dir_name(
                    self.cfg.OUTPUT_DIR, "inference", dataset_name, tag)
                evaluator = Detectron2GoRunner.get_evaluator(
                    self.cfg, dataset_name, output_folder=output_folder)
                evaluator.reset()
                dataset_evaluators.append(evaluator)
Exemplo n.º 2
0
    def _evaluation_dataloader(self):
        # TODO: Support subsample n images
        assert len(self.cfg.DATASETS.TEST)

        dataloaders = []
        for dataset_name in self.cfg.DATASETS.TEST:
            dataloaders.append(
                Detectron2GoRunner.build_detection_test_loader(self.cfg, dataset_name)
            )

        self._reset_dataset_evaluators()
        return dataloaders
Exemplo n.º 3
0
 def get_default_cfg(cls):
     return Detectron2GoRunner.get_default_cfg()
Exemplo n.º 4
0
 def train_dataloader(self):
     return Detectron2GoRunner.build_detection_train_loader(self.cfg)
Exemplo n.º 5
0
 def build_detection_test_loader(cfg, dataset_name, mapper=None):
     return Detectron2GoRunner.build_detection_test_loader(
         cfg, dataset_name, mapper)
Exemplo n.º 6
0
 def build_detection_train_loader(cfg, *args, mapper=None, **kwargs):
     return Detectron2GoRunner.build_detection_train_loader(
         cfg, *args, **kwargs)
Exemplo n.º 7
0
 def get_mapper(cfg, is_train):
     return Detectron2GoRunner.get_mapper(cfg, is_train)
Exemplo n.º 8
0
 def get_evaluator(cfg: CfgNode, dataset_name: str, output_folder: str):
     return Detectron2GoRunner.get_evaluator(cfg=cfg,
                                             dataset_name=dataset_name,
                                             output_folder=output_folder)
Exemplo n.º 9
0
 def get_visualization_evaluator(
 ) -> Optional[Type[VisualizationEvaluator]]:
     return Detectron2GoRunner.get_visualization_evaluator()