ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 7/21 - [17/10K] - preds = model(sweep_imgs, mats, ...)
    개발일지 2024. 7. 22. 00:46

    쉽지 않다.......

    아래 처럼 실행 후 preds를 구해도 128x128의 값이기 때문에 다시 박스를 계산해야한다.

    model = model.to(device)        
    preds = model(sweep_imgs, mats,
                    pts_pv=pts_pv,
                    is_train=False)

     

    너무 복잡하다 이게 하나의 로직이다.

    단순 그냥 박스 그리는것이 아니였다. 쩝......

        def eval_step(self, batch, batch_idx, prefix: str):
            (sweep_imgs, mats, img_metas, _, _, _, _, pts_pv) = batch
            if torch.cuda.is_available():
                if self.return_image:
                    sweep_imgs = sweep_imgs.cuda()
                    for key, value in mats.items():
                        mats[key] = value.cuda()
                if self.return_radar_pv:
                    pts_pv = pts_pv.cuda()
            preds = self(sweep_imgs, mats,
                         pts_pv=pts_pv,
                         is_train=False)
            if isinstance(self.model, torch.nn.parallel.DistributedDataParallel):
                results = self.model.module.get_bboxes(preds, img_metas)
            else:
                results = self.model.get_bboxes(preds, img_metas)
            for i in range(len(results)):
                results[i][0] = results[i][0].tensor.detach().cpu().numpy()
                results[i][1] = results[i][1].detach().cpu().numpy()
                results[i][2] = results[i][2].detach().cpu().numpy()
                results[i].append(img_metas[i])
            return results
    
       def test_epoch_end(self, test_step_outputs):
            all_pred_results = list()
            all_img_metas = list()
            for test_step_output in test_step_outputs:
                for i in range(len(test_step_output)):
                    all_pred_results.append(test_step_output[i][:3])
                    all_img_metas.append(test_step_output[i][3])
            synchronize()
            # TODO: Change another way.
            dataset_length = len(self.val_dataloader().dataset)
            all_pred_results = sum(
                map(list, zip(*all_gather_object(all_pred_results))),
                [])[:dataset_length]
            all_img_metas = sum(map(list, zip(*all_gather_object(all_img_metas))),
                                [])[:dataset_length]
            if self.global_rank == 0:
                self.evaluator.evaluate(all_pred_results, all_img_metas)
    
        def evaluate(
            self,
            results,
            img_metas,
            metric='bbox',
            logger=None,
            jsonfile_prefix=None,
            result_names=['img_bbox'],
            show=False,
            out_dir=None,
            pipeline=None,
        ):
            """Evaluation in nuScenes protocol.
    
            Args:
                results (list[dict]): Testing results of the dataset.
                metric (str | list[str]): Metrics to be evaluated.
                logger (logging.Logger | str | None): Logger used for printing
                    related information during evaluation. Default: None.
                jsonfile_prefix (str | None): The prefix of json files. It includes
                    the file path and the prefix of filename, e.g., "a/b/prefix".
                    If not specified, a temp file will be created. Default: None.
                show (bool): Whether to visualize.
                    Default: False.
                out_dir (str): Path to save the visualization results.
                    Default: None.
                pipeline (list[dict], optional): raw data loading for showing.
                    Default: None.
    
            Returns:
                dict[str, float]: Results of each evaluation metric.
            """
            result_files, tmp_dir = self.format_results(results, img_metas,
                                                        result_names,
                                                        jsonfile_prefix)              
    
    반응형
Designed by Tistory.