diff --git a/tests/test_cosypose_detector_training.py b/tests/test_cosypose_detector_training.py index 15cedac7..915387da 100644 --- a/tests/test_cosypose_detector_training.py +++ b/tests/test_cosypose_detector_training.py @@ -1,16 +1,55 @@ +import functools import os +import time +from collections import defaultdict import numpy as np import pytest +import torch +import torch.distributed as dist +import yaml from omegaconf import OmegaConf +from torch.backends import cudnn +from torch.hub import load_state_dict_from_url +from torch.utils.data import DataLoader +from torchnet.meter import AverageValueMeter +from tqdm import tqdm + +from happypose.pose_estimators.cosypose.cosypose.config import EXP_DIR +from happypose.pose_estimators.cosypose.cosypose.datasets.detection_dataset import ( + DetectionDataset, +) +# Evaluation +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, +) from happypose.pose_estimators.cosypose.cosypose.utils.distributed import ( get_world_size, init_distributed_mode, reduce_dict, sync_model, ) +from happypose.toolbox.datasets.datasets_cfg import make_scene_dataset +from happypose.toolbox.datasets.scene_dataset import ( + IterableMultiSceneDataset, + RandomIterableSceneDataset, +) + +# from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger from happypose.toolbox.utils.logging import get_logger +from happypose.toolbox.utils.resources import ( + get_cuda_memory, + get_gpu_memory, + get_total_memory, +) logger = get_logger(__name__) @@ -120,47 +159,6 @@ def test_detector_training(self): train_detector(self.cfg_detector) -import functools -import time -from collections import defaultdict - -import torch -import torch.distributed as dist -import yaml -from torch.backends import cudnn -from torch.hub import load_state_dict_from_url -from torch.utils.data import DataLoader -from torchnet.meter import AverageValueMeter -from tqdm import tqdm - -from happypose.pose_estimators.cosypose.cosypose.config import EXP_DIR -from happypose.pose_estimators.cosypose.cosypose.datasets.detection_dataset import ( - DetectionDataset, -) - -# Evaluation -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, -) -from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger -from happypose.toolbox.datasets.datasets_cfg import make_scene_dataset -from happypose.toolbox.datasets.scene_dataset import ( - IterableMultiSceneDataset, - RandomIterableSceneDataset, -) -from happypose.toolbox.utils.resources import ( - get_cuda_memory, - get_gpu_memory, - get_total_memory, -) - cudnn.benchmark = True logger = get_logger(__name__) diff --git a/tests/test_cosypose_pose_training.py b/tests/test_cosypose_pose_training.py index 95ace819..f627faaf 100644 --- a/tests/test_cosypose_pose_training.py +++ b/tests/test_cosypose_pose_training.py @@ -1,16 +1,56 @@ +import functools import os +import time +from collections import defaultdict import numpy as np import pytest +import torch +import torch.distributed as dist +import yaml from omegaconf import OmegaConf +from torch.backends import cudnn +from torch.utils.data import DataLoader +from torchnet.meter import AverageValueMeter +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.distributed import ( get_world_size, init_distributed_mode, reduce_dict, sync_model, ) +from happypose.toolbox.datasets.datasets_cfg import ( + make_object_dataset, + make_scene_dataset, +) +from happypose.toolbox.datasets.pose_dataset import PoseDataset +from happypose.toolbox.datasets.scene_dataset import ( + IterableMultiSceneDataset, + RandomIterableSceneDataset, +) +from happypose.toolbox.lib3d.rigid_mesh_database import MeshDataBase +from happypose.toolbox.renderer.panda3d_batch_renderer import Panda3dBatchRenderer + +# from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger from happypose.toolbox.utils.logging import get_logger +from happypose.toolbox.utils.resources import ( + get_cuda_memory, + get_gpu_memory, + get_total_memory, +) logger = get_logger(__name__) @@ -209,48 +249,6 @@ def test_pose_training(self): train_pose(self.cfg_pose) -import functools -import time -from collections import defaultdict - -import torch -import torch.distributed as dist -import yaml -from torch.backends import cudnn -from torch.utils.data import DataLoader -from torchnet.meter import AverageValueMeter -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, -) -from happypose.toolbox.datasets.pose_dataset import PoseDataset -from happypose.toolbox.datasets.scene_dataset import ( - IterableMultiSceneDataset, - RandomIterableSceneDataset, -) -from happypose.toolbox.lib3d.rigid_mesh_database import MeshDataBase -from happypose.toolbox.renderer.panda3d_batch_renderer import Panda3dBatchRenderer -from happypose.toolbox.utils.resources import ( - get_cuda_memory, - get_gpu_memory, - get_total_memory, -) - cudnn.benchmark = True logger = get_logger(__name__) diff --git a/tests/test_evaluation.py b/tests/test_evaluation.py index a1ca9f2b..f8253c08 100644 --- a/tests/test_evaluation.py +++ b/tests/test_evaluation.py @@ -8,10 +8,7 @@ # Third Party from omegaconf import OmegaConf -from happypose.pose_estimators.megapose.config import ( - LOCAL_DATA_DIR, - RESULTS_DIR, -) +from happypose.pose_estimators.megapose.config import LOCAL_DATA_DIR, RESULTS_DIR from happypose.pose_estimators.megapose.evaluation.bop import run_evaluation from happypose.pose_estimators.megapose.evaluation.eval_config import ( BOPEvalConfig, @@ -19,15 +16,11 @@ FullEvalConfig, HardwareConfig, ) -from happypose.pose_estimators.megapose.evaluation.evaluation import ( - get_save_dir, -) +from happypose.pose_estimators.megapose.evaluation.evaluation import get_save_dir 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.distributed import get_rank from happypose.toolbox.utils.logging import get_logger logger = get_logger(__name__) @@ -110,11 +103,11 @@ def test_config(self): assert ( self.cfg["inference"]["n_pose_hypotheses"] == 5 ), "Error: n_pose_hypotheses is not correct" + assert not self.cfg["inference"][ + "run_depth_refiner" + ], "Error: run_depth_refiner 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 + self.cfg["inference"]["depth_refiner"] is None ), "Error: depth_refiner is not correct" assert ( self.cfg["inference"]["bsz_objects"] == 16 @@ -129,34 +122,30 @@ def test_config(self): 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["n_frames"] is 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"], "Error: skip_inference is not correct" + assert self.cfg["skip_evaluation"], "Error: skip_evaluation 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 + self.cfg["global_batch_size"] is 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 not self.cfg["debug"], "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["run_bop_eval"], "Error: run_bop_eval is not correct" + assert not self.cfg[ + "eval_coarse_also" + ], "Error: eval_coarse_also is not correct" + assert not self.cfg["convert_only"], "Error: convert_only is not correct" # TODO # Rajouter un test pour save_dir ?