Skip to content

Commit f5f1faf

Browse files
authored
Merge pull request #118 from agimus-project/py38
fix type hints for python 3.8 compatibility
2 parents 5a07e70 + dddd0a9 commit f5f1faf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+258
-245
lines changed

experiments/generate_dataset.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import typing as tp
44
from dataclasses import dataclass
5+
from typing import List
56

67
import hydra
78
import numpy as np
@@ -15,7 +16,7 @@
1516
@dataclass
1617
class DatasetGenerationConfig:
1718
dataset_id: str
18-
chunk_ids: tp.Optional[list[int]]
19+
chunk_ids: tp.Optional[List[int]]
1920
debug: bool = False
2021
verbose: bool = True
2122
overwrite: bool = False

experiments/job-runner/job_runner/configs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typing as tp
22
from dataclasses import dataclass
3+
from typing import Dict, List
34

45
from hydra.core.config_store import ConfigStore
56

@@ -31,21 +32,21 @@ class SlurmJobConfig(JobConfig):
3132
account: str
3233
qos: str
3334
time: str
34-
additional_parameters: tp.Optional[dict[str, tp.Any]]
35+
additional_parameters: tp.Optional[Dict[str, tp.Any]]
3536

3637

3738
@dataclass
3839
class CodeSnapshotConfig:
3940
snapshot_dir: tp.Optional[str]
4041
exclude_path: tp.Optional[str]
41-
python_packages_dir: tp.Optional[list[str]] = None
42+
python_packages_dir: tp.Optional[List[str]] = None
4243

4344

4445
@dataclass
4546
class JobEnvironmentConfig:
4647
conda_env: str
4748
code_snapshot: tp.Optional[CodeSnapshotConfig] = None
48-
env: tp.Optional[dict[str, str]] = None
49+
env: tp.Optional[Dict[str, str]] = None
4950

5051

5152
@dataclass

experiments/job-runner/job_runner/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pathlib
22
import typing as tp
3+
from typing import List
34

45
import submitit
56
from job_runner.configs import JobEnvironmentConfig, RunnerConfig
67

78

8-
def make_setup(cfg: JobEnvironmentConfig) -> list[str]:
9+
def make_setup(cfg: JobEnvironmentConfig) -> List[str]:
910
setup = []
1011
if cfg.env:
1112
for k, v in cfg.env.items():
@@ -14,7 +15,7 @@ def make_setup(cfg: JobEnvironmentConfig) -> list[str]:
1415

1516

1617
def make_snapshots(
17-
code_directories: list[pathlib.Path],
18+
code_directories: List[pathlib.Path],
1819
output_dir: pathlib.Path,
1920
exclude: tp.Sequence[str] = (),
2021
):

experiments/make_shapenet_ids.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import typing as tp
55
from collections import deque
66
from dataclasses import dataclass
7+
from typing import Dict, List
78

89

910
@dataclass
1011
class ShapeNetSynset:
1112
id: str
1213
name: str
13-
parents: list[str]
14-
children: list[str]
14+
parents: List[str]
15+
children: List[str]
1516

1617

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

29-
id_to_synset: dict[int, ShapeNetSynset] = {}
30+
id_to_synset: Dict[int, ShapeNetSynset] = {}
3031

3132
for synset in taxonomy:
3233
synset_id = synset["synsetId"]
@@ -55,7 +56,7 @@ def get_names(synset_id, id_to_synset):
5556
return names
5657

5758
models_path = shapenet_dir.glob("**/**/models/model_normalized.obj")
58-
models: list[dict[str, tp.Union[int, str]]] = []
59+
models: List[Dict[str, tp.Union[int, str]]] = []
5960
for n, model_path in enumerate(models_path):
6061
source_id = model_path.parent.parent.name
6162
synset_id = model_path.parent.parent.parent.name

happypose/pose_estimators/cosypose/cosypose/evaluation/evaluation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Standard Library
22
from pathlib import Path
3-
from typing import Any, Optional
3+
from typing import Any, Dict, Optional
44

55
# Third Party
66
import torch
@@ -157,7 +157,7 @@ def get_save_dir(cfg: EvalConfig) -> Path:
157157
def run_eval(
158158
cfg: EvalConfig,
159159
save_dir: Optional[Path] = None,
160-
) -> dict[str, Any]:
160+
) -> Dict[str, Any]:
161161
"""Run eval for a single setting on a single dataset.
162162
163163
A single setting is a (detection_type, coarse_estimation_type) such

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Standard Library
1818
import time
1919
from collections import defaultdict
20-
from typing import Optional
20+
from typing import Dict, Optional
2121

2222
# Third Party
2323
import numpy as np
@@ -84,7 +84,7 @@ def run_inference_pipeline(
8484
obs_tensor: ObservationTensor,
8585
gt_detections: DetectionsType,
8686
initial_estimates: Optional[PoseEstimatesType] = None,
87-
) -> dict[str, PoseEstimatesType]:
87+
) -> Dict[str, PoseEstimatesType]:
8888
"""Runs inference pipeline, extracts the results.
8989
9090
Returns: A dict with keys
@@ -160,7 +160,7 @@ def run_inference_pipeline(
160160
def get_predictions(
161161
self,
162162
pose_estimator: PoseEstimator,
163-
) -> dict[str, PoseEstimatesType]:
163+
) -> Dict[str, PoseEstimatesType]:
164164
"""Runs predictions.
165165
166166
Returns: A dict with keys

happypose/pose_estimators/cosypose/cosypose/integrated/pose_estimator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22
from collections import defaultdict
3-
from typing import Any, Optional
3+
from typing import Any, Optional, Tuple
44

55
import numpy as np
66
import torch
@@ -146,7 +146,7 @@ def run_inference_pipeline(
146146
coarse_estimates: Optional[PoseEstimatesType] = None,
147147
detection_th: float = 0.7,
148148
mask_th: float = 0.8,
149-
) -> tuple[PoseEstimatesType, dict]:
149+
) -> Tuple[PoseEstimatesType, dict]:
150150
timing_str = ""
151151
timer = SimpleTimer()
152152
timer.start()
@@ -248,7 +248,7 @@ def forward_coarse_model(
248248
n_iterations: int = 5,
249249
keep_all_outputs: bool = False,
250250
cuda_timer: bool = False,
251-
) -> tuple[dict, dict]:
251+
) -> Tuple[dict, dict]:
252252
"""Runs the refiner model for the specified number of iterations.
253253
254254
Will actually use the batched_model_predictions to stay within
@@ -357,7 +357,7 @@ def forward_refiner(
357357
n_iterations: int = 5,
358358
keep_all_outputs: bool = False,
359359
cuda_timer: bool = False,
360-
) -> tuple[dict, dict]:
360+
) -> Tuple[dict, dict]:
361361
"""Runs the refiner model for the specified number of iterations.
362362
363363
Will actually use the batched_model_predictions to stay within

happypose/pose_estimators/cosypose/cosypose/integrated/pose_predictor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from collections import defaultdict
2+
from typing import Tuple
23

34
import torch
45
from torch.utils.data import DataLoader, TensorDataset
@@ -133,7 +134,7 @@ def forward_coarse_model(
133134
K,
134135
data_TCO_init,
135136
n_coarse_iterations,
136-
) -> tuple[PoseEstimatesType, dict]:
137+
) -> Tuple[PoseEstimatesType, dict]:
137138
return self.batched_model_predictions(
138139
self.coarse_model,
139140
images,
@@ -148,7 +149,7 @@ def forward_refiner(
148149
K,
149150
data_TCO,
150151
n_refiner_iterations,
151-
) -> tuple[dict, dict]:
152+
) -> Tuple[dict, dict]:
152153
return self.batched_model_predictions(
153154
self.refiner_model,
154155
images,

happypose/pose_estimators/cosypose/cosypose/scripts/run_full_cosypose_eval_new.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import copy
33
import os
44
from pathlib import Path
5+
from typing import Dict, Tuple
56

67
# Third Party
78
from omegaconf import OmegaConf
@@ -68,7 +69,7 @@ def create_eval_cfg(
6869
detection_type: str,
6970
coarse_estimation_type: str,
7071
ds_name: str,
71-
) -> tuple[str, EvalConfig]:
72+
) -> Tuple[str, EvalConfig]:
7273
cfg = copy.deepcopy(cfg)
7374

7475
cfg.inference.detection_type = detection_type
@@ -107,7 +108,7 @@ def run_full_eval(cfg: FullEvalConfig) -> None:
107108
# Iterate over each dataset
108109
for ds_name in cfg.ds_names:
109110
# create the EvalConfig objects that we will call `run_eval` on
110-
eval_configs: dict[str, EvalConfig] = {}
111+
eval_configs: Dict[str, EvalConfig] = {}
111112
for detection_type, coarse_estimation_type in cfg.detection_coarse_types:
112113
name, cfg_ = create_eval_cfg(
113114
cfg,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
########################
66
# Add cosypose to my path -> dirty
77
from pathlib import Path
8-
from typing import Union
8+
from typing import Tuple, Union
99

1010
# Third Party
1111
import numpy as np
@@ -47,7 +47,7 @@
4747
def load_observation(
4848
example_dir: Path,
4949
load_depth: bool = False,
50-
) -> tuple[np.ndarray, Union[None, np.ndarray], CameraData]:
50+
) -> Tuple[np.ndarray, Union[None, np.ndarray], CameraData]:
5151
camera_data = CameraData.from_json((example_dir / "camera_data.json").read_text())
5252

5353
rgb = np.array(Image.open(example_dir / "image_rgb.png"), dtype=np.uint8)

happypose/pose_estimators/megapose/evaluation/data_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
# Standard Library
18-
from typing import Optional
18+
from typing import List, Optional
1919

2020
# Third Party
2121
import numpy as np
@@ -30,7 +30,7 @@
3030

3131
def parse_obs_data(
3232
obs: SceneObservation,
33-
object_labels: Optional[list[str]] = None,
33+
object_labels: Optional[List[str]] = None,
3434
) -> PandasTensorCollection:
3535
"""Parses object data into PandasTensorCollection.
3636

happypose/pose_estimators/megapose/evaluation/eval_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Standard Library
1818
from dataclasses import dataclass
19-
from typing import Optional
19+
from typing import List, Optional
2020

2121
# MegaPose
2222
from happypose.pose_estimators.megapose.inference.types import InferenceConfig
@@ -85,8 +85,8 @@ class EvalConfig:
8585
@dataclass
8686
class FullEvalConfig(EvalConfig):
8787
# Full eval
88-
detection_coarse_types: Optional[list] = None
89-
ds_names: Optional[list[str]] = None
88+
detection_coarse_types: Optional[List] = None
89+
ds_names: Optional[List[str]] = None
9090
run_bop_eval: bool = True
9191
eval_coarse_also: bool = False
9292
convert_only: bool = False

happypose/pose_estimators/megapose/evaluation/evaluation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Standard Library
1818
from pathlib import Path
19-
from typing import Any, Optional
19+
from typing import Any, Dict, Optional
2020

2121
# Third Party
2222
import torch
@@ -80,7 +80,7 @@ def get_save_dir(cfg: EvalConfig) -> Path:
8080
def run_eval(
8181
cfg: EvalConfig,
8282
save_dir: Optional[Path] = None,
83-
) -> dict[str, Any]:
83+
) -> Dict[str, Any]:
8484
"""Run eval for a single setting on a single dataset.
8585
8686
A single setting is a (detection_type, coarse_estimation_type) such

happypose/pose_estimators/megapose/inference/depth_refiner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Standard Library
1818
from abc import ABC, abstractmethod
19-
from typing import Optional
19+
from typing import Optional, Tuple
2020

2121
# Third Party
2222
import torch
@@ -33,7 +33,7 @@ def refine_poses(
3333
masks: Optional[torch.tensor] = None,
3434
depth: Optional[torch.tensor] = None,
3535
K: Optional[torch.tensor] = None,
36-
) -> tuple[PoseEstimatesType, dict]:
36+
) -> Tuple[PoseEstimatesType, dict]:
3737
"""Run the depth refinement.
3838
3939
Args:

happypose/pose_estimators/megapose/inference/icp_refiner.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
# Standard Library
18-
from typing import Optional
18+
from typing import Dict, Optional, Tuple
1919

2020
# Third Party
2121
import cv2
@@ -236,7 +236,7 @@ def refine_poses(
236236
masks: Optional[torch.tensor] = None,
237237
depth: Optional[torch.tensor] = None,
238238
K: Optional[torch.tensor] = None,
239-
) -> tuple[PoseEstimatesType, dict]:
239+
) -> Tuple[PoseEstimatesType, Dict]:
240240
"""Runs icp refinement. See superclass DepthRefiner for full documentation."""
241241
assert depth is not None
242242
assert K is not None

0 commit comments

Comments
 (0)