From 838cfb4d6abdd73069216939ee768f677d172068 Mon Sep 17 00:00:00 2001 From: kzorina Date: Fri, 25 Oct 2024 16:53:31 +0200 Subject: [PATCH] fix hardcoded ycbv, some issues with panda batch and cosy eval doc --- docs/book/cosypose/evaluate.md | 14 ++++++++++---- .../cosypose/cosypose/evaluation/evaluation.py | 17 +++++++++-------- .../pose_estimators/megapose/inference/types.py | 2 ++ .../toolbox/renderer/panda3d_batch_renderer.py | 10 +++++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/book/cosypose/evaluate.md b/docs/book/cosypose/evaluate.md index 5a3e6f2c..b754406c 100644 --- a/docs/book/cosypose/evaluate.md +++ b/docs/book/cosypose/evaluate.md @@ -1,11 +1,17 @@ -# Evaluating CosyPose +# CosyPose single view evaluation Please make sure you followed the steps relative to the evaluation in the main readme. -Please run the following command to evaluate on YCBV dataset +To evaluate on YCBV dataset: ``` -python -m happypose.pose_estimators.cosypose.cosypose.scripts.run_full_cosypose_eval_new 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"] +python -m happypose.pose_estimators.cosypose.cosypose.scripts.run_full_cosypose_eval_new 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"] inference.renderer=bullet inference.n_workers=0 ``` -The other BOP datasets are supported as long as you download the correspond models. +To change the renderer from bullet (originally used by cosypose) to panda3d: +``` +python -m happypose.pose_estimators.cosypose.cosypose.scripts.run_full_cosypose_eval_new 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"] inference.renderer=panda3d inference.n_workers=1 +``` + +To evaluate on other datasets, change ["ycbv.bop19"] to e.g. ["tless.bop19"]. +To evaluate on a collection of datasets, change "ycbv.bop19" to e.g. ["ycbv.bop19", "lmo.bop19", "tless.bop19"]. \ No newline at end of file diff --git a/happypose/pose_estimators/cosypose/cosypose/evaluation/evaluation.py b/happypose/pose_estimators/cosypose/cosypose/evaluation/evaluation.py index a2d37a88..78950bfc 100644 --- a/happypose/pose_estimators/cosypose/cosypose/evaluation/evaluation.py +++ b/happypose/pose_estimators/cosypose/cosypose/evaluation/evaluation.py @@ -34,7 +34,6 @@ # Pose estimator from happypose.toolbox.datasets.datasets_cfg import make_object_dataset, make_scene_dataset, get_obj_ds_info -from happypose.toolbox.inference.utils import load_detector from happypose.toolbox.lib3d.rigid_mesh_database import MeshDataBase from happypose.toolbox.utils.distributed import get_rank, get_tmp_dir from happypose.toolbox.utils.logging import get_logger @@ -69,7 +68,7 @@ def load_detector(run_id, ds_name): return model -def load_pose_models(object_dataset, coarse_run_id, refiner_run_id, n_workers, renderer_type="panda3d"): +def load_pose_models_cosypose(object_dataset, coarse_run_id, refiner_run_id, n_workers, renderer_type="panda3d"): run_dir = EXP_DIR / coarse_run_id cfg = yaml.load((run_dir / "config.yaml").read_text(), Loader=yaml.UnsafeLoader) cfg = check_update_config_pose(cfg) @@ -161,6 +160,8 @@ def run_eval( cfg.save_dir = str(save_dir) logger.info(f"Running eval on ds_name={cfg.ds_name} with setting={save_key}") + # e.g. "ycbv.bop19" -> "ycbv" + ds_name_short = cfg.ds_name.split('.')[0] # Load the dataset ds_kwargs = {"load_depth": False} @@ -181,8 +182,7 @@ def run_eval( # Load detector model if cfg.inference.detection_type == "detector": assert cfg.detector_run_id is not None - detector_model = load_detector(cfg.detector_run_id, cfg.ds_name) - # detector_model = load_detector(cfg.detector_run_id, device=device) + detector_model = load_detector(cfg.detector_run_id, ds_name_short) elif cfg.inference.detection_type == "gt": detector_model = None else: @@ -195,14 +195,15 @@ def run_eval( assert cfg.coarse_run_id is not None assert cfg.refiner_run_id is not None - object_ds = make_object_dataset('ycbv') - coarse_model, refiner_model, mesh_db = load_pose_models( + object_ds = make_object_dataset(ds_name_short) + + coarse_model, refiner_model, mesh_db = load_pose_models_cosypose( object_ds, coarse_run_id=cfg.coarse_run_id, refiner_run_id=cfg.refiner_run_id, - n_workers=0, - renderer_type="bullet" + n_workers=cfg.inference.n_workers, + renderer_type=cfg.inference.renderer ) renderer = refiner_model.renderer diff --git a/happypose/pose_estimators/megapose/inference/types.py b/happypose/pose_estimators/megapose/inference/types.py index 74545001..132f5221 100644 --- a/happypose/pose_estimators/megapose/inference/types.py +++ b/happypose/pose_estimators/megapose/inference/types.py @@ -97,6 +97,8 @@ class InferenceConfig: depth_refiner: Optional[str] = None # ['icp', 'teaserpp'] bsz_objects: int = 16 # How many parallel refiners to run bsz_images: int = 288 # How many images to push through coarse model + renderer: str = "panda3d" # ['panda3d', 'pybullet'] + n_workers: int = 1 # How many workers to use in the batch renderer @dataclass diff --git a/happypose/toolbox/renderer/panda3d_batch_renderer.py b/happypose/toolbox/renderer/panda3d_batch_renderer.py index 1bd9a98f..43c4b492 100644 --- a/happypose/toolbox/renderer/panda3d_batch_renderer.py +++ b/happypose/toolbox/renderer/panda3d_batch_renderer.py @@ -133,13 +133,16 @@ def __init__( preload_cache: bool = True, split_objects: bool = False, ): - assert n_workers >= 1 + self._is_closed = False self._object_dataset = asset_dataset self._n_workers = n_workers self._split_objects = split_objects + self._renderers = [] + self._in_queues = [] + self._out_queue = None + assert n_workers >= 1 self._init_renderers(preload_cache) - self._is_closed = False def make_scene_data( self, @@ -340,7 +343,8 @@ def stop(self) -> None: renderer_process.terminate() for queue in self._in_queues: queue.close() - self._out_queue.close() + if self._out_queue is not None: + self._out_queue.close() self._is_closed = True logger.debug("Batch renderer is closed.")