update code
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import importlib
|
| 3 |
import sys
|
| 4 |
import site
|
| 5 |
from PIL import Image
|
|
@@ -10,12 +9,15 @@ import random
|
|
| 10 |
import math
|
| 11 |
import hydra
|
| 12 |
import numpy as np
|
|
|
|
|
|
|
| 13 |
# import torch
|
| 14 |
# import torch.nn as nn
|
| 15 |
# print(torch.__version__)
|
| 16 |
# print(torch.version.cuda)
|
| 17 |
# import torch.backends.cudnn
|
| 18 |
# from torch.utils.data import DataLoader
|
|
|
|
| 19 |
import glob
|
| 20 |
import os
|
| 21 |
import subprocess
|
|
@@ -25,6 +27,7 @@ import copy
|
|
| 25 |
import yaml
|
| 26 |
import matplotlib.pyplot as plt
|
| 27 |
from sklearn.neighbors import NearestNeighbors
|
|
|
|
| 28 |
import spaces
|
| 29 |
from spaces import zero
|
| 30 |
zero.startup()
|
|
@@ -65,43 +68,46 @@ zero.startup()
|
|
| 65 |
# importlib.invalidate_caches()
|
| 66 |
# torch = importlib.import_module("torch")
|
| 67 |
|
| 68 |
-
import torch
|
| 69 |
-
import torch.nn as nn
|
| 70 |
-
from torch.utils.data import DataLoader
|
| 71 |
-
import kornia
|
| 72 |
-
import warp as wp
|
| 73 |
|
| 74 |
-
print(torch.__version__)
|
| 75 |
-
print(torch.version.cuda)
|
| 76 |
|
| 77 |
import sys
|
| 78 |
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
| 79 |
sys.path.append(str(Path(__file__).parent / "src" / "experiments"))
|
| 80 |
|
| 81 |
-
from pgnd.sim import Friction, CacheDiffSimWithFrictionBatch, StaticsBatch, CollidersBatch
|
| 82 |
-
from pgnd.material import PGNDModel
|
| 83 |
-
from pgnd.utils import Logger, get_root, mkdir
|
| 84 |
-
from pgnd.ffmpeg import make_video
|
| 85 |
|
| 86 |
-
from real_world.utils.render_utils import interpolate_motions
|
| 87 |
-
from real_world.gs.helpers import setup_camera
|
| 88 |
-
from real_world.gs.convert import save_to_splat, read_splat
|
| 89 |
|
| 90 |
-
from diff_gaussian_rasterization import GaussianRasterizer
|
| 91 |
-
from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
|
| 92 |
|
| 93 |
root = Path(__file__).parent / "src" / "experiments"
|
| 94 |
|
| 95 |
|
| 96 |
def quat2mat(quat):
|
|
|
|
| 97 |
return kornia.geometry.conversions.quaternion_to_rotation_matrix(quat)
|
| 98 |
|
| 99 |
|
| 100 |
def mat2quat(mat):
|
|
|
|
| 101 |
return kornia.geometry.conversions.rotation_matrix_to_quaternion(mat)
|
| 102 |
|
| 103 |
|
| 104 |
def fps(x, enabled, n, device, random_start=False):
|
|
|
|
| 105 |
from dgl.geometry import farthest_point_sampler
|
| 106 |
assert torch.diff(enabled * 1.0).sum() in [0.0, -1.0]
|
| 107 |
start_idx = random.randint(0, enabled.sum() - 1) if random_start else 0
|
|
@@ -139,10 +145,10 @@ class DynamicsVisualizer:
|
|
| 139 |
cfg.sim.uniform = True
|
| 140 |
cfg.sim.use_pv = False
|
| 141 |
|
| 142 |
-
device = torch.device('cuda')
|
| 143 |
|
| 144 |
self.cfg = cfg
|
| 145 |
-
self.device = device
|
| 146 |
self.k_rel = 8 # knn for relations
|
| 147 |
self.k_wgt = 16 # knn for weights
|
| 148 |
self.with_bg = True
|
|
@@ -155,7 +161,7 @@ class DynamicsVisualizer:
|
|
| 155 |
seed = cfg.seed
|
| 156 |
random.seed(seed)
|
| 157 |
np.random.seed(seed)
|
| 158 |
-
torch.manual_seed(seed)
|
| 159 |
# torch.autograd.set_detect_anomaly(True)
|
| 160 |
# torch.backends.cudnn.benchmark = True
|
| 161 |
|
|
@@ -424,7 +430,7 @@ class DynamicsVisualizer:
|
|
| 424 |
'global_translation': global_translation,
|
| 425 |
}
|
| 426 |
|
| 427 |
-
@torch.no_grad
|
| 428 |
def render(self, render_data, cam_id, bg=[0.7, 0.7, 0.7]):
|
| 429 |
render_data = {k: v.to(self.device) for k, v in render_data.items()}
|
| 430 |
w, h = self.metadata['w'], self.metadata['h']
|
|
@@ -502,7 +508,7 @@ class DynamicsVisualizer:
|
|
| 502 |
sim = CacheDiffSimWithFrictionBatch(self.cfg, num_steps, 1, self.wp_device, requires_grad=True)
|
| 503 |
self.sim = sim
|
| 504 |
|
| 505 |
-
@torch.no_grad
|
| 506 |
def step(self):
|
| 507 |
cfg = self.cfg
|
| 508 |
batch_size = 1
|
|
@@ -897,6 +903,28 @@ class DynamicsVisualizer:
|
|
| 897 |
|
| 898 |
@spaces.GPU
|
| 899 |
def reset(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 900 |
wp.init()
|
| 901 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 902 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1041,7 +1069,6 @@ class DynamicsVisualizer:
|
|
| 1041 |
|
| 1042 |
@spaces.GPU
|
| 1043 |
def on_click_run_xplus(self):
|
| 1044 |
-
wp.init()
|
| 1045 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1046 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1047 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1053,7 +1080,6 @@ class DynamicsVisualizer:
|
|
| 1053 |
|
| 1054 |
@spaces.GPU
|
| 1055 |
def on_click_run_xminus(self):
|
| 1056 |
-
wp.init()
|
| 1057 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1058 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1059 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1065,7 +1091,6 @@ class DynamicsVisualizer:
|
|
| 1065 |
|
| 1066 |
@spaces.GPU
|
| 1067 |
def on_click_run_yplus(self):
|
| 1068 |
-
wp.init()
|
| 1069 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1070 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1071 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1077,7 +1102,6 @@ class DynamicsVisualizer:
|
|
| 1077 |
|
| 1078 |
@spaces.GPU
|
| 1079 |
def on_click_run_yminus(self):
|
| 1080 |
-
wp.init()
|
| 1081 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1082 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1083 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1089,7 +1113,6 @@ class DynamicsVisualizer:
|
|
| 1089 |
|
| 1090 |
@spaces.GPU
|
| 1091 |
def on_click_run_zplus(self):
|
| 1092 |
-
wp.init()
|
| 1093 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1094 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1095 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
@@ -1101,7 +1124,6 @@ class DynamicsVisualizer:
|
|
| 1101 |
|
| 1102 |
@spaces.GPU
|
| 1103 |
def on_click_run_zminus(self):
|
| 1104 |
-
wp.init()
|
| 1105 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1106 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1107 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import sys
|
| 3 |
import site
|
| 4 |
from PIL import Image
|
|
|
|
| 9 |
import math
|
| 10 |
import hydra
|
| 11 |
import numpy as np
|
| 12 |
+
|
| 13 |
+
# import importlib
|
| 14 |
# import torch
|
| 15 |
# import torch.nn as nn
|
| 16 |
# print(torch.__version__)
|
| 17 |
# print(torch.version.cuda)
|
| 18 |
# import torch.backends.cudnn
|
| 19 |
# from torch.utils.data import DataLoader
|
| 20 |
+
|
| 21 |
import glob
|
| 22 |
import os
|
| 23 |
import subprocess
|
|
|
|
| 27 |
import yaml
|
| 28 |
import matplotlib.pyplot as plt
|
| 29 |
from sklearn.neighbors import NearestNeighbors
|
| 30 |
+
|
| 31 |
import spaces
|
| 32 |
from spaces import zero
|
| 33 |
zero.startup()
|
|
|
|
| 68 |
# importlib.invalidate_caches()
|
| 69 |
# torch = importlib.import_module("torch")
|
| 70 |
|
| 71 |
+
# import torch
|
| 72 |
+
# import torch.nn as nn
|
| 73 |
+
# from torch.utils.data import DataLoader
|
| 74 |
+
# import kornia
|
| 75 |
+
# import warp as wp
|
| 76 |
|
| 77 |
+
# print(torch.__version__)
|
| 78 |
+
# print(torch.version.cuda)
|
| 79 |
|
| 80 |
import sys
|
| 81 |
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
| 82 |
sys.path.append(str(Path(__file__).parent / "src" / "experiments"))
|
| 83 |
|
| 84 |
+
# from pgnd.sim import Friction, CacheDiffSimWithFrictionBatch, StaticsBatch, CollidersBatch
|
| 85 |
+
# from pgnd.material import PGNDModel
|
| 86 |
+
# from pgnd.utils import Logger, get_root, mkdir
|
| 87 |
+
# from pgnd.ffmpeg import make_video
|
| 88 |
|
| 89 |
+
# from real_world.utils.render_utils import interpolate_motions
|
| 90 |
+
# from real_world.gs.helpers import setup_camera
|
| 91 |
+
# from real_world.gs.convert import save_to_splat, read_splat
|
| 92 |
|
| 93 |
+
# from diff_gaussian_rasterization import GaussianRasterizer
|
| 94 |
+
# from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
|
| 95 |
|
| 96 |
root = Path(__file__).parent / "src" / "experiments"
|
| 97 |
|
| 98 |
|
| 99 |
def quat2mat(quat):
|
| 100 |
+
import kornia
|
| 101 |
return kornia.geometry.conversions.quaternion_to_rotation_matrix(quat)
|
| 102 |
|
| 103 |
|
| 104 |
def mat2quat(mat):
|
| 105 |
+
import kornia
|
| 106 |
return kornia.geometry.conversions.rotation_matrix_to_quaternion(mat)
|
| 107 |
|
| 108 |
|
| 109 |
def fps(x, enabled, n, device, random_start=False):
|
| 110 |
+
import torch
|
| 111 |
from dgl.geometry import farthest_point_sampler
|
| 112 |
assert torch.diff(enabled * 1.0).sum() in [0.0, -1.0]
|
| 113 |
start_idx = random.randint(0, enabled.sum() - 1) if random_start else 0
|
|
|
|
| 145 |
cfg.sim.uniform = True
|
| 146 |
cfg.sim.use_pv = False
|
| 147 |
|
| 148 |
+
# device = torch.device('cuda')
|
| 149 |
|
| 150 |
self.cfg = cfg
|
| 151 |
+
# self.device = device
|
| 152 |
self.k_rel = 8 # knn for relations
|
| 153 |
self.k_wgt = 16 # knn for weights
|
| 154 |
self.with_bg = True
|
|
|
|
| 161 |
seed = cfg.seed
|
| 162 |
random.seed(seed)
|
| 163 |
np.random.seed(seed)
|
| 164 |
+
# torch.manual_seed(seed)
|
| 165 |
# torch.autograd.set_detect_anomaly(True)
|
| 166 |
# torch.backends.cudnn.benchmark = True
|
| 167 |
|
|
|
|
| 430 |
'global_translation': global_translation,
|
| 431 |
}
|
| 432 |
|
| 433 |
+
# @torch.no_grad
|
| 434 |
def render(self, render_data, cam_id, bg=[0.7, 0.7, 0.7]):
|
| 435 |
render_data = {k: v.to(self.device) for k, v in render_data.items()}
|
| 436 |
w, h = self.metadata['w'], self.metadata['h']
|
|
|
|
| 508 |
sim = CacheDiffSimWithFrictionBatch(self.cfg, num_steps, 1, self.wp_device, requires_grad=True)
|
| 509 |
self.sim = sim
|
| 510 |
|
| 511 |
+
# @torch.no_grad
|
| 512 |
def step(self):
|
| 513 |
cfg = self.cfg
|
| 514 |
batch_size = 1
|
|
|
|
| 903 |
|
| 904 |
@spaces.GPU
|
| 905 |
def reset(self):
|
| 906 |
+
import torch
|
| 907 |
+
import torch.nn as nn
|
| 908 |
+
from torch.utils.data import DataLoader
|
| 909 |
+
import kornia
|
| 910 |
+
import warp as wp
|
| 911 |
+
|
| 912 |
+
from pgnd.sim import Friction, CacheDiffSimWithFrictionBatch, StaticsBatch, CollidersBatch
|
| 913 |
+
from pgnd.material import PGNDModel
|
| 914 |
+
from pgnd.utils import Logger, get_root, mkdir
|
| 915 |
+
from pgnd.ffmpeg import make_video
|
| 916 |
+
|
| 917 |
+
from real_world.utils.render_utils import interpolate_motions
|
| 918 |
+
from real_world.gs.helpers import setup_camera
|
| 919 |
+
from real_world.gs.convert import save_to_splat, read_splat
|
| 920 |
+
|
| 921 |
+
from diff_gaussian_rasterization import GaussianRasterizer
|
| 922 |
+
from diff_gaussian_rasterization import GaussianRasterizationSettings as Camera
|
| 923 |
+
|
| 924 |
+
device = torch.device('cuda:0')
|
| 925 |
+
self.device = device
|
| 926 |
+
torch.manual_seed(self.cfg.seed)
|
| 927 |
+
|
| 928 |
wp.init()
|
| 929 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 930 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1069 |
|
| 1070 |
@spaces.GPU
|
| 1071 |
def on_click_run_xplus(self):
|
|
|
|
| 1072 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1073 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1074 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1080 |
|
| 1081 |
@spaces.GPU
|
| 1082 |
def on_click_run_xminus(self):
|
|
|
|
| 1083 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1084 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1085 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1091 |
|
| 1092 |
@spaces.GPU
|
| 1093 |
def on_click_run_yplus(self):
|
|
|
|
| 1094 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1095 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1096 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1102 |
|
| 1103 |
@spaces.GPU
|
| 1104 |
def on_click_run_yminus(self):
|
|
|
|
| 1105 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1106 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1107 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1113 |
|
| 1114 |
@spaces.GPU
|
| 1115 |
def on_click_run_zplus(self):
|
|
|
|
| 1116 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1117 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1118 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|
|
|
|
| 1124 |
|
| 1125 |
@spaces.GPU
|
| 1126 |
def on_click_run_zminus(self):
|
|
|
|
| 1127 |
gpus = [int(gpu) for gpu in self.cfg.gpus]
|
| 1128 |
wp_devices = [wp.get_device(f'cuda:{gpu}') for gpu in gpus]
|
| 1129 |
torch_devices = [torch.device(f'cuda:{gpu}') for gpu in gpus]
|