Spaces:
Running on Zero
Running on Zero
Delete inference.py
Browse files- inference.py +0 -39
inference.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
import torch
|
| 4 |
-
import os
|
| 5 |
-
import sys
|
| 6 |
-
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 7 |
-
|
| 8 |
-
from src.misc.image_io import save_interpolated_video
|
| 9 |
-
from src.model.ply_export import export_ply
|
| 10 |
-
from src.model.model.anysplat import AnySplat
|
| 11 |
-
from src.utils.image import process_image
|
| 12 |
-
|
| 13 |
-
def main():
|
| 14 |
-
# Load the model from Hugging Face
|
| 15 |
-
model = AnySplat.from_pretrained("lhjiang/anysplat")
|
| 16 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 17 |
-
model = model.to(device)
|
| 18 |
-
model.eval()
|
| 19 |
-
for param in model.parameters():
|
| 20 |
-
param.requires_grad = False
|
| 21 |
-
|
| 22 |
-
# Load Images
|
| 23 |
-
image_folder = "examples/vrnerf/riverview"
|
| 24 |
-
images = sorted([os.path.join(image_folder, f) for f in os.listdir(image_folder) if f.lower().endswith(('.png', '.jpg', '.jpeg'))])
|
| 25 |
-
images = [process_image(img_path) for img_path in images]
|
| 26 |
-
images = torch.stack(images, dim=0).unsqueeze(0).to(device) # [1, K, 3, 448, 448]
|
| 27 |
-
b, v, _, h, w = images.shape
|
| 28 |
-
|
| 29 |
-
# Run Inference
|
| 30 |
-
gaussians, pred_context_pose = model.inference((images+1)*0.5)
|
| 31 |
-
|
| 32 |
-
# Save the results
|
| 33 |
-
pred_all_extrinsic = pred_context_pose['extrinsic']
|
| 34 |
-
pred_all_intrinsic = pred_context_pose['intrinsic']
|
| 35 |
-
save_interpolated_video(pred_all_extrinsic, pred_all_intrinsic, b, h, w, gaussians, image_folder, model.decoder)
|
| 36 |
-
export_ply(gaussians.means[0], gaussians.scales[0], gaussians.rotations[0], gaussians.harmonics[0], gaussians.opacities[0], Path(image_folder) / "gaussians.ply")
|
| 37 |
-
|
| 38 |
-
if __name__ == "__main__":
|
| 39 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|