Skip to content
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.11
rev: v0.16.2
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format
- repo: https://github.com/pappasam/toml-sort
rev: v0.24.2
rev: v0.24.4
hooks:
- id: toml-sort-fix
exclude: poetry.lock
Expand Down
4 changes: 1 addition & 3 deletions experiments/generate_dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import copy
import time
import typing as tp
from dataclasses import dataclass
from typing import List

import hydra
import numpy as np
Expand All @@ -16,7 +14,7 @@
@dataclass
class DatasetGenerationConfig:
dataset_id: str
chunk_ids: tp.Optional[List[int]]
chunk_ids: list[int] | None
debug: bool = False
verbose: bool = True
overwrite: bool = False
Expand Down
23 changes: 11 additions & 12 deletions experiments/job-runner/job_runner/configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import typing as tp
from dataclasses import dataclass
from typing import Dict, List

from hydra.core.config_store import ConfigStore

Expand All @@ -16,7 +15,7 @@ class NodeConfig:
@dataclass
class SlurmQueueConfig(NodeConfig):
partition: str
constraint: tp.Optional[str] = None
constraint: str | None = None


@dataclass
Expand All @@ -32,31 +31,31 @@ class SlurmJobConfig(JobConfig):
account: str
qos: str
time: str
additional_parameters: tp.Optional[Dict[str, tp.Any]]
additional_parameters: dict[str, tp.Any] | None


@dataclass
class CodeSnapshotConfig:
snapshot_dir: tp.Optional[str]
exclude_path: tp.Optional[str]
python_packages_dir: tp.Optional[List[str]] = None
snapshot_dir: str | None
exclude_path: str | None
python_packages_dir: list[str] | None = None


@dataclass
class JobEnvironmentConfig:
conda_env: str
code_snapshot: tp.Optional[CodeSnapshotConfig] = None
env: tp.Optional[Dict[str, str]] = None
code_snapshot: CodeSnapshotConfig | None = None
env: dict[str, str] | None = None


@dataclass
class RunnerConfig:
log_dir: str
job_env: JobEnvironmentConfig
local_node: tp.Optional[NodeConfig]
local_job: tp.Optional[JobConfig]
slurm_queue: tp.Optional[SlurmQueueConfig]
slurm_job: tp.Optional[SlurmJobConfig]
local_node: NodeConfig | None
local_job: JobConfig | None
slurm_queue: SlurmQueueConfig | None
slurm_job: SlurmJobConfig | None
use_slurm: bool = False


Expand Down
6 changes: 2 additions & 4 deletions experiments/job-runner/job_runner/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pathlib
import typing as tp
from typing import List

import submitit

from job_runner.configs import JobEnvironmentConfig, RunnerConfig


def make_setup(cfg: JobEnvironmentConfig) -> List[str]:
def make_setup(cfg: JobEnvironmentConfig) -> list[str]:
setup = []
if cfg.env:
for k, v in cfg.env.items():
Expand All @@ -16,7 +15,7 @@ def make_setup(cfg: JobEnvironmentConfig) -> List[str]:


def make_snapshots(
code_directories: List[pathlib.Path],
code_directories: list[pathlib.Path],
output_dir: pathlib.Path,
exclude: tp.Sequence[str] = (),
):
Expand All @@ -28,7 +27,6 @@ def make_snapshots(
)
with snapshot:
pass
return


def make_submitit_executor(
Expand Down
10 changes: 4 additions & 6 deletions experiments/make_shapenet_ids.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import json
import os
import pathlib as p
import typing as tp
from collections import deque
from dataclasses import dataclass
from typing import Dict, List


@dataclass
class ShapeNetSynset:
id: str
name: str
parents: List[str]
children: List[str]
parents: list[str]
children: list[str]


@dataclass
Expand All @@ -27,7 +25,7 @@ def read_models(shapenet_dir):
# TODO: This probably has issues / is poorly implemented and very slow
taxonomy = json.load(open(shapenet_dir / "taxonomy.json"))

id_to_synset: Dict[int, ShapeNetSynset] = {}
id_to_synset: dict[int, ShapeNetSynset] = {}

for synset in taxonomy:
synset_id = synset["synsetId"]
Expand Down Expand Up @@ -56,7 +54,7 @@ def get_names(synset_id, id_to_synset):
return names

models_path = shapenet_dir.glob("**/**/models/model_normalized.obj")
models: List[Dict[str, tp.Union[int, str]]] = []
models: list[dict[str, int | str]] = []
for n, model_path in enumerate(models_path):
source_id = model_path.parent.parent.name
synset_id = model_path.parent.parent.parent.name
Expand Down
1 change: 0 additions & 1 deletion experiments/postprocess_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def process_key(key, ds_dir, stoi_obj, out_dir):
gt_n["obj_id"] = stoi_obj[gt_n["obj_id"]]
gt = [inout._gt_as_json(d) for d in gt]
inout.save_json(out_dir / f"{key}.gt.json", gt)
return


def process_keys(keys, *args):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def build_index(ds_dir, save_file, split, save_file_annotations):
)
frame_index.to_feather(save_file)
save_file_annotations.write_bytes(pickle.dumps(annotations))
return


class BOPDataset:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
from pathlib import Path
from typing import Union


class BOPObjectDataset:
def __init__(self, ds_dir, label_format: Union[None, str] = None):
def __init__(self, ds_dir, label_format: None | str = None):
ds_dir = Path(ds_dir)
infos_file = ds_dir / "models_info.json"
infos = json.loads(infos_file.read_text())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Standard Library
from pathlib import Path
from typing import Any, Dict, Optional
from typing import Any

# Third Party
import torch
Expand Down Expand Up @@ -140,8 +140,8 @@ def get_save_dir(cfg: EvalConfig) -> Path:

def run_eval(
cfg: EvalConfig,
save_dir: Optional[Path] = None,
) -> Dict[str, Any]:
save_dir: Path | None = None,
) -> dict[str, Any]:
"""Run eval for a single setting on a single dataset.

A single setting is a (detection_type, coarse_estimation_type) such
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ def gather_distributed(self, tmp_dir):

if world_size > 1:
torch.distributed.barrier()
return
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# Standard Library
import time
from collections import defaultdict
from typing import Dict, Optional

# Third Party
import numpy as np
Expand Down Expand Up @@ -82,8 +81,8 @@ def run_inference_pipeline(
pose_estimator: PoseEstimator,
obs_tensor: ObservationTensor,
gt_detections: DetectionsType,
initial_estimates: Optional[PoseEstimatesType] = None,
) -> Dict[str, PoseEstimatesType]:
initial_estimates: PoseEstimatesType | None = None,
) -> dict[str, PoseEstimatesType]:
"""Runs inference pipeline, extracts the results.

Returns: A dict with keys
Expand Down Expand Up @@ -160,7 +159,7 @@ def run_inference_pipeline(
def get_predictions(
self,
pose_estimator: PoseEstimator,
) -> Dict[str, PoseEstimatesType]:
) -> dict[str, PoseEstimatesType]:
"""Runs predictions.

Returns: A dict with keys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

import numpy as np
import pandas as pd
import torch
Expand Down Expand Up @@ -31,7 +29,7 @@ def __init__(self, model, ds_name):
def get_detections(
self,
observation: ObservationTensor,
detection_th: Optional[float] = None,
detection_th: float | None = None,
output_masks: bool = False,
mask_th: float = 0.8,
one_instance_per_class: bool = False,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time
from collections import defaultdict
from typing import Any, List, Optional, Tuple
from typing import Any

import numpy as np
import torch
Expand Down Expand Up @@ -35,9 +35,9 @@ class PoseEstimator(PoseEstimationModule):

def __init__(
self,
refiner_model: Optional[torch.nn.Module] = None,
coarse_model: Optional[torch.nn.Module] = None,
detector_model: Optional[torch.nn.Module] = None,
refiner_model: torch.nn.Module | None = None,
coarse_model: torch.nn.Module | None = None,
detector_model: torch.nn.Module | None = None,
# depth_refiner: Optional[DepthRefiner] = None,
bsz_objects: int = 8,
bsz_images: int = 256,
Expand Down Expand Up @@ -139,18 +139,18 @@ def make_TCO_init(self, detections, K):
def run_inference_pipeline(
self,
observation: ObservationTensor,
detections: Optional[DetectionsType] = None,
data_TCO_init: Optional[PandasTensorCollection] = None,
run_detector: Optional[bool] = None,
detections: DetectionsType | None = None,
data_TCO_init: PandasTensorCollection | None = None,
run_detector: bool | None = None,
n_refiner_iterations: int = 1,
n_coarse_iterations: int = 1,
bsz_images: Optional[int] = None,
bsz_objects: Optional[int] = None,
coarse_estimates: Optional[PoseEstimatesType] = None,
bsz_images: int | None = None,
bsz_objects: int | None = None,
coarse_estimates: PoseEstimatesType | None = None,
detection_th: float = 0.7,
mask_th: float = 0.8,
labels_to_keep: Optional[List[str]] = None,
) -> Tuple[PoseEstimatesType, dict]:
labels_to_keep: list[str] | None = None,
) -> tuple[PoseEstimatesType, dict]:
timing_str = ""
timer = SimpleTimer()
timer.start()
Expand Down Expand Up @@ -265,7 +265,7 @@ def forward_coarse_model(
n_iterations: int = 5,
keep_all_outputs: bool = False,
cuda_timer: bool = False,
) -> Tuple[dict, dict]:
) -> tuple[dict, dict]:
"""Runs the refiner model for the specified number of iterations.

Will actually use the batched_model_predictions to stay within
Expand Down Expand Up @@ -377,7 +377,7 @@ def forward_refiner(
n_iterations: int = 5,
keep_all_outputs: bool = False,
cuda_timer: bool = False,
) -> Tuple[dict, dict]:
) -> tuple[dict, dict]:
"""Runs the refiner model for the specified number of iterations.

Will actually use the batched_model_predictions to stay within
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections import defaultdict
from typing import Tuple

import torch
from torch.utils.data import DataLoader, TensorDataset
Expand Down Expand Up @@ -135,7 +134,7 @@ def forward_coarse_model(
K,
data_TCO_init,
n_coarse_iterations,
) -> Tuple[PoseEstimatesType, dict]:
) -> tuple[PoseEstimatesType, dict]:
return self.batched_model_predictions(
self.coarse_model,
images,
Expand All @@ -150,7 +149,7 @@ def forward_refiner(
K,
data_TCO,
n_refiner_iterations,
) -> Tuple[dict, dict]:
) -> tuple[dict, dict]:
return self.batched_model_predictions(
self.refiner_model,
images,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,3 @@ def obj_to_urdf(obj_path, urdf_path):

xmlstr = minidom.parseString(ET.tostring(robot)).toprettyxml(indent=" ")
Path(urdf_path).write_text(xmlstr) # Write xml file
return
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See Implementation here https://github.com/ClementPinard/FlowNetPytorch/blob/master/models/FlowNetS.py
import torch
import torch.nn as nn
from torch import nn
from torch.nn.init import constant_, kaiming_normal_

from happypose.pose_estimators.cosypose.cosypose.config import LOCAL_DATA_DIR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def run_inference(args):
logger.info(f"Saved predictions in {save_dir}")

torch.distributed.barrier()
return


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# ruff: noqa: E402
from happypose.pose_estimators.cosypose.cosypose.utils.tqdm import patch_tqdm

patch_tqdm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def save_scene_json(objects, cameras, results_scene_path):

scene = {"objects": list_objects, "cameras": list_cameras}
results_scene_path.write_text(json.dumps(scene))
return


def main():
Expand Down
Loading
Loading