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

[pre-commit.ci] pre-commit autoupdate #204

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
hooks:
- id: ruff
args:
Expand Down
6 changes: 3 additions & 3 deletions happypose/pose_estimators/cosypose/cosypose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
LOCAL_DATA_DIR = Path(
os.environ.get("HAPPYPOSE_DATA_DIR", Path(PROJECT_DIR) / "local_data"),
)
assert (
LOCAL_DATA_DIR.exists()
), "Did you forget to set env variable 'HAPPYPOSE_DATA_DIR'?"
assert LOCAL_DATA_DIR.exists(), (
"Did you forget to set env variable 'HAPPYPOSE_DATA_DIR'?"
)
TEST_DATA_DIR = LOCAL_DATA_DIR
DASK_LOGS_DIR = LOCAL_DATA_DIR / "dasklogs"
SYNT_DS_DIR = LOCAL_DATA_DIR / "synt_datasets"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_predictions(
depth = None
if self.load_depth:
depth = data["depth"].cuda().float()
logger.debug(f"{'-'*80}")
logger.debug(f"{'-' * 80}")
logger.debug(f"Predictions on {data['im_infos']}")

def get_preds():
Expand Down Expand Up @@ -155,7 +155,7 @@ def get_preds():
f"Full predictions: {n_dets} detections + pose estimation "
f"in {duration:.3f} s",
)
logger.debug(f"{'-'*80}")
logger.debug(f"{'-' * 80}")
return this_batch_detections, all_preds, duration

# Run once without measuring timing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_predictions(
view_ids = np.unique(gt_detections.infos["view_id"])
group_id = np.unique(gt_detections.infos["group_id"])
n_gt_dets = len(gt_detections)
logger.debug(f"{'-'*80}")
logger.debug(f"{'-' * 80}")
logger.debug(f"Scene: {scene_id}")
logger.debug(f"Views: {view_ids}")
logger.debug(f"Group: {group_id}")
Expand Down Expand Up @@ -163,7 +163,7 @@ def get_predictions(
candidates,
cameras,
)
logger.debug(f"{'-'*80}")
logger.debug(f"{'-' * 80}")

for k, v in sv_preds.items():
predictions[k].append(v.cpu())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def format_results(predictions, eval_metrics, eval_dfs, print_metrics=True):
df = defaultdict(list)
summary_txt = ""
for k, v in eval_metrics.items():
summary_txt += f"\n{k}\n{'-'*80}\n"
summary_txt += f"\n{k}\n{'-' * 80}\n"
for k_, v_ in v.items():
summary[f"{k}/{k_}"] = v_
df["method"].append(k)
df["metric"].append(k_)
df["value"].append(v_)
summary_txt += f"{k}/{k_}: {v_}\n"
summary_txt += f"{'-'*80}"
summary_txt += f"{'-' * 80}"
if print_metrics:
logger.info(summary_txt)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def run_inference_pipeline(

if coarse_estimates is None:
assert detections is not None or run_detector, (
"You must " "either pass in `detections` or set run_detector=True"
"You must either pass in `detections` or set run_detector=True"
)
if detections is None and run_detector:
start_time = time.time()
Expand Down
8 changes: 4 additions & 4 deletions happypose/pose_estimators/cosypose/cosypose/models/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def forward(self, images, K, labels, TCO, n_iterations=1):

TCO_output = self.update_pose(TCO_input, K_crop, model_outputs["pose"])

outputs[f"iteration={n+1}"] = {
outputs[f"iteration={n + 1}"] = {
"TCO_input": TCO_input,
"TCO_output": TCO_output,
"K_crop": K_crop,
Expand All @@ -170,7 +170,7 @@ def forward(self, images, K, labels, TCO, n_iterations=1):
"boxes_crop": boxes_crop,
}

outputs[f"iteration={n+1}"] = PosePredictorOutputCosypose(
outputs[f"iteration={n + 1}"] = PosePredictorOutputCosypose(
renders=renders.rgbs,
images_crop=images_crop,
TCO_input=TCO_input,
Expand All @@ -186,13 +186,13 @@ def forward(self, images, K, labels, TCO, n_iterations=1):
TCO_input = TCO_output

if self.debug:
self.tmp_debug.update(outputs[f"iteration={n+1}"])
self.tmp_debug.update(outputs[f"iteration={n + 1}"])
self.tmp_debug.update(
images=images,
images_crop=images_crop,
renders=renders.rgbs,
)
path = DEBUG_DATA_DIR / f"debug_iter={n+1}.pth.tar"
path = DEBUG_DATA_DIR / f"debug_iter={n + 1}.pth.tar"
logger.info(f"Wrote debug data: {path}")
torch.save(self.tmp_debug, path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def main():
proc.join()

for _ in range(10):
print(f"{'-'*80}")
print(f"{'-' * 80}")

for ds_name, (cfg, _) in processes.items():
results_dir = (
LOCAL_DATA_DIR / "bop_eval_outputs" / cfg.csv_path.with_suffix("").name
)
scores_path = results_dir / "scores_bop19.json"
print(f"{'-'*80}")
print(f"{'-' * 80}")
print(f"{ds_name}: {scores_path}")
print(scores_path.read_text())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def load_pose_models(coarse_run_id, refiner_run_id=None, n_workers=8):


def run_inference(args):
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
for k, v in args.__dict__.items():
logger.info(f"{k}: {v}")
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")

scene_ds = make_scene_dataset(args.ds_name, n_frames=args.n_frames)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,7 @@ def main():
f"CLASS/AUC/objects/mean"
)
k_4 = (
f"{det_key}/ba_output+all_cand/ADD-S_ntop=1_matching="
f"CLASS/AUC/objects/mean"
f"{det_key}/ba_output+all_cand/ADD-S_ntop=1_matching=CLASS/AUC/objects/mean"
)
metrics_to_print.update(
{
Expand Down Expand Up @@ -595,9 +594,9 @@ def main():
for k, v in metrics_to_print.items():
if k in full_summary:
summary_txt += f"\n{v}: {full_summary[k]}"
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
logger.info(summary_txt)
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")

torch.save(results, save_dir / "results.pth.tar")
(save_dir / "summary.txt").write_text(summary_txt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ def main():
if "cosypose" in logger.name:
logger.setLevel(logging.DEBUG)

logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
for k, v in args.__dict__.items():
logger.info(f"{k}: {v}")
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")

scenario_dir = LOCAL_DATA_DIR / "custom_scenarios" / args.scenario

candidates = read_csv_candidates(scenario_dir / "candidates.csv").float().cuda()
candidates.infos["group_id"] = 0
scene_ids = np.unique(candidates.infos["scene_id"])
assert (
len(scene_ids) == 1
), "Please only provide 6D pose estimations that correspond to the same scene."
assert len(scene_ids) == 1, (
"Please only provide 6D pose estimations that correspond to the same scene."
)
scene_id = scene_ids.item()
view_ids = np.unique(candidates.infos["view_id"])
n_views = len(view_ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def get_meters(scene_ds):


def run_detection_eval(args, detector=None):
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
for k, v in args.__dict__.items():
logger.info(f"{k}: {v}")
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")

scene_ds = make_scene_dataset(args.ds_name, n_frames=args.n_frames)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def main():
data_dir = os.getenv("HAPPYPOSE_DATA_DIR")
assert data_dir, "Set HAPPYPOSE_DATA_DIR env variable"
example_dir = Path(data_dir) / "examples" / args.example_name
assert (
example_dir.exists()
), "Example {args.example_name} not available, follow download instructions"
assert example_dir.exists(), (
"Example {args.example_name} not available, follow download instructions"
)
# dataset_to_use = args.dataset # hope/tless/ycbv

# Load data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, urdf_ds, client_id):
def _load_body(self, label):
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"]}')
raise ValueError(f"Label {label} not in {self.urdf_ds.index['label']}")
object_infos = self.urdf_ds[ds_idx.item()].to_dict()
body = Body.load(
object_infos["urdf_path"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def h_pose(model, mesh_db, data, meters, cfg, n_iterations=1, input_generator="f

losses_TCO_iter = []
for n in range(n_iterations):
iter_outputs = outputs[f"iteration={n+1}"]
iter_outputs = outputs[f"iteration={n + 1}"]
K_crop = iter_outputs.K_crop
TCO_input = iter_outputs.TCO_input
TCO_pred = iter_outputs.TCO_output
Expand Down Expand Up @@ -90,7 +90,7 @@ def h_pose(model, mesh_db, data, meters, cfg, n_iterations=1, input_generator="f
points,
)

meters[f"loss_TCO-iter={n+1}"].add(loss_TCO_iter.mean().item())
meters[f"loss_TCO-iter={n + 1}"].add(loss_TCO_iter.mean().item())
losses_TCO_iter.append(loss_TCO_iter)

loss_TCO = torch.cat(losses_TCO_iter).mean()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def train_detector(args):
args = check_update_config(args)
args.save_dir = EXP_DIR / args.run_id

logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
for k, v in args.__dict__.items():
logger.info(f"{k}: {v}")
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
# Initialize distributed
device = torch.cuda.current_device()
init_distributed_mode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def train_pose(args):
args.save_dir = EXP_DIR / args.run_id
args = check_update_config(args)

logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")
for k, v in args.__dict__.items():
logger.info(f"{k}: {v}")
logger.info(f"{'-'*80}")
logger.info(f"{'-' * 80}")

# Initialize distributed
device = torch.cuda.current_device()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def delete_tensor(self, name):
del self._tensors[name]

def __repr__(self):
s = self.__class__.__name__ + "(" "\n"
s = self.__class__.__name__ + "(\n"
for k, t in self._tensors.items():
s += f" {k}: {t.shape} {t.dtype} {t.device},\n"
s += ")"
Expand Down Expand Up @@ -131,10 +131,10 @@ def clone(self):
return PandasTensorCollection(self.infos.copy(), **tensors)

def __repr__(self):
s = self.__class__.__name__ + "(" "\n"
s = self.__class__.__name__ + "(\n"
for k, t in self._tensors.items():
s += f" {k}: {t.shape} {t.dtype} {t.device},\n"
s += f"{'-'*40}\n"
s += f"{'-' * 40}\n"
s += " infos:\n" + self.infos.__repr__() + "\n"
s += ")"
return s
Expand Down
6 changes: 3 additions & 3 deletions happypose/pose_estimators/megapose/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
LOCAL_DATA_DIR = Path(
os.environ.get("HAPPYPOSE_DATA_DIR", Path(PROJECT_DIR) / "local_data"),
)
assert (
LOCAL_DATA_DIR.exists()
), "Did you forget to set env variable 'HAPPYPOSE_DATA_DIR'?"
assert LOCAL_DATA_DIR.exists(), (
"Did you forget to set env variable 'HAPPYPOSE_DATA_DIR'?"
)
BOP_DS_DIR = LOCAL_DATA_DIR / "bop_datasets"
NB_DATA_DIR = LOCAL_DATA_DIR / "notebook_data"
SHAPENET_DIR = LOCAL_DATA_DIR / "shapenetcorev2"
Expand Down
4 changes: 2 additions & 2 deletions happypose/pose_estimators/megapose/evaluation/runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def format_results(predictions, eval_metrics, eval_dfs, print_metrics=True):
df = defaultdict(list)
summary_txt = ""
for k, v in eval_metrics.items():
summary_txt += f"\n{k}\n{'-'*80}\n"
summary_txt += f"\n{k}\n{'-' * 80}\n"
for k_, v_ in v.items():
summary[f"{k}/{k_}"] = v_
df["method"].append(k)
df["metric"].append(k_)
df["value"].append(v_)
summary_txt += f"{k}/{k_}: {v_}\n"
summary_txt += f"{'-'*80}"
summary_txt += f"{'-' * 80}"
if print_metrics:
logger.info(summary_txt)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def run_inference_pipeline(

if coarse_estimates is None:
assert detections is not None or run_detector, (
"You must " "either pass in `detections` or set run_detector=True"
"You must either pass in `detections` or set run_detector=True"
)
if detections is None and run_detector:
start_time = time.time()
Expand All @@ -576,9 +576,9 @@ def run_inference_pipeline(
labels_to_keep,
)

assert (
len(detections) > 0
), "TOFIX: currently, dealing with absence of detections is not supported"
assert len(detections) > 0, (
"TOFIX: currently, dealing with absence of detections is not supported"
)

# Ensure that detections has the instance_id column
detections = add_instance_id(detections)
Expand Down
16 changes: 8 additions & 8 deletions happypose/pose_estimators/megapose/models/pose_rigid.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def forward(
device=device,
)

outputs[f"iteration={n+1}"] = PosePredictorOutput(
outputs[f"iteration={n + 1}"] = PosePredictorOutput(
renders=renders,
images_crop=images_crop,
TCO_input=TCO_input,
Expand All @@ -669,7 +669,7 @@ def forward(
timing_dict=timing_dict,
)
if self.debug:
self.debug_data.output = outputs[f"iteration={n+1}"]
self.debug_data.output = outputs[f"iteration={n + 1}"]
TCO_input = TCO_output
return outputs

Expand All @@ -689,9 +689,9 @@ def forward_coarse_tensor(
input + rendered image

"""
assert (
self.predict_rendered_views_logits
), "Method only valid if coarse classification model"
assert self.predict_rendered_views_logits, (
"Method only valid if coarse classification model"
)
if torch.cuda.is_available():
timer = CudaTimer(enabled=cuda_timer)
else:
Expand Down Expand Up @@ -738,9 +738,9 @@ def forward_coarse(

"""

assert (
self.predict_rendered_views_logits
), "Method only valid if coarse classification model"
assert self.predict_rendered_views_logits, (
"Method only valid if coarse classification model"
)

if not self.input_depth:
# Remove the depth dimension if it is not used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def make_new_block():
face = line_f[3:].split(" ")
face = [f.split("/") for f in face]
face_flipped = " ".join(
[f"{x[0]}/{x[1]}/{int(x[2])+n_vn_orig}" for x in face],
[f"{x[0]}/{x[1]}/{int(x[2]) + n_vn_orig}" for x in face],
)
f_flipped.append(f"f {face_flipped}")
block["f"] += f_flipped
Expand Down
Loading
Loading