Skip to content

Commit

Permalink
fix hardcoded ycbv, some issues with panda batch and cosy eval doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kzorina committed Oct 25, 2024
1 parent 10324d5 commit 838cfb4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
14 changes: 10 additions & 4 deletions docs/book/cosypose/evaluate.md
Original file line number Diff line number Diff line change
@@ -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"].
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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:
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions happypose/pose_estimators/megapose/inference/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions happypose/toolbox/renderer/panda3d_batch_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.")

Expand Down

0 comments on commit 838cfb4

Please sign in to comment.