Spaces:
Running
on
Zero
Running
on
Zero
daidedou
commited on
Commit
·
ad6a975
1
Parent(s):
cddf12c
Adapt to ZeroGPU?
Browse files- app.py +3 -3
- zero_shot.py +5 -0
app.py
CHANGED
|
@@ -43,7 +43,7 @@ def _safe_ext(path: str) -> str:
|
|
| 43 |
return ext
|
| 44 |
return os.path.splitext(path)[1].lower()
|
| 45 |
|
| 46 |
-
|
| 47 |
def convert_and_show(mesh_file):
|
| 48 |
os.makedirs("tmp/glbs", exist_ok=True)
|
| 49 |
if mesh_file is None:
|
|
@@ -54,7 +54,6 @@ def convert_and_show(mesh_file):
|
|
| 54 |
mesh.export(f_name)
|
| 55 |
return f_name
|
| 56 |
|
| 57 |
-
@spaces.GPU
|
| 58 |
def convert_and_show_twice(mesh_file_1, mesh_file_2):
|
| 59 |
return convert_and_show(mesh_file_1), convert_and_show(mesh_file_2)
|
| 60 |
|
|
@@ -176,6 +175,8 @@ def build_outputs(surf_a: Surface, surf_b: Surface, cmap_a: np.ndarray, p2p: np.
|
|
| 176 |
@spaces.GPU
|
| 177 |
def init_clicked(mesh1_path, mesh2_path,
|
| 178 |
lambda_val, zoomout_val, time_val, nloop_val, sds_val, proper_val):
|
|
|
|
|
|
|
| 179 |
print("inside init")
|
| 180 |
cfg.deepfeat_conf.fmap.lambda_ = lambda_val
|
| 181 |
cfg.sds_conf.zoomout = zoomout_val
|
|
@@ -188,7 +189,6 @@ def init_clicked(mesh1_path, mesh2_path,
|
|
| 188 |
raise gr.Error("Please upload both meshes.")
|
| 189 |
global datadicts
|
| 190 |
datadicts = Datadicts(mesh1_path, mesh2_path)
|
| 191 |
-
matcher._init()
|
| 192 |
shape_dict, target_dict = convert_dict(datadicts.shape_dict, 'cuda'), convert_dict(datadicts.target_dict, 'cuda')
|
| 193 |
fmap_model_cuda = matcher.fmap_model.cuda()
|
| 194 |
diff_model_cuda = matcher.diffusion_model
|
|
|
|
| 43 |
return ext
|
| 44 |
return os.path.splitext(path)[1].lower()
|
| 45 |
|
| 46 |
+
|
| 47 |
def convert_and_show(mesh_file):
|
| 48 |
os.makedirs("tmp/glbs", exist_ok=True)
|
| 49 |
if mesh_file is None:
|
|
|
|
| 54 |
mesh.export(f_name)
|
| 55 |
return f_name
|
| 56 |
|
|
|
|
| 57 |
def convert_and_show_twice(mesh_file_1, mesh_file_2):
|
| 58 |
return convert_and_show(mesh_file_1), convert_and_show(mesh_file_2)
|
| 59 |
|
|
|
|
| 175 |
@spaces.GPU
|
| 176 |
def init_clicked(mesh1_path, mesh2_path,
|
| 177 |
lambda_val, zoomout_val, time_val, nloop_val, sds_val, proper_val):
|
| 178 |
+
|
| 179 |
+
matcher._init()
|
| 180 |
print("inside init")
|
| 181 |
cfg.deepfeat_conf.fmap.lambda_ = lambda_val
|
| 182 |
cfg.sds_conf.zoomout = zoomout_val
|
|
|
|
| 189 |
raise gr.Error("Please upload both meshes.")
|
| 190 |
global datadicts
|
| 191 |
datadicts = Datadicts(mesh1_path, mesh2_path)
|
|
|
|
| 192 |
shape_dict, target_dict = convert_dict(datadicts.shape_dict, 'cuda'), convert_dict(datadicts.target_dict, 'cuda')
|
| 193 |
fmap_model_cuda = matcher.fmap_model.cuda()
|
| 194 |
diff_model_cuda = matcher.diffusion_model
|
zero_shot.py
CHANGED
|
@@ -27,6 +27,7 @@ from utils.pickle_stuff import safe_load_with_fallback
|
|
| 27 |
from utils.geometry import compute_operators, load_operators
|
| 28 |
from utils.surfaces import Surface
|
| 29 |
import sys
|
|
|
|
| 30 |
|
| 31 |
try:
|
| 32 |
import google.colab
|
|
@@ -120,6 +121,7 @@ class Matcher(object):
|
|
| 120 |
self.fmap_cfg = self.cfg.deepfeat_conf.fmap
|
| 121 |
self.dataloaders = dict()
|
| 122 |
|
|
|
|
| 123 |
def _init(self):
|
| 124 |
cfg = self.cfg
|
| 125 |
self.fmap_model = DFMNet(self.cfg["deepfeat_conf"]["fmap"]).cuda()
|
|
@@ -136,6 +138,7 @@ class Matcher(object):
|
|
| 136 |
self.eye = torch.eye(self.n_fmap).float().cuda()
|
| 137 |
self.eye.requires_grad = False
|
| 138 |
|
|
|
|
| 139 |
def fmap(self, shape_dict, target_dict):
|
| 140 |
diff_model_cuda = self.diffusion_model
|
| 141 |
diff_model_cuda.net.cuda()
|
|
@@ -152,6 +155,7 @@ class Matcher(object):
|
|
| 152 |
mask_12, mask_21 = None, None
|
| 153 |
return C12_pred, C12_obj, C21_pred, C21_obj, feat1, feat2, evecs_trans1, evecs_trans2, mask_12, mask_21
|
| 154 |
|
|
|
|
| 155 |
def zo_shot(self, shape_dict, target_dict):
|
| 156 |
self._init()
|
| 157 |
evecs1, evecs2 = shape_dict["evecs"], target_dict["evecs"]
|
|
@@ -161,6 +165,7 @@ class Matcher(object):
|
|
| 161 |
indKNN_new, _ = extract_p2p_torch_fmap(new_FM, evecs1, evecs2)
|
| 162 |
return new_FM, indKNN_new
|
| 163 |
|
|
|
|
| 164 |
def optimize(self, shape_dict, target_dict, target_normals):
|
| 165 |
self._init()
|
| 166 |
diff_model_cuda = self.diffusion_model
|
|
|
|
| 27 |
from utils.geometry import compute_operators, load_operators
|
| 28 |
from utils.surfaces import Surface
|
| 29 |
import sys
|
| 30 |
+
import spaces
|
| 31 |
|
| 32 |
try:
|
| 33 |
import google.colab
|
|
|
|
| 121 |
self.fmap_cfg = self.cfg.deepfeat_conf.fmap
|
| 122 |
self.dataloaders = dict()
|
| 123 |
|
| 124 |
+
@spaces.GPU
|
| 125 |
def _init(self):
|
| 126 |
cfg = self.cfg
|
| 127 |
self.fmap_model = DFMNet(self.cfg["deepfeat_conf"]["fmap"]).cuda()
|
|
|
|
| 138 |
self.eye = torch.eye(self.n_fmap).float().cuda()
|
| 139 |
self.eye.requires_grad = False
|
| 140 |
|
| 141 |
+
@spaces.GPU
|
| 142 |
def fmap(self, shape_dict, target_dict):
|
| 143 |
diff_model_cuda = self.diffusion_model
|
| 144 |
diff_model_cuda.net.cuda()
|
|
|
|
| 155 |
mask_12, mask_21 = None, None
|
| 156 |
return C12_pred, C12_obj, C21_pred, C21_obj, feat1, feat2, evecs_trans1, evecs_trans2, mask_12, mask_21
|
| 157 |
|
| 158 |
+
@spaces.GPU
|
| 159 |
def zo_shot(self, shape_dict, target_dict):
|
| 160 |
self._init()
|
| 161 |
evecs1, evecs2 = shape_dict["evecs"], target_dict["evecs"]
|
|
|
|
| 165 |
indKNN_new, _ = extract_p2p_torch_fmap(new_FM, evecs1, evecs2)
|
| 166 |
return new_FM, indKNN_new
|
| 167 |
|
| 168 |
+
@spaces.GPU
|
| 169 |
def optimize(self, shape_dict, target_dict, target_normals):
|
| 170 |
self._init()
|
| 171 |
diff_model_cuda = self.diffusion_model
|