Skip to content

Commit

Permalink
Merge branch 'dev' into low-hanging-fruits
Browse files Browse the repository at this point in the history
  • Loading branch information
nim65s committed Apr 29, 2024
2 parents ff64175 + 888f536 commit e65fa4b
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 677 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/conda-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'

- name: Install happypose
run: pip install -e ".[evaluation]"
run: pip install -e .

- name: Download pre-trained models required for tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pip-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: pip install -U pip

- name: Install happypose
run: pip install ".[cpu,evaluation,pypi]" --extra-index-url https://download.pytorch.org/whl/cpu
run: pip install ".[cpu,pypi]" --extra-index-url https://download.pytorch.org/whl/cpu

- name: Download pre-trained models required for tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/poetry-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
cache: poetry

- name: Install happypose
run: poetry install --with dev -E cpu -E evaluation -E pypi
run: poetry install --with dev -E cpu -E pypi

- name: Download pre-trained models required for tests
run: |
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pip install .[pypi,cpu] --extra-index-url https://download.pytorch.org/whl/cpu

- `cpu`: required to get pytorch CPU from PyPI (don't use this for GPU or with conda)
- `gpu`: required to get pytorch GPU from PyPI (don't use this for CPU or with conda)
- `evaluation`: installs bop_toolkit
- `multiview`: installs cosypose c++ extension
- `pypi`: install pinocchio & opencv from PyPI (don't use this with conda)

Expand Down
18 changes: 3 additions & 15 deletions docs/book/megapose/download_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,11 @@ Megapose can use pretrained detectors from CosyPose, which can be downloaded to

```sh
# hope
python -m happypose.toolbox.utils.download --cosypose_models \
detector-bop-hope-pbr--15246 \
coarse-bop-hope-pbr--225203 \
refiner-bop-hope-pbr--955392

python -m happypose.toolbox.utils.download --cosypose_models detector-bop-hope-pbr--15246
# ycbv

python -m happypose.toolbox.utils.download --cosypose_models \
detector-bop-ycbv-pbr--970850 \
coarse-bop-ycbv-pbr--724183 \
refiner-bop-ycbv-pbr--604090

python -m happypose.toolbox.utils.download --cosypose_models detector-bop-ycbv-pbr--970850
# tless
python -m happypose.toolbox.utils.download --cosypose_models \
detector-bop-tless-pbr--873074 \
coarse-bop-tless-pbr--506801 \
refiner-bop-tless-pbr--233420
python -m happypose.toolbox.utils.download --cosypose_models detector-bop-tless-pbr--873074
```

# Dataset
Expand Down
19 changes: 1 addition & 18 deletions docs/book/megapose/evaluate.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,11 @@

Please make sure you followed the steps relative to the evaluation in the main readme.

## TEASER++

You will first need to install [TEASER++](https://github.com/MIT-SPARK/TEASER-plusplus) if you want to use the depth for MegaPose.
To do so, please run the following commands to install it :

```
# Go to HappyPose root directory
apt install -y cmake libeigen3-dev libboost-all-dev
conda activate happypose
mamba install compilers -c conda-forge
pip install open3d
mkdir /build && cd /build && git clone https://github.com/MIT-SPARK/TEASER-plusplus.git
cd TEASER-plusplus && mkdir build && cd build
cmake -DTEASERPP_PYTHON_VERSION=3.9 .. && make teaserpp_python
cd python && pip install .
```

## Evaluating with Megapose detector
Run a detector part of Megapose pipeline to detect bounding boxes in the image dataset at run-time.

```
python -m happypose.pose_estimators.megapose.scripts.run_full_megapose_eval detector_run_id=bop_pbr coarse_run_id=coarse-rgb-906902141 refiner_run_id=refiner-rgb-653307694 ds_names=[ycbv.bop19,lmo.bop19,tless.bop19,tudl.bop19,icbin.bop19,hb.bop19,itodd.bop19] result_id=detector_1posehyp detection_coarse_types=[["detector","SO3_grid"]] inference.n_pose_hypotheses=1 skip_inference=false run_bop_eval=true
python -m happypose.pose_estimators.megapose.scripts.run_full_megapose_eval detector_run_id=bop_pbr coarse_run_id=coarse-rgb-906902141 refiner_run_id=refiner-rgb-653307694 ds_names=[ycbv.bop19,lmo.bop19,tless.bop19,tudl.bop19,icbin.bop19,hb.bop19,itodd.bop19,hope.bop19] result_id=detector_1posehyp detection_coarse_types=[["detector","SO3_grid"]] inference.n_pose_hypotheses=1 skip_inference=false run_bop_eval=true
```

## Evaluating with external detections
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pip
- pytorch::pytorch==1.11.0
- torchvision==0.12.0
- mkl==2024.0.0
- geckodriver
- firefox
- opencv
Expand Down
5 changes: 3 additions & 2 deletions happypose/pose_estimators/cosypose/cosypose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
SYNT_DS_DIR = LOCAL_DATA_DIR / "synt_datasets"
BOP_DS_DIR = LOCAL_DATA_DIR / "bop_datasets"

BOP_TOOLKIT_DIR = PROJECT_DIR / "deps" / "bop_toolkit_cosypose"
BOP_CHALLENGE_TOOLKIT_DIR = PROJECT_DIR / "deps" / "bop_toolkit_challenge"
# BOP scripts
BOP_POSE_EVAL_SCRIPT_NAME = "eval_bop19_pose.py"
BOP_DETECTION_EVAL_SCRIPT_NAME = "eval_bop22_coco.py"

EXP_DIR = LOCAL_DATA_DIR / "experiments"
RESULTS_DIR = LOCAL_DATA_DIR / "results"
Expand Down
10 changes: 2 additions & 8 deletions happypose/pose_estimators/cosypose/cosypose/datasets/bop.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import json
import pickle
import sys
from pathlib import Path

import numpy as np
import pandas as pd
import torch
from bop_toolkit_lib import inout
from PIL import Image

from happypose.pose_estimators.cosypose.cosypose.config import BOP_TOOLKIT_DIR, MEMORY
from happypose.pose_estimators.cosypose.cosypose.config import MEMORY
from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger
from happypose.toolbox.lib3d.transform import Transform

sys.path.append(str(BOP_TOOLKIT_DIR))
from bop_toolkit_lib import inout

sys.path = sys.path[:-1]


logger = get_logger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,8 @@
ModelNetErrorMeter,
)
from happypose.pose_estimators.megapose.evaluation.runner_utils import format_results
from happypose.pose_estimators.megapose.inference.icp_refiner import ICPRefiner

# Pose estimator
from happypose.pose_estimators.megapose.inference.teaserpp_refiner import (
TeaserppRefiner,
)
from happypose.toolbox.datasets.datasets_cfg import make_object_dataset
from happypose.toolbox.lib3d.rigid_mesh_database import MeshDataBase
from happypose.toolbox.renderer.panda3d_batch_renderer import Panda3dBatchRenderer
Expand Down Expand Up @@ -189,22 +185,7 @@ def run_eval(
# See https://stackoverflow.com/a/53287330
assert cfg.coarse_run_id is not None
assert cfg.refiner_run_id is not None
# TODO (emaitre): This fuction seems to take the wrong parameters. Trying to fix
# this.
"""
(
coarse_model,
refiner_model,
mesh_db,
) = happypose.toolbox.inference.utils.load_pose_models(
coarse_run_id=cfg.coarse_run_id,
refiner_run_id=cfg.refiner_run_id,
n_workers=cfg.n_rendering_workers,
obj_ds_name=obj_ds_name,
urdf_ds_name=urdf_ds_name,
force_panda3d_renderer=True,
)
"""

object_ds = make_object_dataset(obj_ds_name)

coarse_model, refiner_model, mesh_db = load_pose_models(
Expand All @@ -217,8 +198,16 @@ def run_eval(

if cfg.inference.run_depth_refiner:
if cfg.inference.depth_refiner == "icp":
from happypose.pose_estimators.megapose.inference.icp_refiner import (
ICPRefiner,
)

ICPRefiner(mesh_db, renderer)
elif cfg.inference.depth_refiner == "teaserpp":
from happypose.pose_estimators.megapose.inference.teaserpp_refiner import (
TeaserppRefiner,
)

TeaserppRefiner(mesh_db, renderer)
else:
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,46 +173,43 @@ def get_predictions(
"""
predictions_list = defaultdict(list)
for n, data in enumerate(tqdm(self.dataloader)):
if n < 3:
# data is a dict
rgb = data["rgb"]
depth = None
K = data["cameras"].K
gt_detections = data["gt_detections"].cuda()

initial_data = None
if data["initial_data"]:
initial_data = data["initial_data"].cuda()

obs_tensor = ObservationTensor.from_torch_batched(rgb, depth, K)
obs_tensor = obs_tensor.cuda()

# GPU warmup for timing
if n == 0:
with torch.no_grad():
self.run_inference_pipeline(
pose_estimator,
obs_tensor,
gt_detections,
initial_estimates=initial_data,
)

cuda_timer = CudaTimer()
cuda_timer.start()
# data is a dict
rgb = data["rgb"]
depth = None
K = data["cameras"].K
gt_detections = data["gt_detections"].cuda()

initial_data = None
if data["initial_data"]:
initial_data = data["initial_data"].cuda()

obs_tensor = ObservationTensor.from_torch_batched(rgb, depth, K)
obs_tensor = obs_tensor.cuda()

# GPU warmup for timing
if n == 0:
with torch.no_grad():
all_preds = self.run_inference_pipeline(
self.run_inference_pipeline(
pose_estimator,
obs_tensor,
gt_detections,
initial_estimates=initial_data,
)
cuda_timer.end()
cuda_timer.elapsed()

for k, v in all_preds.items():
predictions_list[k].append(v)
else:
break
cuda_timer = CudaTimer()
cuda_timer.start()
with torch.no_grad():
all_preds = self.run_inference_pipeline(
pose_estimator,
obs_tensor,
gt_detections,
initial_estimates=initial_data,
)
cuda_timer.end()
cuda_timer.elapsed()

for k, v in all_preds.items():
predictions_list[k].append(v)

# Concatenate the lists of PandasTensorCollections
predictions = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import argparse
import os
import shutil
import subprocess
import sys
from pathlib import Path

import torch
from bop_toolkit_lib import inout
from tqdm import tqdm

from happypose.pose_estimators.cosypose.cosypose.config import PROJECT_DIR, RESULTS_DIR

TOOLKIT_DIR = Path(PROJECT_DIR / "deps" / "bop_toolkit_challenge")
EVAL_SCRIPT_PATH = TOOLKIT_DIR / "scripts/eval_bop19.py"
DUMMY_EVAL_SCRIPT_PATH = TOOLKIT_DIR / "scripts/eval_bop19_dummy.py"

sys.path.append(TOOLKIT_DIR.as_posix())
from bop_toolkit_lib import inout # noqa

# from bop_toolkit_lib.config import results_path as BOP_RESULTS_PATH
from happypose.pose_estimators.cosypose.cosypose.config import (
BOP_POSE_EVAL_SCRIPT_NAME,
RESULTS_DIR,
)


def main():
Expand Down Expand Up @@ -47,7 +39,7 @@ def run_evaluation(args):
)

if not args.convert_only:
run_bop_evaluation(csv_path, dummy=args.dummy)
run_bop_evaluation(csv_path)
return csv_path


Expand Down Expand Up @@ -82,25 +74,15 @@ def convert_results(results_path, out_csv_path, method):
return out_csv_path


def run_bop_evaluation(filename, dummy=False):
myenv = os.environ.copy()
myenv["PYTHONPATH"] = TOOLKIT_DIR.as_posix()
myenv["COSYPOSE_DIR"] = PROJECT_DIR.as_posix()
if dummy:
script_path = DUMMY_EVAL_SCRIPT_PATH
else:
script_path = EVAL_SCRIPT_PATH
def run_bop_evaluation(filename):
subprocess.call(
[
"python",
script_path.as_posix(),
BOP_POSE_EVAL_SCRIPT_NAME,
"--renderer_type",
"python",
"--result_filenames",
filename,
],
env=myenv,
cwd=TOOLKIT_DIR.as_posix(),
)


Expand Down
Loading

0 comments on commit e65fa4b

Please sign in to comment.