Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -150,12 +150,12 @@ pipeline = pipeline.to(device)
|
|
| 150 |
# load reconstruction model
|
| 151 |
print('Loading reconstruction model ...')
|
| 152 |
model_ckpt_path = hf_hub_download(repo_id="TencentARC/InstantMesh", filename="instant_mesh_large.ckpt", repo_type="model")
|
| 153 |
-
|
| 154 |
state_dict = torch.load(model_ckpt_path, map_location='cpu')['state_dict']
|
| 155 |
state_dict = {k[14:]: v for k, v in state_dict.items() if k.startswith('lrm_generator.') and 'source_camera' not in k}
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
|
| 160 |
print('Loading Finished!')
|
| 161 |
|
|
@@ -199,10 +199,10 @@ def generate_mvs(input_image, sample_steps, sample_seed):
|
|
| 199 |
# @spaces.GPU
|
| 200 |
def make3d(images):
|
| 201 |
|
| 202 |
-
global
|
| 203 |
if IS_FLEXICUBES:
|
| 204 |
-
|
| 205 |
-
|
| 206 |
|
| 207 |
images = np.asarray(images, dtype=np.float32) / 255.0
|
| 208 |
images = torch.from_numpy(images).permute(2, 0, 1).contiguous().float() # (3, 960, 640)
|
|
@@ -223,7 +223,7 @@ def make3d(images):
|
|
| 223 |
|
| 224 |
with torch.no_grad():
|
| 225 |
# get triplane
|
| 226 |
-
planes =
|
| 227 |
|
| 228 |
# # get video
|
| 229 |
# chunk_size = 20 if IS_FLEXICUBES else 1
|
|
@@ -255,7 +255,7 @@ def make3d(images):
|
|
| 255 |
# print(f"Video saved to {video_fpath}")
|
| 256 |
|
| 257 |
# get mesh
|
| 258 |
-
mesh_out =
|
| 259 |
planes,
|
| 260 |
use_texture_map=False,
|
| 261 |
**infer_config,
|
|
|
|
| 150 |
# load reconstruction model
|
| 151 |
print('Loading reconstruction model ...')
|
| 152 |
model_ckpt_path = hf_hub_download(repo_id="TencentARC/InstantMesh", filename="instant_mesh_large.ckpt", repo_type="model")
|
| 153 |
+
model0 = instantiate_from_config(model_config)
|
| 154 |
state_dict = torch.load(model_ckpt_path, map_location='cpu')['state_dict']
|
| 155 |
state_dict = {k[14:]: v for k, v in state_dict.items() if k.startswith('lrm_generator.') and 'source_camera' not in k}
|
| 156 |
+
model0.load_state_dict(state_dict, strict=True)
|
| 157 |
|
| 158 |
+
model0 = model0.to(device)
|
| 159 |
|
| 160 |
print('Loading Finished!')
|
| 161 |
|
|
|
|
| 199 |
# @spaces.GPU
|
| 200 |
def make3d(images):
|
| 201 |
|
| 202 |
+
global model0
|
| 203 |
if IS_FLEXICUBES:
|
| 204 |
+
model0.init_flexicubes_geometry(device, use_renderer=False)
|
| 205 |
+
model0 = model0.eval()
|
| 206 |
|
| 207 |
images = np.asarray(images, dtype=np.float32) / 255.0
|
| 208 |
images = torch.from_numpy(images).permute(2, 0, 1).contiguous().float() # (3, 960, 640)
|
|
|
|
| 223 |
|
| 224 |
with torch.no_grad():
|
| 225 |
# get triplane
|
| 226 |
+
planes = model0.forward_planes(images, input_cameras)
|
| 227 |
|
| 228 |
# # get video
|
| 229 |
# chunk_size = 20 if IS_FLEXICUBES else 1
|
|
|
|
| 255 |
# print(f"Video saved to {video_fpath}")
|
| 256 |
|
| 257 |
# get mesh
|
| 258 |
+
mesh_out = model0.extract_mesh(
|
| 259 |
planes,
|
| 260 |
use_texture_map=False,
|
| 261 |
**infer_config,
|