Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

132 example data and scripts not unified #139

Merged
merged 19 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
18816a3
Add hope from downloadable datasets
MedericFourmy Feb 19, 2024
12858f4
Refacor run_inference_on_example
MedericFourmy Feb 19, 2024
82469a8
Unfiformize inference examples and tests between mega/cosy pose, refa…
MedericFourmy Feb 20, 2024
7b7dba8
Adapt inference examples and tests to new barbecue-sauce structure
MedericFourmy Feb 20, 2024
f884b64
ObservationTensor.to(device) function
MedericFourmy Feb 20, 2024
b9e59bf
Allow running detector in inference example scripts
MedericFourmy Feb 20, 2024
e132c2a
Update documentation and CI with barbecue-sauce example
MedericFourmy Feb 20, 2024
353b6a0
Merge branch 'dev' into 132-example-data-and-scripts-not-unified
MedericFourmy Feb 20, 2024
5f7fff9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2024
8457d58
Merge branch 'dev' into 132-example-data-and-scripts-not-unified
MedericFourmy Feb 21, 2024
e9fa82d
add tensor conversion to Transform
MedericFourmy Feb 22, 2024
64b4896
Fix cosy wrapper default param
MedericFourmy Feb 26, 2024
4cb0305
Fix urdf conversion script
MedericFourmy Feb 26, 2024
4b9a9de
Fix np warning
MedericFourmy Feb 26, 2024
be01907
Panda3dObjectData TWO input attempt construct Transform
MedericFourmy Feb 27, 2024
ba99eb5
Bullet scene renderer accepts OneUrdfDataset
MedericFourmy Feb 27, 2024
e0999c7
make_object_dataset RigidObjectDataset accepts "tless" -> "tless.cad"
MedericFourmy Feb 27, 2024
eb0b8d0
Fix multiview gif viz
MedericFourmy Feb 27, 2024
902416e
reraise caught exception
MedericFourmy Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import json
from pathlib import Path
from typing import Union


class BOPObjectDataset:
def __init__(self, ds_dir):
def __init__(self, ds_dir, label_format: Union[None, str] = None):
ds_dir = Path(ds_dir)
infos_file = ds_dir / "models_info.json"
infos = json.loads(infos_file.read_text())
objects = []
for obj_id, bop_info in infos.items():
obj_id = int(obj_id)
obj_label = f"obj_{obj_id:06d}"
mesh_path = (ds_dir / obj_label).with_suffix(".ply").as_posix()
label = f"obj_{obj_id:06d}"
mesh_path = (ds_dir / label).with_suffix(".ply").as_posix()
if label_format is not None:
label = label_format.format(label=label)

Check warning on line 17 in happypose/pose_estimators/cosypose/cosypose/datasets/bop_object_datasets.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/bop_object_datasets.py#L14-L17

Added lines #L14 - L17 were not covered by tests
obj = {
"label": obj_label,
"label": label,
"category": None,
"mesh_path": mesh_path,
"mesh_units": "mm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@
return {label: obj["n_sym"] for label, obj in self.infos.items()}

def select(self, labels):
ids = [self.label_to_id[label] for label in labels]
try:
ids = [self.label_to_id[label] for label in labels]
except KeyError as e:
print(e)
print("self.label_to_id.keys(): ", list(self.label_to_id.keys()))

Check warning on line 99 in happypose/pose_estimators/cosypose/cosypose/lib3d/rigid_mesh_database.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/lib3d/rigid_mesh_database.py#L95-L99

Added lines #L95 - L99 were not covered by tests
MedericFourmy marked this conversation as resolved.
Show resolved Hide resolved
return Meshes(
infos=[self.infos[label] for label in labels],
labels=self.labels[ids],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
self.away_transform = (0, 0, 1000), (0, 0, 0, 1)

def _load_body(self, label):
ds_idx = np.where(self.urdf_ds.index["label"] == label)[0].item()
object_infos = self.urdf_ds[ds_idx].to_dict()
ds_idx = np.where(self.urdf_ds.index["label"] == label)[0]
if len(ds_idx) == 0:
raise ValueError(f'Label {label} not in {self.urdf_ds.index["label"]}')

Check warning on line 20 in happypose/pose_estimators/cosypose/cosypose/simulator/caching.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/simulator/caching.py#L20

Added line #L20 was not covered by tests
object_infos = self.urdf_ds[ds_idx.item()].to_dict()
body = Body.load(
object_infos["urdf_path"],
scale=object_infos["scale"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
{"K": K, "TWC": TWC, "resolution": (w, h)},
)
renders = renderer.render_scene(list_objects, list_cameras)
images = np.stack([render["rgb"] for render in renders])
images = np.stack([render.rgb for render in renders])

Check warning on line 155 in happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py#L155

Added line #L155 was not covered by tests
if gui:
time.sleep(100)
renderer.disconnect()
Expand Down Expand Up @@ -201,7 +201,7 @@
"TWO": preds_with_colors.poses[n].cpu().numpy(),
}
list_objects.append(obj)
rgb_rendered = renderer.render_scene(list_objects, [camera])[0]["rgb"]
rgb_rendered = renderer.render_scene(list_objects, [camera])[0].rgb

Check warning on line 204 in happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py#L204

Added line #L204 was not covered by tests
return rgb_rendered


Expand All @@ -212,7 +212,7 @@
obj["color"] = colormap_rgb[obj["label"]]
obj["TWO"] = np.linalg.inv(TWC) @ obj["TWO"]
camera["TWC"] = np.eye(4)
rgb_rendered = renderer.render_scene(objects, [camera])[0]["rgb"]
rgb_rendered = renderer.render_scene(objects, [camera])[0].rgb

Check warning on line 215 in happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py#L215

Added line #L215 was not covered by tests
return rgb_rendered


Expand Down
7 changes: 6 additions & 1 deletion happypose/toolbox/datasets/datasets_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@
def make_object_dataset(ds_name: str) -> RigidObjectDataset:
# BOP original models

if ds_name == "tless.cad":
if ds_name == "tless":
ds: RigidObjectDataset = BOPObjectDataset(

Check warning on line 253 in happypose/toolbox/datasets/datasets_cfg.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/datasets/datasets_cfg.py#L252-L253

Added lines #L252 - L253 were not covered by tests
BOP_DS_DIR / "tless/models_cad",
label_format="tless-{label}",
)
elif ds_name == "tless.cad":

Check warning on line 257 in happypose/toolbox/datasets/datasets_cfg.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/datasets/datasets_cfg.py#L257

Added line #L257 was not covered by tests
ds: RigidObjectDataset = BOPObjectDataset(
BOP_DS_DIR / "tless/models_cad",
label_format="tless-{label}",
Expand Down
5 changes: 3 additions & 2 deletions happypose/toolbox/renderer/bullet_scene_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# from happypose.toolbox.datasets.datasets_cfg import UrdfDataset
from happypose.pose_estimators.cosypose.cosypose.datasets.urdf_dataset import (
OneUrdfDataset,
UrdfDataset,
)

Expand All @@ -31,7 +32,7 @@ def __init__(
gpu_renderer=True,
gui=False,
):
if isinstance(asset_dataset, UrdfDataset):
if isinstance(asset_dataset, (UrdfDataset, OneUrdfDataset)):
self.urdf_ds = asset_dataset
elif isinstance(asset_dataset, RigidObjectDataset):
# Build urdfs files from RigidObjectDataset
Expand All @@ -43,7 +44,7 @@ def __init__(
self.urdf_ds.index["scale"] = asset_dataset[0].scale
else:
raise TypeError(
f"asset_dataset of type {type(asset_dataset)} should be either UrdfDataset or RigidObjectDataset"
f"asset_dataset of type {type(asset_dataset)} should be either OneUrdfDataset/UrdfDataset or RigidObjectDataset"
)
self.connect(gpu_renderer=gpu_renderer, gui=gui)
self.body_cache = BodyCache(self.urdf_ds, self.client_id)
Expand Down
4 changes: 4 additions & 0 deletions happypose/toolbox/renderer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
scale: float = 1
positioning_function: Optional[NodeFunction] = None

def __post_init__(self):
if not isinstance(self.TWO, Transform):
self.TWO = Transform(self.TWO)

Check warning on line 165 in happypose/toolbox/renderer/types.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/renderer/types.py#L165

Added line #L165 was not covered by tests

def set_node_material_and_transparency(
self,
node_path: p3d.core.NodePath,
Expand Down
Loading