-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathvideo_demo.py
94 lines (71 loc) · 2.55 KB
/
video_demo.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
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import hydra
from omegaconf import DictConfig, OmegaConf
# from vggsfm.runners.runner import VGGSfMRunner
from vggsfm.runners.video_runner import VideoRunner
from vggsfm.datasets.demo_loader import DemoLoader
from vggsfm.utils.utils import seed_all_random_engines
@hydra.main(config_path="cfgs/", config_name="video_demo")
def demo_fn(cfg: DictConfig):
"""
Main function to run the VGGSfM demo. VideoRunner is the main controller.
VideoRunner assumes a sequential input of images.
"""
OmegaConf.set_struct(cfg, False)
# Print configuration
print("Model Config:", OmegaConf.to_yaml(cfg))
# Configure CUDA settings
torch.backends.cudnn.enabled = False
torch.backends.cudnn.benchmark = True
torch.backends.cudnn.deterministic = True
# Set seed for reproducibility
seed_all_random_engines(cfg.seed)
# Initialize VGGSfM Runner
vggsfm_runner = VideoRunner(cfg)
# Load Data
test_dataset = DemoLoader(
SCENE_DIR=cfg.SCENE_DIR,
img_size=cfg.img_size,
normalize_cameras=False,
load_gt=cfg.load_gt,
)
sequence_list = test_dataset.sequence_list
seq_name = sequence_list[0] # Run on one Scene
# Load the data for the selected sequence
batch, image_paths = test_dataset.get_data(
sequence_name=seq_name, return_path=True
)
output_dir = batch[
"scene_dir"
] # which is also cfg.SCENE_DIR for DemoLoader
images = batch["image"]
masks = batch["masks"] if batch["masks"] is not None else None
crop_params = (
batch["crop_params"] if batch["crop_params"] is not None else None
)
# Cache the original images for visualization, so that we don't need to re-load many times
original_images = batch["original_images"]
# Run VGGSfM
# Both visualization and output writing are performed inside VGGSfMRunner
predictions = vggsfm_runner.run(
images,
masks=masks,
original_images=original_images,
image_paths=image_paths,
crop_params=crop_params,
seq_name=seq_name,
output_dir=output_dir,
init_window_size=cfg.init_window_size,
window_size=cfg.window_size,
joint_BA_interval=cfg.joint_BA_interval,
)
print("Video Demo Finished Successfully")
return True
if __name__ == "__main__":
with torch.no_grad():
demo_fn()