MCPcopy Create free account
hub / github.com/Inception3D/TTT3R / prepare_input

Function prepare_input

demo.py:119–231  ·  view source on GitHub ↗

Prepare input views for inference from a list of image paths. Args: img_paths (list): List of image file paths. img_mask (list of bool): Flags indicating valid images. size (int): Target image size. raymaps (list, optional): List of ray maps. raymap_

(
    img_paths, img_mask, size, raymaps=None, raymap_mask=None, revisit=1, update=True, reset_interval=10000
)

Source from the content-addressed store, hash-verified

117
118
119def prepare_input(
120 img_paths, img_mask, size, raymaps=None, raymap_mask=None, revisit=1, update=True, reset_interval=10000
121):
122 """
123 Prepare input views for inference from a list of image paths.
124
125 Args:
126 img_paths (list): List of image file paths.
127 img_mask (list of bool): Flags indicating valid images.
128 size (int): Target image size.
129 raymaps (list, optional): List of ray maps.
130 raymap_mask (list, optional): Flags indicating valid ray maps.
131 revisit (int): How many times to revisit each view.
132 update (bool): Whether to update the state on revisits.
133
134 Returns:
135 list: A list of view dictionaries.
136 """
137 # Import image loader (delayed import needed after adding ckpt path).
138 from src.dust3r.utils.image import load_images
139
140 images = load_images(img_paths, size=size)
141 views = []
142
143 if raymaps is None and raymap_mask is None:
144 # Only images are provided.
145 for i in range(len(images)):
146 view = {
147 "img": images[i]["img"],
148 "ray_map": torch.full(
149 (
150 images[i]["img"].shape[0],
151 6,
152 images[i]["img"].shape[-2],
153 images[i]["img"].shape[-1],
154 ),
155 torch.nan,
156 ),
157 "true_shape": torch.from_numpy(images[i]["true_shape"]),
158 "idx": i,
159 "instance": str(i),
160 "camera_pose": torch.from_numpy(np.eye(4, dtype=np.float32)).unsqueeze(
161 0
162 ),
163 "img_mask": torch.tensor(True).unsqueeze(0),
164 "ray_mask": torch.tensor(False).unsqueeze(0),
165 "update": torch.tensor(True).unsqueeze(0),
166 "reset": torch.tensor((i+1) % reset_interval == 0).unsqueeze(0),
167 }
168 views.append(view)
169 if (i+1) % reset_interval == 0:
170 overlap_view = deepcopy(view)
171 overlap_view["reset"] = torch.tensor(False).unsqueeze(0)
172 views.append(overlap_view)
173 else:
174 # Combine images and raymaps.
175 num_views = len(images) + len(raymaps)
176 assert len(img_mask) == len(raymap_mask) == num_views

Callers 1

run_inferenceFunction · 0.70

Calls 1

load_imagesFunction · 0.90

Tested by

no test coverage detected