Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 25, 2024
1 parent 3b6259d commit 400d14d
Show file tree
Hide file tree
Showing 22 changed files with 215 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import random
from dataclasses import dataclass

Check warning on line 2 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L2

Added line #L2 was not covered by tests
from typing import List, Optional

import numpy as np
import torch
Expand Down Expand Up @@ -29,20 +28,18 @@
PillowSharpness,
VOCBackgroundAugmentation,
)
from happypose.toolbox.datasets.augmentations import (

Check warning on line 31 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L31

Added line #L31 was not covered by tests
SceneObservationAugmentation as SceneObsAug,
)

# HappyPose
from happypose.toolbox.datasets.scene_dataset import (

Check warning on line 36 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L36

Added line #L36 was not covered by tests
IterableSceneDataset,
ObjectData,
SceneDataset,
SceneObservation,
)

from happypose.toolbox.datasets.augmentations import (
SceneObservationAugmentation as SceneObsAug,
)

from happypose.toolbox.datasets.scene_dataset_wrappers import remove_invisible_objects

Check warning on line 41 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L41

Added line #L41 was not covered by tests

# from happypose.toolbox.datasets.scene_dataset_wrappers import VisibilityWrapper
"""

Check warning on line 44 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L44

Added line #L44 was not covered by tests
from .augmentations import (
Expand All @@ -58,6 +55,7 @@
from .wrappers.visibility_wrapper import VisibilityWrapper
"""


def collate_fn(batch):
print("inside collate fn")
rgbs, targets = zip(*batch)
Expand Down Expand Up @@ -92,7 +90,8 @@ def collate_fn(batch):
# Return the batch data as a dictionary
return {"rgbs": rgbs, "targets": target}

Check warning on line 91 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L91

Added line #L91 was not covered by tests

#TODO : Double check on types and add format documentation

# TODO : Double check on types and add format documentation
@dataclass
class DetectionData:

Check warning on line 96 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L95-L96

Added lines #L95 - L96 were not covered by tests
"""rgb: (h, w, 3) uint8
Expand Down Expand Up @@ -135,6 +134,7 @@ def pin_memory(self) -> "BatchDetectionData":
self.depths = self.depths.pin_memory()
return self

Check warning on line 135 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L128-L135

Added lines #L128 - L135 were not covered by tests


class DetectionDataset(torch.utils.data.IterableDataset):

Check warning on line 138 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L138

Added line #L138 was not covered by tests
def __init__(
self,
Expand Down Expand Up @@ -168,13 +168,14 @@ def __init__(
SceneObsAug(PillowSharpness(factor_interval=(0.0, 50.0)), p=0.3),
SceneObsAug(PillowContrast(factor_interval=(0.2, 50.0)), p=0.3),
SceneObsAug(PillowBrightness(factor_interval=(0.1, 6.0)), p=0.5),
SceneObsAug(PillowColor(factor_interval=(0.0, 20.0)), p=0.3),]
SceneObsAug(PillowColor(factor_interval=(0.0, 20.0)), p=0.3),
]
)

]

self.label_to_category_id = label_to_category_id
self.min_area = min_area

Check warning on line 177 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L176-L177

Added lines #L176 - L177 were not covered by tests

"""

Check warning on line 179 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L179

Added line #L179 was not covered by tests
def collate_fn(self, list_data: List[DetectionData]) -> BatchDetectionData:
batch_data = BatchDetectionData(
Expand All @@ -194,19 +195,19 @@ def collate_fn(self, list_data: List[DetectionData]) -> BatchDetectionData:
return batch_data
"""

def make_data_from_obs(self, obs: SceneObservation, idx):

obs = remove_invisible_objects(obs)

Check warning on line 200 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L199-L200

Added lines #L199 - L200 were not covered by tests

obs = self.resize_augmentation(obs)

Check warning on line 202 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L202

Added line #L202 was not covered by tests

for aug in self.background_augmentations:
obs = aug(obs)

Check warning on line 205 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L204-L205

Added lines #L204 - L205 were not covered by tests

if self.rgb_augmentations and random.random() < 0.8:
for aug in self.rgb_augmentations:
obs = aug(obs)

Check warning on line 209 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L207-L209

Added lines #L207 - L209 were not covered by tests

assert obs.object_datas is not None
assert obs.rgb is not None
assert obs.camera_data is not None
Expand All @@ -226,13 +227,13 @@ def make_data_from_obs(self, obs: SceneObservation, idx):
if obs.binary_masks is not None:
binary_mask = torch.tensor(obs.binary_masks[obj_data.unique_id]).float()
masks.append(binary_mask)

Check warning on line 229 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L225-L229

Added lines #L225 - L229 were not covered by tests

if obs.segmentation is not None:
binary_mask = np.zeros_like(obs.segmentation, dtype=np.bool_)
binary_mask[obs.segmentation == obj_data.unique_id] = 1
binary_mask = torch.as_tensor(binary_mask).float()
masks.append(binary_mask)

Check warning on line 235 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L231-L235

Added lines #L231 - L235 were not covered by tests

masks = np.array(masks)
masks = masks == obj_ids[:, None, None]

Check warning on line 238 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L237-L238

Added lines #L237 - L238 were not covered by tests

Expand All @@ -258,17 +259,15 @@ def make_data_from_obs(self, obs: SceneObservation, idx):
target["image_id"] = image_id
target["area"] = area
target["iscrowd"] = iscrowd

Check warning on line 261 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L254-L261

Added lines #L254 - L261 were not covered by tests

return rgb, target

Check warning on line 263 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L263

Added line #L263 was not covered by tests



def __getitem__(self, index: int):
assert isinstance(self.scene_ds, SceneDataset)
obs = self.scene_ds[index]
return self.make_data_from_obs(obs, index)

Check warning on line 268 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L265-L268

Added lines #L265 - L268 were not covered by tests
# def find_valid_data(self, iterator: Iterator[SceneObservation]) -> PoseData:

# def find_valid_data(self, iterator: Iterator[SceneObservation]) -> PoseData:
def find_valid_data(self, iterator):
n_attempts = 0
for idx, obs in enumerate(iterator):
Expand All @@ -279,17 +278,13 @@ def find_valid_data(self, iterator):
if n_attempts > 200:
msg = "Cannot find valid image in the dataset"
raise ValueError(msg)

Check warning on line 280 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L271-L280

Added lines #L271 - L280 were not covered by tests

def __iter__(self):
assert isinstance(self.scene_ds, IterableSceneDataset)
iterator = iter(self.scene_ds)
while True:
yield self.find_valid_data(iterator)

Check warning on line 286 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L282-L286

Added lines #L282 - L286 were not covered by tests






def __init___old(

Check warning on line 288 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L288

Added line #L288 was not covered by tests
self,
scene_ds,
Expand Down Expand Up @@ -322,10 +317,7 @@ def __init___old(
self.label_to_category_id = label_to_category_id
self.min_area = min_area



def get_data_old(self, idx):

print("I am in get_data")

Check warning on line 321 in happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/detection_dataset.py#L320-L321

Added lines #L320 - L321 were not covered by tests
rgb, mask, state = self.scene_ds[idx]

Expand Down Expand Up @@ -393,4 +385,3 @@ def __getitem__old(self, index):
try_index = random.randint(0, len(self.scene_ds) - 1)
n_attempts += 1
return im, target

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
CameraData,
ObjectData,
ObservationInfos,
SceneDataset,
SceneObservation,
)
from happypose.toolbox.lib3d.transform import Transform

Check warning on line 19 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L19

Added line #L19 was not covered by tests
Expand Down Expand Up @@ -82,33 +81,33 @@ def __getitem__(self, idx):
if obj["id_in_segm"] in mask_uniqs:
obj["bbox"] = dets_gt[obj["id_in_segm"]].numpy()
obj_data = ObjectData(

Check warning on line 83 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L83

Added line #L83 was not covered by tests
label= obj['name'],
TWO=Transform(obj['TWO']),
unique_id=obj['body_id'],
bbox_modal=obj['bbox']
label=obj["name"],
TWO=Transform(obj["TWO"]),
unique_id=obj["body_id"],
bbox_modal=obj["bbox"],
)
else:
obj_data = ObjectData(

Check warning on line 90 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L90

Added line #L90 was not covered by tests
label= obj['name'],
TWO=Transform(obj['TWO']),
unique_id=obj['body_id']
label=obj["name"],
TWO=Transform(obj["TWO"]),
unique_id=obj["body_id"],
)
object_datas.append(obj_data)

Check warning on line 95 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L95

Added line #L95 was not covered by tests

state = {
"camera": cam,
"objects": objects,
"frame_info": self.frame_index.iloc[idx].to_dict(),
}
image_infos = ObservationInfos(

Check warning on line 102 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L102

Added line #L102 was not covered by tests
scene_id=self.frame_index.iloc[idx].to_dict()['scene_id'],
view_id=self.frame_index.iloc[idx].to_dict()['view_id'])

scene_id=self.frame_index.iloc[idx].to_dict()["scene_id"],
view_id=self.frame_index.iloc[idx].to_dict()["view_id"],
)

cam = CameraData(

Check warning on line 107 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L107

Added line #L107 was not covered by tests
K=cam["K"],
resolution=cam["resolution"],
TWC=Transform(cam["TWC"]))

K=cam["K"], resolution=cam["resolution"], TWC=Transform(cam["TWC"])
)

observation = SceneObservation(

Check warning on line 111 in happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/datasets/synthetic_dataset.py#L111

Added line #L111 was not covered by tests
rgb=rgb.numpy().astype(np.uint8),
segmentation=mask.numpy().astype(np.uint32),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ def run_inference_pipeline(
"""
if self.inference_cfg['detection_type'] == "gt":
if self.inference_cfg["detection_type"] == "gt":

Check warning on line 97 in happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py#L97

Added line #L97 was not covered by tests
detections = gt_detections
run_detector = False
elif self.inference_cfg['detection_type'] == "detector":
elif self.inference_cfg["detection_type"] == "detector":

Check warning on line 100 in happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py#L100

Added line #L100 was not covered by tests
detections = None
run_detector = True
else:
msg = f"Unknown detection type {self.inference_cfg['detection_type']}"

Check warning on line 104 in happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py#L104

Added line #L104 was not covered by tests
raise ValueError(msg)

coarse_estimates = None
if self.inference_cfg['coarse_estimation_type'] == "external":
if self.inference_cfg["coarse_estimation_type"] == "external":

Check warning on line 108 in happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py#L108

Added line #L108 was not covered by tests
# TODO (ylabbe): This is hacky, clean this for modelnet eval.
coarse_estimates = initial_estimates
coarse_estimates = happypose.toolbox.inference.utils.add_instance_id(
Expand Down Expand Up @@ -144,7 +144,7 @@ def run_inference_pipeline(
"coarse": extra_data["coarse"]["preds"],
}

if self.inference_cfg['run_depth_refiner']:
if self.inference_cfg["run_depth_refiner"]:

Check warning on line 147 in happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/prediction_runner.py#L147

Added line #L147 was not covered by tests
all_preds["depth_refiner"] = extra_data["depth_refiner"]["preds"]

# Remove any mask tensors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def run_pred_eval(pred_runner, pred_kwargs, eval_runner, eval_preds=None):
all_predictions = {}
for pred_prefix, pred_kwargs_n in pred_kwargs.items():
pose_predictor = pred_kwargs_n['pose_predictor']
pose_predictor = pred_kwargs_n["pose_predictor"]
preds = pred_runner.get_predictions(pose_predictor)

Check warning on line 18 in happypose/pose_estimators/cosypose/cosypose/evaluation/runner_utils.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/runner_utils.py#L17-L18

Added lines #L17 - L18 were not covered by tests
for preds_name, preds_n in preds.items():
all_predictions[f"{pred_prefix}/{preds_name}"] = preds_n
Expand Down
2 changes: 1 addition & 1 deletion happypose/pose_estimators/cosypose/cosypose/models/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def forward(self, images, K, labels, TCO, n_iterations=1):
K_crop=K_crop,
boxes_rend=boxes_rend,
boxes_crop=boxes_crop,
model_outputs=model_outputs
model_outputs=model_outputs,
)

TCO_input = TCO_output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
RESULTS_DIR,
)
from happypose.pose_estimators.cosypose.cosypose.datasets.bop import remap_bop_targets
from happypose.toolbox.datasets.datasets_cfg import (
make_object_dataset,
make_scene_dataset,
)
from happypose.pose_estimators.cosypose.cosypose.datasets.samplers import ListSampler
from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import (
MultiViewWrapper,
Expand Down Expand Up @@ -61,6 +57,10 @@
init_distributed_mode,
)
from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger
from happypose.toolbox.datasets.datasets_cfg import (

Check warning on line 60 in happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py#L60

Added line #L60 was not covered by tests
make_object_dataset,
make_scene_dataset,
)
from happypose.toolbox.lib3d.transform import Transform
from happypose.toolbox.renderer.bullet_batch_renderer import BulletBatchRenderer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def run_inference(
rgb, depth, camera_data = load_observation_example(example_dir, load_depth=True)
# TODO: cosypose forward does not work if depth is loaded detection
# contrary to megapose
observation = ObservationTensor.from_numpy(rgb, depth=None, K=camera_data.K).to(device)
observation = ObservationTensor.from_numpy(rgb, depth=None, K=camera_data.K).to(

Check warning on line 88 in happypose/pose_estimators/cosypose/cosypose/scripts/run_inference_on_example.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_inference_on_example.py#L88

Added line #L88 was not covered by tests
device
)

# Load models
pose_estimator = setup_pose_estimator(args.dataset, object_dataset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@


import warnings

Check warning on line 13 in happypose/pose_estimators/cosypose/cosypose/scripts/run_pose_training.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_pose_training.py#L13

Added line #L13 was not covered by tests

warnings.filterwarnings("ignore")

Check warning on line 15 in happypose/pose_estimators/cosypose/cosypose/scripts/run_pose_training.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_pose_training.py#L15

Added line #L15 was not covered by tests


def make_cfg(args):
cfg = argparse.ArgumentParser("").parse_args([])
if args.config:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def h_pose(model, mesh_db, data, meters, cfg, n_iterations=1, input_generator="f
TCO_pred = iter_outputs.TCO_output
model_outputs = iter_outputs.model_outputs

Check warning on line 69 in happypose/pose_estimators/cosypose/cosypose/training/pose_forward_loss.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/training/pose_forward_loss.py#L66-L69

Added lines #L66 - L69 were not covered by tests


if cfg.loss_disentangled:
if cfg.n_pose_dims == 9:
loss_fn = loss_refiner_CO_disentangled
Expand Down
Loading

0 comments on commit 400d14d

Please sign in to comment.