-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathdemo.py
More file actions
692 lines (629 loc) · 24.1 KB
/
Copy pathdemo.py
File metadata and controls
692 lines (629 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/usr/bin/env python3
"""
Modified from CUT3R: https://github.com/CUT3R/CUT3R
Online Human-Scene Reconstruction Inference and Visualization Script
This script performs inference using the ARCroco3DStereo model and visualizes the
resulting 3D scene point clouds and SMPLX sequences with the SceneHumanViewer.
Use the command-line arguments to adjust parameters
such as the model checkpoint path, image sequence directory, image size, device, etc.
Example:
python demo.py --model_path src/human3r_896L.pth --size 512 \
--seq_path examples/GoodMornin1.mp4 --subsample 1 --vis_threshold 2 \
--downsample_factor 1 --use_ttt3r --reset_interval 100
"""
import os
import numpy as np
import torch
import time
import glob
import random
import cv2
import argparse
import tempfile
import shutil
from copy import deepcopy
from add_ckpt_path import add_path_to_dust3r
import imageio.v2 as iio
import roma
# Set random seed for reproducibility.
random.seed(42)
def parse_args():
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(
description="Run 3D point cloud inference and visualization using ARCroco3DStereo."
)
parser.add_argument(
"--model_path",
type=str,
default="src/cut3r_512_dpt_4_64.pth",
help="Path to the pretrained model checkpoint.",
)
parser.add_argument(
"--seq_path",
type=str,
default="",
help="Path to the directory containing the image sequence.",
)
parser.add_argument(
"--device",
type=str,
default="cuda",
help="Device to run inference on (e.g., 'cuda' or 'cpu').",
)
parser.add_argument(
"--size",
type=int,
default="512",
help="Shape that input images will be rescaled to; if using 224+linear model, choose 224 otherwise 512",
)
parser.add_argument(
"--vis_threshold",
type=float,
default=1.5,
help="Visualization threshold for the viewer. Ranging from 1 to INF",
)
parser.add_argument(
"--msk_threshold",
type=float,
default=0.1,
help="Mask threshold. Ranging from 0 to 1",
)
parser.add_argument(
"--output_dir",
type=str,
default="./tmp",
help="value for tempfile.tempdir",
)
parser.add_argument(
"--save",
action="store_true",
help="Save output results.",
)
parser.add_argument(
"--render",
action="store_true",
help="Save smpl mesh projection.",
)
parser.add_argument(
"--render_video",
action="store_true",
help="Save smpl mesh projection video.",
)
parser.add_argument(
"--max_frames",
type=int,
default=None,
help="Max frames to use. Default is None (use all images).",
)
parser.add_argument(
"--subsample",
type=int,
default=1,
help="Subsample factor for input images. Default is 1 (use all images).",
)
parser.add_argument(
"--reset_interval",
type=int,
default=10000000
)
parser.add_argument(
"--use_ttt3r",
action="store_true",
help="Use TTT3R.",
default=False
)
parser.add_argument(
"--downsample_factor",
type=int,
default=10,
help="Point cloud downsample factor for the viewer",
)
parser.add_argument(
"--smpl_downsample",
type=int,
default=1,
help="SMPL sequence downsample factor for the viewer",
)
parser.add_argument(
"--camera_downsample",
type=int,
default=1,
help="Camera motion downsample factor for the viewer",
)
parser.add_argument(
"--mask_morph",
type=int,
default=10,
help="Mask morphology for the viewer",
)
return parser.parse_args()
def prepare_input(
img_paths,
img_mask,
size,
raymaps=None,
raymap_mask=None,
revisit=1,
update=True,
img_res=None,
reset_interval=100
):
"""
Prepare input views for inference from a list of image paths.
Args:
img_paths (list): List of image file paths.
img_mask (list of bool): Flags indicating valid images.
size (int): Target image size.
raymaps (list, optional): List of ray maps.
raymap_mask (list, optional): Flags indicating valid ray maps.
revisit (int): How many times to revisit each view.
update (bool): Whether to update the state on revisits.
Returns:
list: A list of view dictionaries.
"""
# Import image loader (delayed import needed after adding ckpt path).
from src.dust3r.utils.image import load_images, pad_image
from dust3r.utils.geometry import get_camera_parameters
images = load_images(img_paths, size=size)
if img_res is not None:
K_mhmr = get_camera_parameters(img_res, device="cpu") # if use pseudo K
views = []
if raymaps is None and raymap_mask is None:
# Only images are provided.
for i in range(len(images)):
view = {
"img": images[i]["img"],
"ray_map": torch.full(
(
images[i]["img"].shape[0],
6,
images[i]["img"].shape[-2],
images[i]["img"].shape[-1],
),
torch.nan,
),
"true_shape": torch.from_numpy(images[i]["true_shape"]),
"idx": i,
"instance": str(i),
"camera_pose": torch.from_numpy(
np.eye(4, dtype=np.float32)
).unsqueeze(0),
"img_mask": torch.tensor(True).unsqueeze(0),
"ray_mask": torch.tensor(False).unsqueeze(0),
"update": torch.tensor(True).unsqueeze(0),
"reset": torch.tensor((i+1) % reset_interval == 0).unsqueeze(0),
}
if img_res is not None:
view["img_mhmr"] = pad_image(view["img"], img_res)
view["K_mhmr"] = K_mhmr
views.append(view)
if (i+1) % reset_interval == 0:
overlap_view = deepcopy(view)
overlap_view["reset"] = torch.tensor(False).unsqueeze(0)
views.append(overlap_view)
else:
# Combine images and raymaps.
num_views = len(images) + len(raymaps)
assert len(img_mask) == len(raymap_mask) == num_views
assert sum(img_mask) == len(images) and sum(raymap_mask) == len(raymaps)
j = 0
k = 0
for i in range(num_views):
view = {
"img": (
images[j]["img"]
if img_mask[i]
else torch.full_like(images[0]["img"], torch.nan)
),
"ray_map": (
raymaps[k]
if raymap_mask[i]
else torch.full_like(raymaps[0], torch.nan)
),
"true_shape": (
torch.from_numpy(images[j]["true_shape"])
if img_mask[i]
else torch.from_numpy(np.int32([raymaps[k].shape[1:-1][::-1]]))
),
"idx": i,
"instance": str(i),
"camera_pose": torch.from_numpy(
np.eye(4, dtype=np.float32)
).unsqueeze(0),
"img_mask": torch.tensor(img_mask[i]).unsqueeze(0),
"ray_mask": torch.tensor(raymap_mask[i]).unsqueeze(0),
"update": torch.tensor(img_mask[i]).unsqueeze(0),
"reset": torch.tensor((i+1) % reset_interval == 0).unsqueeze(0),
}
if img_res is not None:
view["img_mhmr"] = pad_image(view["img"], img_res)
view["K_mhmr"] = K_mhmr
if img_mask[i]:
j += 1
if raymap_mask[i]:
k += 1
views.append(view)
if (i+1) % reset_interval == 0:
overlap_view = deepcopy(view)
overlap_view["reset"] = torch.tensor(False).unsqueeze(0)
views.append(overlap_view)
assert j == len(images) and k == len(raymaps)
if revisit > 1:
new_views = []
for r in range(revisit):
for i, view in enumerate(views):
new_view = deepcopy(view)
new_view["idx"] = r * len(views) + i
new_view["instance"] = str(r * len(views) + i)
if r > 0 and not update:
new_view["update"] = torch.tensor(False).unsqueeze(0)
new_views.append(new_view)
return new_views
return views
def prepare_output(
outputs, outdir, revisit=1, use_pose=True,
save=False, render=False, render_video=False, img_res=None, subsample=1):
"""
Process inference outputs to generate point clouds and camera parameters for visualization.
Args:
outputs (dict): Inference outputs.
revisit (int): Number of revisits per view.
use_pose (bool): Whether to transform points using camera pose.
save (bool): Whether to save output results.
render (bool): Whether to save smpl mesh projection.
render_video (bool): Whether to save smpl mesh projection video.
"""
from src.dust3r.utils.camera import pose_encoding_to_camera
from src.dust3r.post_process import estimate_focal_knowing_depth
from src.dust3r.utils.geometry import geotrf, matrix_cumprod
from src.dust3r.utils import SMPL_Layer, vis_heatmap, render_meshes
from src.dust3r.utils.image import unpad_image
from viser_utils import get_color
# Only keep the outputs corresponding to one full pass.
valid_length = len(outputs["pred"]) // revisit
outputs["pred"] = outputs["pred"][-valid_length:]
outputs["views"] = outputs["views"][-valid_length:]
# delet overlaps: reset_mask=True outputs["pred"] and outputs["views"]
reset_mask = torch.cat([view["reset"] for view in outputs["views"]], 0)
shifted_reset_mask = torch.cat([torch.tensor(False).unsqueeze(0), reset_mask[:-1]], dim=0)
outputs["pred"] = [
pred for pred, mask in zip(outputs["pred"], shifted_reset_mask) if not mask]
outputs["views"] = [
view for view, mask in zip(outputs["views"], shifted_reset_mask) if not mask]
reset_mask = reset_mask[~shifted_reset_mask]
pts3ds_self_ls = [output["pts3d_in_self_view"] for output in outputs["pred"]]
pts3ds_other = [output["pts3d_in_other_view"] for output in outputs["pred"]]
conf_self = [output["conf_self"] for output in outputs["pred"]]
conf_other = [output["conf"] for output in outputs["pred"]]
pts3ds_self = torch.cat(pts3ds_self_ls, 0)
# Recover camera poses.
pr_poses = [
pose_encoding_to_camera(pred["camera_pose"].clone()).cpu()
for pred in outputs["pred"]
]
# reset_mask = torch.cat([view["reset"] for view in outputs["views"]], 0)
if reset_mask.any():
pr_poses = torch.cat(pr_poses, 0)
identity = torch.eye(4, device=pr_poses.device)
reset_poses = torch.where(reset_mask.unsqueeze(-1).unsqueeze(-1), pr_poses, identity)
cumulative_bases = matrix_cumprod(reset_poses)
shifted_bases = torch.cat([identity.unsqueeze(0), cumulative_bases[:-1]], dim=0)
pr_poses = torch.einsum('bij,bjk->bik', shifted_bases, pr_poses)
# keeps only reset_mask=False pr_poses
pr_poses = list(pr_poses.unsqueeze(1).unbind(0))
R_c2w = torch.cat([pr_pose[:, :3, :3] for pr_pose in pr_poses], 0)
t_c2w = torch.cat([pr_pose[:, :3, 3] for pr_pose in pr_poses], 0)
if use_pose:
transformed_pts3ds_other = []
for pose, pself in zip(pr_poses, pts3ds_self):
transformed_pts3ds_other.append(geotrf(pose, pself.unsqueeze(0)))
pts3ds_other = transformed_pts3ds_other
conf_other = conf_self
# Estimate focal length based on depth.
B, H, W, _ = pts3ds_self.shape
pp = torch.tensor([W // 2, H // 2], device=pts3ds_self.device).float().repeat(B, 1)
focal = estimate_focal_knowing_depth(pts3ds_self, pp, focal_mode="weiszfeld")
colors = [
0.5 * (output["img"].permute(0, 2, 3, 1) + 1.0) for output in outputs["views"]
]
cam_dict = {
"focal": focal.numpy(),
"pp": pp.numpy(),
"R": R_c2w.numpy(),
"t": t_c2w.numpy(),
}
pts3ds_self_tosave = pts3ds_self # B, H, W, 3
depths_tosave = pts3ds_self_tosave[..., 2]
pts3ds_other_tosave = torch.cat(pts3ds_other) # B, H, W, 3
conf_self_tosave = torch.cat(conf_self) # B, H, W
conf_other_tosave = torch.cat(conf_other) # B, H, W
colors_tosave = torch.cat(
[
0.5 * (output["img"].permute(0, 2, 3, 1) + 1.0)
for output in outputs["views"]
]
) # [B, H, W, 3]
cam2world_tosave = torch.cat(pr_poses) # B, 4, 4
intrinsics_tosave = (
torch.eye(3).unsqueeze(0).repeat(cam2world_tosave.shape[0], 1, 1)
) # B, 3, 3
intrinsics_tosave[:, 0, 0] = focal.detach()
intrinsics_tosave[:, 1, 1] = focal.detach()
intrinsics_tosave[:, 0, 2] = pp[:, 0]
intrinsics_tosave[:, 1, 2] = pp[:, 1]
# get SMPL parameters from outputs
smpl_shape = [output.get(
"smpl_shape", torch.empty(1,0,10))[0] for output in outputs["pred"]]
smpl_rotvec = [roma.rotmat_to_rotvec(
output.get(
"smpl_rotmat", torch.empty(1,0,53,3,3))[0]) for output in outputs["pred"]]
smpl_transl = [output.get(
"smpl_transl", torch.empty(1,0,3))[0] for output in outputs["pred"]]
smpl_expression = [output.get(
"smpl_expression", [None])[0] for output in outputs["pred"]]
smpl_id = [output.get(
"smpl_id", torch.empty(1,0))[0] for output in outputs["pred"]]
# smpl_loc = [output.get(
# "smpl_loc", torch.empty(1,0,2))[0] for output in outputs["pred"]]
# K_mhmr = [output.get(
# "K_mhmr", torch.empty(1,0,3))[0] for output in outputs["views"]]
if render or save:
smpl_scores = [
output.get("smpl_scores", torch.zeros(1, H, W, 1))[...,0] for output in outputs["pred"]]
if img_res is not None:
smpl_scores = [
unpad_image(s, [H, W])[0] for s in smpl_scores]
has_mask = "msk" in outputs["pred"][0]
if has_mask:
msks = [output["msk"][...,0] for output in outputs["pred"]]
if img_res is not None:
msks = [unpad_image(m, [H, W]) for m in msks]
else:
msks = [torch.zeros(1, H, W) for _ in range(B)]
# SMPL layer
smpl_layer = SMPL_Layer(type='smplx',
gender='neutral',
num_betas=smpl_shape[0].shape[-1],
kid=False,
person_center='head')
smpl_faces = smpl_layer.bm_x.faces
if save:
print(f"Saving output to {outdir}...")
os.makedirs(os.path.join(outdir, "depth"), exist_ok=True)
os.makedirs(os.path.join(outdir, "conf"), exist_ok=True)
os.makedirs(os.path.join(outdir, "color"), exist_ok=True)
os.makedirs(os.path.join(outdir, "camera"), exist_ok=True)
os.makedirs(os.path.join(outdir, "smpl"), exist_ok=True)
all_verts = []
for f_id in range(B):
n_humans_i = smpl_shape[f_id].shape[0]
if n_humans_i > 0:
with torch.no_grad():
smpl_out = smpl_layer(
smpl_rotvec[f_id],
smpl_shape[f_id],
smpl_transl[f_id],
None, None,
K=intrinsics_tosave[f_id].expand(n_humans_i, -1 , -1),
expression=smpl_expression[f_id])
depth = depths_tosave[f_id].numpy()
conf = conf_self_tosave[f_id].numpy()
color = colors_tosave[f_id].numpy()
c2w = cam2world_tosave[f_id].numpy()
intrins = intrinsics_tosave[f_id].numpy()
if n_humans_i > 0:
# transform smpl verts to world coordinates
all_verts.append(geotrf(pr_poses[f_id], smpl_out['smpl_v3d'].unsqueeze(0))[0])
pr_verts = [t.numpy() for t in smpl_out['smpl_v3d'].unbind(0)]
pr_faces = [smpl_faces] * n_humans_i
else:
pr_verts = []
pr_faces = []
all_verts.append(torch.empty(0))
if render:
hm = vis_heatmap(colors_tosave[f_id], smpl_scores[f_id]).numpy()
img_array_np = (color * 255).astype(np.uint8)
smpl_rend = render_meshes(img_array_np.copy(), pr_verts, pr_faces,
{'focal': intrins[[0,1],[0,1]],
'princpt': intrins[[0,1],[-1,-1]]},
color=[get_color(i)/255 for i in smpl_id[f_id]])
if has_mask:
msk_array_np = vis_heatmap(colors_tosave[f_id], msks[f_id][0]).numpy()
color_smpl = np.concatenate([
img_array_np,
(msk_array_np * 255).astype(np.uint8),
(hm * 255).astype(np.uint8),
smpl_rend], 1)
else:
color_smpl = np.concatenate([
img_array_np,
(hm * 255).astype(np.uint8),
smpl_rend], 1)
if save:
np.save(os.path.join(outdir, "depth", f"{f_id:06d}.npy"), depth)
np.save(os.path.join(outdir, "conf", f"{f_id:06d}.npy"), conf)
iio.imwrite(
os.path.join(outdir, "color", f"{f_id:06d}.png"),
(color * 255).astype(np.uint8),
)
np.savez(
os.path.join(outdir, "camera", f"{f_id:06d}.npz"),
pose=c2w,
intrinsics=intrins,
)
np.savez(
os.path.join(outdir, "smpl", f"{f_id:06d}.npz"),
scores=smpl_scores[f_id].numpy(),
msk=msks[f_id].numpy() if has_mask else None,
shape=smpl_shape[f_id].numpy(),
rotvec=smpl_rotvec[f_id].numpy(),
transl=smpl_transl[f_id].numpy(),
expression=smpl_expression[f_id].numpy() if smpl_expression[f_id] is not None else None
)
# Save smpl projection
if render:
os.makedirs(os.path.join(outdir, "color_smpl"), exist_ok=True)
iio.imwrite(
os.path.join(outdir, "color_smpl", f"{f_id:06d}.png"),
color_smpl,
)
if render and render_video:
print(f"Saving smpl mesh projection to {outdir}...")
frames_dir = os.path.join(outdir, "color_smpl")
video_path = os.path.join(outdir, "output_video.mp4")
output_fps = 30 // subsample
os.system(f'/usr/bin/ffmpeg -y -framerate {output_fps} -i "{frames_dir}/%06d.png" '
f'-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" '
f'-vcodec h264 -preset fast -profile:v baseline -pix_fmt yuv420p '
f'-movflags +faststart -b:v 5000k "{video_path}"')
return (
pts3ds_other,
colors,
conf_other,
cam_dict,
all_verts,
smpl_faces,
smpl_id,
msks
)
def parse_seq_path(p):
if os.path.isdir(p):
img_paths = sorted(glob.glob(f"{p}/*"))
tmpdirname = None
else:
cap = cv2.VideoCapture(p)
if not cap.isOpened():
raise ValueError(f"Error opening video file {p}")
video_fps = cap.get(cv2.CAP_PROP_FPS)
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
if video_fps == 0:
cap.release()
raise ValueError(f"Error: Video FPS is 0 for {p}")
frame_interval = 1
frame_indices = list(range(0, total_frames, frame_interval))
print(
f" - Video FPS: {video_fps}, Frame Interval: {frame_interval}, Total Frames to Read: {len(frame_indices)}"
)
img_paths = []
tmpdirname = tempfile.mkdtemp()
for i in frame_indices:
cap.set(cv2.CAP_PROP_POS_FRAMES, i)
ret, frame = cap.read()
if not ret:
break
frame_path = os.path.join(tmpdirname, f"frame_{i}.jpg")
cv2.imwrite(frame_path, frame)
img_paths.append(frame_path)
cap.release()
return img_paths, tmpdirname
def run_inference(args):
"""
Execute the full inference and visualization pipeline.
Args:
args: Parsed command-line arguments.
"""
# Set up the computation device.
device = args.device
if device == "cuda" and not torch.cuda.is_available():
print("CUDA not available. Switching to CPU.")
device = "cpu"
# Add the checkpoint path (required for model imports in the dust3r package).
add_path_to_dust3r(args.model_path)
# Import model and inference functions after adding the ckpt path.
from src.dust3r.inference import inference_recurrent_lighter
from src.dust3r.model import ARCroco3DStereo
from viser_utils import SceneHumanViewer
# Prepare image file paths.
img_paths, tmpdirname = parse_seq_path(args.seq_path)
if not img_paths:
print(f"No images found in {args.seq_path}. Please verify the path.")
return
if args.max_frames is not None:
img_paths = img_paths[:args.max_frames]
img_paths = img_paths[::args.subsample]
print(f"Found {len(img_paths)} images in {args.seq_path}.")
img_mask = [True] * len(img_paths)
# Load and prepare the model.
print(f"Loading model from {args.model_path}...")
model = ARCroco3DStereo.from_pretrained(args.model_path).to(device)
model.eval()
# Prepare input views.
print("Preparing input views...")
img_res = getattr(model, 'mhmr_img_res', None)
views = prepare_input(
img_paths=img_paths,
img_mask=img_mask,
size=args.size,
revisit=1,
update=True,
img_res=img_res,
reset_interval=args.reset_interval
)
if tmpdirname is not None:
shutil.rmtree(tmpdirname)
# Run inference.
print("Running inference...")
start_time = time.time()
outputs, _ = inference_recurrent_lighter(
views, model, device, use_ttt3r=args.use_ttt3r)
total_time = time.time() - start_time
per_frame_time = total_time / len(views)
print(
f"Inference completed in {total_time:.2f} seconds (average {per_frame_time:.2f} s per frame)."
)
# Process outputs for visualization.
print("Preparing output for visualization...")
(
pts3ds_other,
colors,
conf,
cam_dict,
all_smpl_verts,
smpl_faces,
smpl_id,
msks,
) = prepare_output(
outputs, args.output_dir, 1, True,
args.save, args.render, args.render_video, img_res, args.subsample
)
# Convert tensors to numpy arrays for visualization.
pts3ds_to_vis = [p.cpu().numpy() for p in pts3ds_other]
colors_to_vis = [c.cpu().numpy() for c in colors]
msks_to_vis = [m.cpu().numpy() for m in msks]
conf_to_vis = [c.cpu().numpy() for c in conf]
edge_colors = [None] * len(pts3ds_to_vis)
verts_to_vis = [p.cpu().numpy() for p in all_smpl_verts]
# Create and run the point cloud viewer.
print("Launching Human3R viewer...")
viewer = SceneHumanViewer(
pts3ds_to_vis,
colors_to_vis,
conf_to_vis,
cam_dict,
verts_to_vis,
smpl_faces,
smpl_id,
msks_to_vis,
device=device,
edge_color_list=edge_colors,
show_camera=True,
vis_threshold=args.vis_threshold,
msk_threshold=args.msk_threshold,
mask_morph=args.mask_morph,
size = args.size,
downsample_factor=args.downsample_factor,
smpl_downsample_factor=args.smpl_downsample,
camera_downsample_factor=args.camera_downsample
)
viewer.run()
def main():
args = parse_args()
if not args.seq_path:
print(
"No inputs found! Please use our gradio demo if you would like to iteractively upload inputs."
)
return
else:
run_inference(args)
if __name__ == "__main__":
main()