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
)
| 127 | |
| 128 | |
| 129 | def prepare_input( |
| 130 | img_paths, img_mask, size, raymaps=None, raymap_mask=None, revisit=1, update=True |
| 131 | ): |
| 132 | """ |
| 133 | Prepare input views for inference from a list of image paths. |
| 134 | |
| 135 | Args: |
| 136 | img_paths (list): List of image file paths. |
| 137 | img_mask (list of bool): Flags indicating valid images. |
| 138 | size (int): Target image size. |
| 139 | raymaps (list, optional): List of ray maps. |
| 140 | raymap_mask (list, optional): Flags indicating valid ray maps. |
| 141 | revisit (int): How many times to revisit each view. |
| 142 | update (bool): Whether to update the state on revisits. |
| 143 | |
| 144 | Returns: |
| 145 | list: A list of view dictionaries. |
| 146 | """ |
| 147 | # Import image loader (delayed import needed after adding ckpt path). |
| 148 | from src.dust3r.utils.image import load_images |
| 149 | |
| 150 | images = load_images(img_paths, size=size) |
| 151 | views = [] |
| 152 | num_views = len(images) |
| 153 | all_permutations = forward_backward_permutations(num_views, interval=2) |
| 154 | for permute in all_permutations: |
| 155 | _views = [] |
| 156 | for idx, i in enumerate(permute): |
| 157 | view = { |
| 158 | "img": images[i]["img"], |
| 159 | "ray_map": torch.full( |
| 160 | ( |
| 161 | images[i]["img"].shape[0], |
| 162 | 6, |
| 163 | images[i]["img"].shape[-2], |
| 164 | images[i]["img"].shape[-1], |
| 165 | ), |
| 166 | torch.nan, |
| 167 | ), |
| 168 | "true_shape": torch.from_numpy(images[i]["true_shape"]), |
| 169 | "idx": i, |
| 170 | "instance": str(i), |
| 171 | "camera_pose": torch.from_numpy(np.eye(4).astype(np.float32)).unsqueeze( |
| 172 | 0 |
| 173 | ), |
| 174 | "img_mask": torch.tensor(True).unsqueeze(0), |
| 175 | "ray_mask": torch.tensor(False).unsqueeze(0), |
| 176 | "update": torch.tensor(True).unsqueeze(0), |
| 177 | "reset": torch.tensor(False).unsqueeze(0), |
| 178 | } |
| 179 | _views.append(view) |
| 180 | views.append(_views) |
| 181 | return views |
| 182 | |
| 183 | |
| 184 | def prepare_output(output, outdir, device): |
no test coverage detected