-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtest.py
executable file
·103 lines (81 loc) · 2.61 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import shutil
from termcolor import colored
import ipdb
import os
import random
import hydra
import numpy as np
import torch
from src.test.testbed import SlamTestbed as SLAM
from src.datasets import get_dataset
"""
Run the SLAM system on a given dataset or on image folder.
You can configure the system using .yaml configs. See docs for reference ...
"""
def sys_print(msg: str) -> None:
print(colored(msg, "white", "on_grey", attrs=["bold"]))
def setup_seed(seed):
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
torch.backends.cudnn.deterministic = True
def backup_source_code(backup_directory):
ignore_hidden = shutil.ignore_patterns(
".",
"..",
".git*",
"*pycache*",
"*build",
"*ext",
"*thirdparty",
"*.fuse*",
"*_drive_*",
"*pretrained*",
"*output*",
"*.png",
"*.jpg",
"*.jpeg",
"*media*",
"*.so",
"*.pyc",
"*.Python",
"*.eggs*",
"*.DS_Store*",
"*.idea*",
"*.pth",
"*__pycache__*",
"*.ply",
"*exps*",
)
if os.path.exists(backup_directory):
shutil.rmtree(backup_directory)
shutil.copytree(".", backup_directory, ignore=ignore_hidden)
os.system("chmod -R g+w {}".format(backup_directory))
def get_in_the_wild_heuristics(ht: int, wd: int, strategy: str = "generic") -> torch.Tensor:
"""We do not have camera intrinsics on in-the-wild data. In order for this to converge, we
need a good initialize guess. There are two strategies to do this: i) generc ii) teeds from DeepV2D
"""
if strategy == "generic":
fx = fy = (wd + ht) / 2
cx, cy = wd / 2, ht / 2
else:
fx = fy = wd * 1.2
cx, cy = wd / 2, ht / 2
return torch.Tensor([fx, fy, cx, cy], dtype=torch.float32)
@hydra.main(version_base=None, config_path="./configs/", config_name="test")
def run_slam(cfg):
output_folder = hydra.core.hydra_config.HydraConfig.get().runtime.output_dir
setup_seed(43)
torch.multiprocessing.set_start_method("spawn")
sys_print("#######################################")
sys_print("TESTBED")
sys_print("#######################################")
sys_print(f"\n\n** Running {cfg.data.input_folder} in {cfg.mode} mode!!! **\n\n")
dataset = get_dataset(cfg, device=cfg.device)
slam = SLAM(cfg, dataset=dataset, output_folder=output_folder)
sys_print(f"Running on {len(dataset)} frames")
slam.run(dataset)
sys_print("Done!")
if __name__ == "__main__":
run_slam()