diff --git a/happypose/pose_estimators/cosypose/cosypose/training/train_detector.py b/happypose/pose_estimators/cosypose/cosypose/training/train_detector.py index 06db70d9..0cd3b7a7 100644 --- a/happypose/pose_estimators/cosypose/cosypose/training/train_detector.py +++ b/happypose/pose_estimators/cosypose/cosypose/training/train_detector.py @@ -231,7 +231,9 @@ def make_datasets(dataset_names): logger.info(f"Using pretrained model from {pretrain_path}.") model.load_state_dict(torch.load(pretrain_path)["state_dict"]) elif args.pretrain_coco: - state_dict = load_state_dict_from_url('https://download.pytorch.org/models/maskrcnn_resnet50_fpn_coco-bf2d0c1e.pth') + state_dict = load_state_dict_from_url( + "https://download.pytorch.org/models/maskrcnn_resnet50_fpn_coco-bf2d0c1e.pth" + ) def keep(k): return "box_predictor" not in k and "mask_predictor" not in k @@ -289,7 +291,7 @@ def lambd(batch): ) lr_scheduler.last_epoch = start_epoch - 1 # This led to a warning in newer version of PyTorch? - #lr_scheduler.step() + # lr_scheduler.step() for epoch in range(start_epoch, end_epoch): meters_train = defaultdict(AverageValueMeter) diff --git a/happypose/pose_estimators/cosypose/cosypose/training/train_pose.py b/happypose/pose_estimators/cosypose/cosypose/training/train_pose.py index d9ed2898..2f8543b9 100644 --- a/happypose/pose_estimators/cosypose/cosypose/training/train_pose.py +++ b/happypose/pose_estimators/cosypose/cosypose/training/train_pose.py @@ -439,9 +439,7 @@ def train_epoch(): max_norm=args.clip_grad_norm, norm_type=2, ) - meters_train["grad_norm"].add( - torch.as_tensor(total_grad_norm).item() - ) + meters_train["grad_norm"].add(torch.as_tensor(total_grad_norm).item()) optimizer.step() meters_time["backward"].add(time.time() - t) @@ -463,7 +461,6 @@ def validation(): loss = h(data=sample, meters=meters_val) meters_val["loss_total"].add(loss.item()) - @torch.no_grad() def test(): model.eval() diff --git a/happypose/pose_estimators/megapose/evaluation/bop.py b/happypose/pose_estimators/megapose/evaluation/bop.py index 03ec9226..b386038d 100644 --- a/happypose/pose_estimators/megapose/evaluation/bop.py +++ b/happypose/pose_estimators/megapose/evaluation/bop.py @@ -49,6 +49,7 @@ # Third Party from bop_toolkit_lib import inout # noqa + def main(): parser = argparse.ArgumentParser("Bop evaluation") parser.add_argument("--results_path", default="", type=str) @@ -121,16 +122,16 @@ def convert_results_to_bop( print("row =", row) obj_id = int(row.label.split("_")[-1]) if use_pose_score: - score = row['pose_score'] + score = row["pose_score"] else: - score = row['score'] + score = row["score"] if "time" in row: - time = row['time'] + time = row["time"] else: time = -1 pred = dict( - scene_id=row['scene_id'], - im_id=row['view_id'], + scene_id=row["scene_id"], + im_id=row["view_id"], obj_id=obj_id, score=score, t=t, @@ -202,9 +203,7 @@ def run_evaluation(cfg: BOPEvalConfig) -> None: csv_path = eval_dir / f"{method}_{cfg.dataset.split('.')[0]}-{cfg.split}.csv" # pose scores give better AR scores in general - convert_results_to_bop( - results_path, csv_path, cfg.method, use_pose_score=False - ) + convert_results_to_bop(results_path, csv_path, cfg.method, use_pose_score=False) if not cfg.convert_only: _run_bop_evaluation(csv_path, cfg.eval_dir, eval_detection=False) diff --git a/happypose/toolbox/utils/download.py b/happypose/toolbox/utils/download.py index 4fe9baa1..197f5b87 100755 --- a/happypose/toolbox/utils/download.py +++ b/happypose/toolbox/utils/download.py @@ -170,9 +170,7 @@ async def main(): if args.ycbv_tests: to_dl.append(("ycbv-debug.zip", DOWNLOAD_DIR)) - to_unzip.append( - (DOWNLOAD_DIR / "ycbv-debug.zip", LOCAL_DATA_DIR / "results") - ) + to_unzip.append((DOWNLOAD_DIR / "ycbv-debug.zip", LOCAL_DATA_DIR / "results")) if args.cosypose_models: for model in args.cosypose_models: diff --git a/tests/test_batch_renderer_panda3d.py b/tests/test_batch_renderer_panda3d.py index 0fdb44ed..2524823e 100644 --- a/tests/test_batch_renderer_panda3d.py +++ b/tests/test_batch_renderer_panda3d.py @@ -115,7 +115,12 @@ def test_batch_renderer(self, device): # Renders from 2 identical cams are equals assert tr_assert_close(renderings.rgbs[0], renderings.rgbs[1]) is None assert tr_assert_close(renderings.normals[0], renderings.normals[1]) is None - assert tr_assert_close(renderings.depths[0], renderings.depths[1], atol=1e-3, rtol=1e-3) is None + assert ( + tr_assert_close( + renderings.depths[0], renderings.depths[1], atol=1e-3, rtol=1e-3 + ) + is None + ) assert ( tr_assert_close(renderings.binary_masks[0], renderings.binary_masks[1]) is None diff --git a/tests/test_cosypose_detector_training.py b/tests/test_cosypose_detector_training.py index a1058201..15cedac7 100644 --- a/tests/test_cosypose_detector_training.py +++ b/tests/test_cosypose_detector_training.py @@ -1,32 +1,27 @@ import os -import numpy as np -import pytest +import numpy as np +import pytest from omegaconf import OmegaConf from happypose.pose_estimators.cosypose.cosypose.utils.distributed import ( - get_rank, get_world_size, init_distributed_mode, reduce_dict, sync_model, ) - -from happypose.toolbox.utils.logging import get_logger, set_logging_level +from happypose.toolbox.utils.logging import get_logger logger = get_logger(__name__) -class TestCosyposeDetectorTraining(): - + +class TestCosyposeDetectorTraining: @pytest.fixture(autouse=True) def setup(self): + args = {"config": "bop-ycbv-synt+real"} - args = { - 'config':'bop-ycbv-synt+real' - } - cfg_detector = OmegaConf.create({}) - + logger.info( f"Training with config: {args['config']}", ) @@ -82,22 +77,22 @@ def setup(self): cfg_detector.classifier_alpha = 1 cfg_detector.mask_alpha = 1 cfg_detector.box_reg_alpha = 1 - if "tless" in args['config']: + if "tless" in args["config"]: cfg_detector.input_resize = (540, 720) - elif "ycbv" in args['config']: + elif "ycbv" in args["config"]: cfg_detector.input_resize = (480, 640) - elif "bop-" in args['config']: + elif "bop-" in args["config"]: cfg_detector.input_resize = None else: raise ValueError - if "bop-" in args['config']: + if "bop-" in args["config"]: from happypose.pose_estimators.cosypose.cosypose.bop_config import ( BOP_CONFIG, PBR_DETECTORS, ) - bop_name, train_type = args['config'].split("-")[1:] + bop_name, train_type = args["config"].split("-")[1:] bop_cfg = BOP_CONFIG[bop_name] if train_type == "pbr": cfg_detector.train_ds_names = [(bop_cfg["train_pbr_ds_name"][0], 1)] @@ -112,7 +107,7 @@ def setup(self): cfg_detector.test_ds_names = bop_cfg["test_ds_name"] else: - raise ValueError(args['config']) + raise ValueError(args["config"]) cfg_detector.val_ds_names = cfg_detector.train_ds_names cfg_detector.run_id = f"detector-{args['config']}-{run_comment}-{N_RAND}" @@ -120,17 +115,15 @@ def setup(self): N_GPUS = int(os.environ.get("N_PROCS", 1)) cfg_detector.epoch_size = cfg_detector.epoch_size // N_GPUS self.cfg_detector = cfg_detector - + def test_detector_training(self): train_detector(self.cfg_detector) - + import functools import time from collections import defaultdict -import numpy as np -import simplejson as json import torch import torch.distributed as dist import yaml @@ -144,18 +137,17 @@ def test_detector_training(self): from happypose.pose_estimators.cosypose.cosypose.datasets.detection_dataset import ( DetectionDataset, ) -from happypose.pose_estimators.cosypose.cosypose.integrated.detector import Detector # Evaluation -from happypose.pose_estimators.cosypose.cosypose.scripts.run_detection_eval import ( - run_detection_eval, +from happypose.pose_estimators.cosypose.cosypose.training.detector_models_cfg import ( + check_update_config, + create_model_detector, ) -from happypose.pose_estimators.cosypose.cosypose.utils.distributed import ( - get_rank, - get_world_size, - init_distributed_mode, - reduce_dict, - sync_model, +from happypose.pose_estimators.cosypose.cosypose.training.maskrcnn_forward_loss import ( + h_maskrcnn, +) +from happypose.pose_estimators.cosypose.cosypose.training.train_detector import ( + collate_fn, ) from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger from happypose.toolbox.datasets.datasets_cfg import make_scene_dataset @@ -169,11 +161,6 @@ def test_detector_training(self): get_total_memory, ) -from happypose.pose_estimators.cosypose.cosypose.training.detector_models_cfg import check_update_config, create_model_detector -from happypose.pose_estimators.cosypose.cosypose.training.maskrcnn_forward_loss import h_maskrcnn - -from happypose.pose_estimators.cosypose.cosypose.training.train_detector import collate_fn - cudnn.benchmark = True logger = get_logger(__name__) @@ -293,7 +280,9 @@ def make_datasets(dataset_names): logger.info(f"Using pretrained model from {pretrain_path}.") model.load_state_dict(torch.load(pretrain_path)["state_dict"]) elif args.pretrain_coco: - state_dict = load_state_dict_from_url('https://download.pytorch.org/models/maskrcnn_resnet50_fpn_coco-bf2d0c1e.pth') + state_dict = load_state_dict_from_url( + "https://download.pytorch.org/models/maskrcnn_resnet50_fpn_coco-bf2d0c1e.pth" + ) def keep(k): return "box_predictor" not in k and "mask_predictor" not in k @@ -383,7 +372,9 @@ def train_epoch(): max_norm=np.inf, norm_type=2, ) - meters_train["grad_norm"].add(torch.as_tensor(total_grad_norm).item()) + meters_train["grad_norm"].add( + torch.as_tensor(total_grad_norm).item() + ) optimizer.step() meters_time["backward"].add(time.time() - t) @@ -444,4 +435,3 @@ def validation(): log_dict = reduce_dict(log_dict) dist.barrier() - diff --git a/tests/test_cosypose_pose_training.py b/tests/test_cosypose_pose_training.py index 4dc77a08..95ace819 100644 --- a/tests/test_cosypose_pose_training.py +++ b/tests/test_cosypose_pose_training.py @@ -1,7 +1,7 @@ import os -import numpy as np -import pytest +import numpy as np +import pytest from omegaconf import OmegaConf from happypose.pose_estimators.cosypose.cosypose.utils.distributed import ( @@ -10,26 +10,22 @@ reduce_dict, sync_model, ) - -from happypose.toolbox.utils.logging import get_logger, set_logging_level +from happypose.toolbox.utils.logging import get_logger logger = get_logger(__name__) -class TestCosyposePoseTraining(): - + +class TestCosyposePoseTraining: @pytest.fixture(autouse=True) def setup(self): - - args = { - 'config':'ycbv-refiner-syntonly' - } - + args = {"config": "ycbv-refiner-syntonly"} + cfg_pose = OmegaConf.create({}) - + logger.info( f"Training with config: {args['config']}", ) - if args['config']: + if args["config"]: logger.info( f"Training with config: {args['config']}", ) @@ -92,14 +88,14 @@ def setup(self): cfg_pose.n_iterations = 1 cfg_pose.min_area = None - if "bop-" in args['config']: + if "bop-" in args["config"]: from happypose.pose_estimators.cosypose.cosypose.bop_config import ( BOP_CONFIG, PBR_COARSE, PBR_REFINER, ) - bop_name, train_type, model_type = args['config'].split("-")[1:] + bop_name, train_type, model_type = args["config"].split("-")[1:] bop_cfg = BOP_CONFIG[bop_name] if train_type == "pbr": cfg_pose.train_ds_names = [(bop_cfg["train_pbr_ds_name"][0], 1)] @@ -128,7 +124,7 @@ def setup(self): else: raise ValueError - elif "ycbv-" in args['config']: + elif "ycbv-" in args["config"]: cfg_pose.urdf_ds_name = "ycbv" cfg_pose.object_ds_name = "ycbv" cfg_pose.train_ds_names = [ @@ -140,16 +136,16 @@ def setup(self): cfg_pose.test_ds_names = ["ycbv.test.keyframes"] cfg_pose.input_resize = (480, 640) - if args['config'] == "ycbv-refiner-syntonly": + if args["config"] == "ycbv-refiner-syntonly": cfg_pose.TCO_input_generator = "gt+noise" cfg_pose.train_ds_names = [("synthetic.ycbv-1M.train", 1)] - elif args['config'] == "ycbv-refiner-finetune": + elif args["config"] == "ycbv-refiner-finetune": cfg_pose.TCO_input_generator = "gt+noise" cfg_pose.run_id_pretrain = "ycbv-refiner-syntonly--596719" else: - raise ValueError(args['config']) + raise ValueError(args["config"]) - elif "tless-" in args['config']: + elif "tless-" in args["config"]: cfg_pose.urdf_ds_name = "tless.cad" cfg_pose.object_ds_name = "tless.cad" cfg_pose.train_ds_names = [ @@ -160,64 +156,63 @@ def setup(self): cfg_pose.test_ds_names = ["tless.primesense.test"] cfg_pose.input_resize = (540, 720) - if args['config'] == "tless-coarse": + if args["config"] == "tless-coarse": cfg_pose.TCO_input_generator = "fixed" - elif args['config'] == "tless-refiner": + elif args["config"] == "tless-refiner": cfg_pose.TCO_input_generator = "gt+noise" # Ablations - elif args['config'] == "tless-coarse-ablation-loss": + elif args["config"] == "tless-coarse-ablation-loss": cfg_pose.loss_disentangled = False cfg_pose.TCO_input_generator = "fixed" - elif args['config'] == "tless-refiner-ablation-loss": + elif args["config"] == "tless-refiner-ablation-loss": cfg_pose.loss_disentangled = False cfg_pose.TCO_input_generator = "gt+noise" - elif args['config'] == "tless-coarse-ablation-network": + elif args["config"] == "tless-coarse-ablation-network": cfg_pose.TCO_input_generator = "fixed" cfg_pose.backbone_str = "flownet" - elif args['config'] == "tless-refiner-ablation-network": + elif args["config"] == "tless-refiner-ablation-network": cfg_pose.TCO_input_generator = "gt+noise" cfg_pose.backbone_str = "flownet" - elif args['config'] == "tless-coarse-ablation-rot": + elif args["config"] == "tless-coarse-ablation-rot": cfg_pose.n_pose_dims = 7 cfg_pose.TCO_input_generator = "fixed" - elif args['config'] == "tless-refiner-ablation-rot": + elif args["config"] == "tless-refiner-ablation-rot": cfg_pose.n_pose_dims = 7 cfg_pose.TCO_input_generator = "gt+noise" - elif args['config'] == "tless-coarse-ablation-augm": + elif args["config"] == "tless-coarse-ablation-augm": cfg_pose.TCO_input_generator = "fixed" cfg_pose.rgb_augmentation = False - elif args['config'] == "tless-refiner-ablation-augm": + elif args["config"] == "tless-refiner-ablation-augm": cfg_pose.TCO_input_generator = "gt+noise" cfg_pose.rgb_augmentation = False else: - raise ValueError(args['config']) + raise ValueError(args["config"]) else: - raise ValueError(args['config']) + raise ValueError(args["config"]) cfg_pose.run_id = f"{args['config']}-{run_comment}-{N_RAND}" N_GPUS = int(os.environ.get("N_PROCS", 1)) cfg_pose.epoch_size = cfg_pose.epoch_size // N_GPUS self.cfg_pose = cfg_pose - - @pytest.mark.skip(reason="Currently, run two training tests (i.e. detector and pose) consecutively doesn't work with torch distributed") + + @pytest.mark.skip( + reason="Currently, run two training tests (i.e. detector and pose) consecutively doesn't work with torch distributed" + ) def test_pose_training(self): train_pose(self.cfg_pose) - - - + + import functools import time from collections import defaultdict -from pathlib import Path -import simplejson as json import torch import torch.distributed as dist import yaml @@ -227,10 +222,18 @@ def test_pose_training(self): from tqdm import tqdm from happypose.pose_estimators.cosypose.cosypose.config import EXP_DIR - - +from happypose.pose_estimators.cosypose.cosypose.training.pose_forward_loss import ( + h_pose, +) +from happypose.pose_estimators.cosypose.cosypose.training.pose_models_cfg import ( + check_update_config, + create_pose_model_cosypose, +) +from happypose.pose_estimators.cosypose.cosypose.training.train_pose import ( + make_eval_bundle, + run_eval, +) from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger - from happypose.toolbox.datasets.datasets_cfg import ( make_object_dataset, make_scene_dataset, @@ -248,16 +251,10 @@ def test_pose_training(self): get_total_memory, ) -from happypose.pose_estimators.cosypose.cosypose.training.pose_forward_loss import h_pose -from happypose.pose_estimators.cosypose.cosypose.training.pose_models_cfg import check_update_config, create_pose_model_cosypose - -from happypose.pose_estimators.cosypose.cosypose.training.train_pose import make_eval_bundle, run_eval, log - cudnn.benchmark = True logger = get_logger(__name__) - def train_pose(args): torch.set_num_threads(1) @@ -521,5 +518,3 @@ def test(): print("waiting on barrier") dist.barrier() - - \ No newline at end of file diff --git a/tests/test_evaluation.py b/tests/test_evaluation.py index bbfd8d1d..a1ca9f2b 100644 --- a/tests/test_evaluation.py +++ b/tests/test_evaluation.py @@ -1,82 +1,77 @@ -import os -import pytest -from pathlib import Path - # Standard Library import os +from pathlib import Path from typing import Dict +import pytest + # Third Party from omegaconf import OmegaConf from happypose.pose_estimators.megapose.config import ( + LOCAL_DATA_DIR, RESULTS_DIR, ) -from happypose.toolbox.utils.distributed import ( - get_rank, -) -from happypose.pose_estimators.megapose.scripts.run_full_megapose_eval import ( - create_eval_cfg -) +from happypose.pose_estimators.megapose.evaluation.bop import run_evaluation from happypose.pose_estimators.megapose.evaluation.eval_config import ( BOPEvalConfig, EvalConfig, FullEvalConfig, HardwareConfig, ) - -from happypose.pose_estimators.megapose.config import ( - LOCAL_DATA_DIR, -) - from happypose.pose_estimators.megapose.evaluation.evaluation import ( get_save_dir, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.evaluation import run_eval - -from happypose.pose_estimators.megapose.evaluation.bop import run_evaluation - -from happypose.toolbox.utils.logging import get_logger, set_logging_level +from happypose.pose_estimators.megapose.scripts.run_full_megapose_eval import ( + create_eval_cfg, +) +from happypose.toolbox.utils.distributed import ( + get_rank, +) +from happypose.toolbox.utils.logging import get_logger logger = get_logger(__name__) - -class TestCosyPoseEvaluation(): +class TestCosyPoseEvaluation: """Unit tests for CosyPose evaluation.""" + @pytest.fixture(autouse=True) def setUp(self) -> None: configuration = { - "detector_run_id":"bop_pbr", - "coarse_run_id":"coarse-bop-ycbv-pbr--724183", - "refiner_run_id":"refiner-bop-ycbv-pbr--604090", - "ds_names":["ycbv.bop19"], - "result_id":"ycbv-debug", - "detection_coarse_types":[["detector","S03_grid"]], - "skip_inference":True, - "run_bop_eval":True, + "detector_run_id": "bop_pbr", + "coarse_run_id": "coarse-bop-ycbv-pbr--724183", + "refiner_run_id": "refiner-bop-ycbv-pbr--604090", + "ds_names": ["ycbv.bop19"], + "result_id": "ycbv-debug", + "detection_coarse_types": [["detector", "S03_grid"]], + "skip_inference": True, + "run_bop_eval": True, } - + conf = OmegaConf.create(configuration) - + cfg: FullEvalConfig = OmegaConf.structured(FullEvalConfig) cfg.hardware = HardwareConfig( n_cpus=int(os.environ.get("N_CPUS", 10)), n_gpus=int(os.environ.get("WORLD_SIZE", 1)), ) - + cfg = OmegaConf.merge(cfg, conf) - + cfg.save_dir = RESULTS_DIR / cfg.result_id self.cfg = cfg - + # Iterate over each dataset for ds_name in self.cfg.ds_names: # create the EvalConfig objects that we will call `run_eval` on eval_configs: Dict[str, EvalConfig] = {} - for detection_type, coarse_estimation_type in self.cfg.detection_coarse_types: + for ( + detection_type, + coarse_estimation_type, + ) in self.cfg.detection_coarse_types: name, cfg_ = create_eval_cfg( self.cfg, detection_type, @@ -84,48 +79,85 @@ def setUp(self) -> None: ds_name, ) eval_configs[name] = cfg_ - - self.eval_cfg = eval_configs + self.eval_cfg = eval_configs - def test_config(self): assert self.eval_cfg is not None assert len(self.eval_cfg) == 1 - assert self.cfg['detector_run_id'] == 'bop_pbr', "Error: detector_run_id is not correct" - assert self.cfg['coarse_run_id'] == 'coarse-bop-ycbv-pbr--724183', "Error: coarse_run_id is not correct" - assert self.cfg['refiner_run_id'] == 'refiner-bop-ycbv-pbr--604090', "Error: refiner_run_id is not correct" - assert self.cfg['ds_name'] == 'ycbv.bop19', "Error: ds_name is not correct" - assert self.cfg['inference']['detection_type'] == 'detector', "Error: detection_type is not correct" - assert self.cfg['inference']['coarse_estimation_type'] == 'SO3_grid', "Error: coarse_estimation_type is not correct" - assert self.cfg['inference']['SO3_grid_size'] == 576, "Error: SO3_grid_size is not correct" - assert self.cfg['inference']['n_refiner_iterations'] == 5, "Error: n_refiner_iterations is not correct" - assert self.cfg['inference']['n_pose_hypotheses'] == 5, "Error: n_pose_hypotheses is not correct" - assert self.cfg['inference']['run_depth_refiner'] == False, "Error: run_depth_refiner is not correct" - assert self.cfg['inference']['depth_refiner'] == None, "Error: depth_refiner is not correct" - assert self.cfg['inference']['bsz_objects'] == 16, "Error: bsz_objects is not correct" - assert self.cfg['inference']['bsz_images'] == 288, "Error: bsz_images is not correct" - assert self.cfg['result_id'] == 'ycbv-debug', "Error: result_id is not correct" - assert self.cfg['n_dataloader_workers'] == 8, "Error: n_dataloader_workers is not correct" - assert self.cfg['n_rendering_workers'] == 8, "Error: n_rendering_workers is not correct" - assert self.cfg['n_frames'] == None, "Error: n_frames is not correct" - assert self.cfg['batch_size'] == 1, "Error: batch_size is not correct" - assert self.cfg['save_dir'] == f'{LOCAL_DATA_DIR}/results/ycbv-debug', "Error: save_dir is not correct" - assert self.cfg['bsz_images'] == 256, "Error: bsz_images is not correct" - assert self.cfg['bsz_objects'] == 16, "Error: bsz_objects is not correct" - assert self.cfg['skip_inference'] == True, "Error: skip_inference is not correct" - assert self.cfg['skip_evaluation'] == True, "Error: skip_evaluation is not correct" - assert self.cfg['global_batch_size'] == None, "Error: global_batch_size is not correct" - assert self.cfg['hardware']['n_cpus'] == 10, "Error: n_cpus is not correct" - assert self.cfg['hardware']['n_gpus'] == 1, "Error: n_gpus is not correct" - assert self.cfg['debug'] == False, "Error: debug is not correct" - assert self.cfg['detection_coarse_types'] == [['detector', 'S03_grid']], "Error: detection_coarse_types is not correct" - assert self.cfg['ds_names'] == ['ycbv.bop19'], "Error: ds_names is not correct" - assert self.cfg['run_bop_eval'] == True, "Error: run_bop_eval is not correct" - assert self.cfg['eval_coarse_also'] == False, "Error: eval_coarse_also is not correct" - assert self.cfg['convert_only'] == False, "Error: convert_only is not correct" - - + assert ( + self.cfg["detector_run_id"] == "bop_pbr" + ), "Error: detector_run_id is not correct" + assert ( + self.cfg["coarse_run_id"] == "coarse-bop-ycbv-pbr--724183" + ), "Error: coarse_run_id is not correct" + assert ( + self.cfg["refiner_run_id"] == "refiner-bop-ycbv-pbr--604090" + ), "Error: refiner_run_id is not correct" + assert self.cfg["ds_name"] == "ycbv.bop19", "Error: ds_name is not correct" + assert ( + self.cfg["inference"]["detection_type"] == "detector" + ), "Error: detection_type is not correct" + assert ( + self.cfg["inference"]["coarse_estimation_type"] == "SO3_grid" + ), "Error: coarse_estimation_type is not correct" + assert ( + self.cfg["inference"]["SO3_grid_size"] == 576 + ), "Error: SO3_grid_size is not correct" + assert ( + self.cfg["inference"]["n_refiner_iterations"] == 5 + ), "Error: n_refiner_iterations is not correct" + assert ( + self.cfg["inference"]["n_pose_hypotheses"] == 5 + ), "Error: n_pose_hypotheses is not correct" + assert ( + self.cfg["inference"]["run_depth_refiner"] == False + ), "Error: run_depth_refiner is not correct" + assert ( + self.cfg["inference"]["depth_refiner"] == None + ), "Error: depth_refiner is not correct" + assert ( + self.cfg["inference"]["bsz_objects"] == 16 + ), "Error: bsz_objects is not correct" + assert ( + self.cfg["inference"]["bsz_images"] == 288 + ), "Error: bsz_images is not correct" + assert self.cfg["result_id"] == "ycbv-debug", "Error: result_id is not correct" + assert ( + self.cfg["n_dataloader_workers"] == 8 + ), "Error: n_dataloader_workers is not correct" + assert ( + self.cfg["n_rendering_workers"] == 8 + ), "Error: n_rendering_workers is not correct" + assert self.cfg["n_frames"] == None, "Error: n_frames is not correct" + assert self.cfg["batch_size"] == 1, "Error: batch_size is not correct" + assert ( + self.cfg["save_dir"] == f"{LOCAL_DATA_DIR}/results/ycbv-debug" + ), "Error: save_dir is not correct" + assert self.cfg["bsz_images"] == 256, "Error: bsz_images is not correct" + assert self.cfg["bsz_objects"] == 16, "Error: bsz_objects is not correct" + assert ( + self.cfg["skip_inference"] == True + ), "Error: skip_inference is not correct" + assert ( + self.cfg["skip_evaluation"] == True + ), "Error: skip_evaluation is not correct" + assert ( + self.cfg["global_batch_size"] == None + ), "Error: global_batch_size is not correct" + assert self.cfg["hardware"]["n_cpus"] == 10, "Error: n_cpus is not correct" + assert self.cfg["hardware"]["n_gpus"] == 1, "Error: n_gpus is not correct" + assert self.cfg["debug"] == False, "Error: debug is not correct" + assert self.cfg["detection_coarse_types"] == [ + ["detector", "S03_grid"] + ], "Error: detection_coarse_types is not correct" + assert self.cfg["ds_names"] == ["ycbv.bop19"], "Error: ds_names is not correct" + assert self.cfg["run_bop_eval"] == True, "Error: run_bop_eval is not correct" + assert ( + self.cfg["eval_coarse_also"] == False + ), "Error: eval_coarse_also is not correct" + assert self.cfg["convert_only"] == False, "Error: convert_only is not correct" + # TODO # Rajouter un test pour save_dir ? # Modifier ensuite pour que le path soit un path temporaire ? @@ -152,7 +184,9 @@ def test_evaluation_existing_results(self): # Run the bop eval for each type of prediction if self.cfg.run_bop_eval and get_rank() == 0: bop_eval_keys = {"refiner/final", "depth_refiner"} - bop_eval_keys = bop_eval_keys.intersection(set(eval_out["pred_keys"])) + bop_eval_keys = bop_eval_keys.intersection( + set(eval_out["pred_keys"]) + ) for method in bop_eval_keys: if "bop19" not in ds_name: @@ -170,17 +204,22 @@ def test_evaluation_existing_results(self): bop_eval_cfgs.append(bop_eval_cfg) assert bop_eval_cfg.results_path == eval_out["results_path"] - assert bop_eval_cfg.dataset == 'ycbv.bop19' - + assert bop_eval_cfg.dataset == "ycbv.bop19" + if get_rank() == 0: if self.cfg.run_bop_eval: for bop_eval_cfg in bop_eval_cfgs: scores_pose_path, _ = run_evaluation(bop_eval_cfg) - assert Path(LOCAL_DATA_DIR / "bop_eval_outputs" / f"refiner-final_{bop_eval_cfg.dataset.split('.')[0]}-{bop_eval_cfg.split}" / "scores_bop19.json").is_file() - #assert scores_pose_path.is_file() + assert Path( + LOCAL_DATA_DIR + / "bop_eval_outputs" + / f"refiner-final_{bop_eval_cfg.dataset.split('.')[0]}-{bop_eval_cfg.split}" + / "scores_bop19.json" + ).is_file() + # assert scores_pose_path.is_file() logger.info(f"Process {get_rank()} reached end of script") - + # TODO : Run the inference, then use the results for evaluation """ # The inference shouldn't be tested in this function? @@ -190,7 +229,7 @@ def eval_out(self, setUp): for _save_key, eval_cfg in self.eval_cfg.items(): # Run the inference self.eval_out = run_eval(eval_cfg) - + def test_evaluation_inference(self, eval_out): bop_eval_cfgs = [] for ds_name in self.cfg.ds_names: diff --git a/tests/test_scene_renderer_panda3d.py b/tests/test_scene_renderer_panda3d.py index 637cee6e..ae31c013 100644 --- a/tests/test_scene_renderer_panda3d.py +++ b/tests/test_scene_renderer_panda3d.py @@ -93,7 +93,12 @@ def test_scene_renderer(self, device): # render from 2 identical cams are equals assert tr_assert_close(renderings[0].rgb, renderings[1].rgb) is None assert tr_assert_close(renderings[0].normals, renderings[1].normals) is None - assert tr_assert_close(renderings[0].depth, renderings[1].depth, atol=1e-3, rtol=1e-3) is None + assert ( + tr_assert_close( + renderings[0].depth, renderings[1].depth, atol=1e-3, rtol=1e-3 + ) + is None + ) assert ( tr_assert_close(renderings[0].binary_mask, renderings[1].binary_mask) is None