Spaces:
Sleeping
Sleeping
Delete diffusionsfm/inference/predict.py
Browse files
diffusionsfm/inference/predict.py
DELETED
@@ -1,93 +0,0 @@
|
|
1 |
-
from diffusionsfm.inference.ddim import inference_ddim
|
2 |
-
from diffusionsfm.utils.rays import (
|
3 |
-
Rays,
|
4 |
-
rays_to_cameras,
|
5 |
-
rays_to_cameras_homography,
|
6 |
-
)
|
7 |
-
|
8 |
-
|
9 |
-
def predict_cameras(
|
10 |
-
model,
|
11 |
-
images,
|
12 |
-
device,
|
13 |
-
crop_parameters=None,
|
14 |
-
num_patches_x=16,
|
15 |
-
num_patches_y=16,
|
16 |
-
additional_timesteps=(),
|
17 |
-
calculate_intrinsics=False,
|
18 |
-
max_num_images=None,
|
19 |
-
mode=None,
|
20 |
-
return_rays=False,
|
21 |
-
use_homogeneous=False,
|
22 |
-
seed=0,
|
23 |
-
):
|
24 |
-
"""
|
25 |
-
Args:
|
26 |
-
images (torch.Tensor): (N, C, H, W)
|
27 |
-
crop_parameters (torch.Tensor): (N, 4) or None
|
28 |
-
"""
|
29 |
-
if calculate_intrinsics:
|
30 |
-
ray_to_cam = rays_to_cameras_homography
|
31 |
-
else:
|
32 |
-
ray_to_cam = rays_to_cameras
|
33 |
-
|
34 |
-
get_spatial_rays = Rays.from_spatial
|
35 |
-
|
36 |
-
rays_final, rays_intermediate, pred_intermediate, _ = inference_ddim(
|
37 |
-
model,
|
38 |
-
images.unsqueeze(0),
|
39 |
-
device,
|
40 |
-
visualize=True,
|
41 |
-
crop_parameters=crop_parameters.unsqueeze(0),
|
42 |
-
num_patches_x=num_patches_x,
|
43 |
-
num_patches_y=num_patches_y,
|
44 |
-
pbar=False,
|
45 |
-
eta=[1, 0],
|
46 |
-
num_inference_steps=100,
|
47 |
-
)
|
48 |
-
|
49 |
-
spatial_rays = get_spatial_rays(
|
50 |
-
rays_final[0],
|
51 |
-
mode=mode,
|
52 |
-
num_patches_x=num_patches_x,
|
53 |
-
num_patches_y=num_patches_y,
|
54 |
-
use_homogeneous=use_homogeneous,
|
55 |
-
)
|
56 |
-
|
57 |
-
pred_cam = ray_to_cam(
|
58 |
-
spatial_rays,
|
59 |
-
crop_parameters,
|
60 |
-
num_patches_x=num_patches_x,
|
61 |
-
num_patches_y=num_patches_y,
|
62 |
-
depth_resolution=model.depth_resolution,
|
63 |
-
average_centers=True,
|
64 |
-
directions_from_averaged_center=True,
|
65 |
-
)
|
66 |
-
|
67 |
-
additional_predictions = []
|
68 |
-
for t in additional_timesteps:
|
69 |
-
ray = pred_intermediate[t]
|
70 |
-
|
71 |
-
ray = get_spatial_rays(
|
72 |
-
ray[0],
|
73 |
-
mode=mode,
|
74 |
-
num_patches_x=num_patches_x,
|
75 |
-
num_patches_y=num_patches_y,
|
76 |
-
use_homogeneous=use_homogeneous,
|
77 |
-
)
|
78 |
-
|
79 |
-
cam = ray_to_cam(
|
80 |
-
ray,
|
81 |
-
crop_parameters,
|
82 |
-
num_patches_x=num_patches_x,
|
83 |
-
num_patches_y=num_patches_y,
|
84 |
-
average_centers=True,
|
85 |
-
directions_from_averaged_center=True,
|
86 |
-
)
|
87 |
-
if return_rays:
|
88 |
-
cam = (cam, ray)
|
89 |
-
additional_predictions.append(cam)
|
90 |
-
|
91 |
-
if return_rays:
|
92 |
-
return (pred_cam, spatial_rays), additional_predictions
|
93 |
-
return pred_cam, additional_predictions, spatial_rays
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|