MCPcopy Create free account
hub / github.com/Inception3D/TTT3R / run_inference

Function run_inference

demo.py:419–509  ·  view source on GitHub ↗

Execute the full inference and visualization pipeline. Args: args: Parsed command-line arguments.

(args)

Source from the content-addressed store, hash-verified

417
418
419def run_inference(args):
420 """
421 Execute the full inference and visualization pipeline.
422
423 Args:
424 args: Parsed command-line arguments.
425 """
426 # Set up the computation device.
427 device = args.device
428 if device == "cuda" and not torch.cuda.is_available():
429 print("CUDA not available. Switching to CPU.")
430 device = "cpu"
431
432 # Add the checkpoint path (required for model imports in the dust3r package).
433 add_path_to_dust3r(args.model_path)
434
435 # Import model and inference functions after adding the ckpt path.
436 from src.dust3r.inference import inference, inference_recurrent, inference_recurrent_lighter
437 from src.dust3r.model import ARCroco3DStereo
438 from viser_utils import PointCloudViewer
439
440 # Prepare image file paths.
441 img_paths, tmpdirname = parse_seq_path(args.seq_path, args.frame_interval)
442 if not img_paths:
443 print(f"No images found in {args.seq_path}. Please verify the path.")
444 return
445
446 print(f"Found {len(img_paths)} images in {args.seq_path}.")
447 img_mask = [True] * len(img_paths)
448
449 # Prepare input views.
450 print("Preparing input views...")
451 views = prepare_input(
452 img_paths=img_paths,
453 img_mask=img_mask,
454 size=args.size,
455 revisit=1,
456 update=True,
457 reset_interval=args.reset_interval
458 )
459 if tmpdirname is not None:
460 shutil.rmtree(tmpdirname)
461
462 # Load and prepare the model.
463 print(f"Loading model from {args.model_path}...")
464 model = ARCroco3DStereo.from_pretrained(args.model_path).to(device)
465 model.config.model_update_type = args.model_update_type
466
467 model.eval()
468
469 # Run inference.
470 print("Running inference...")
471 start_time = time.time()
472 outputs, state_args = inference_recurrent_lighter(views, model, device)
473
474 total_time = time.time() - start_time
475 per_frame_time = total_time / len(views)
476 FPS_num = 1 / per_frame_time

Callers 1

mainFunction · 0.85

Calls 9

runMethod · 0.95
add_path_to_dust3rFunction · 0.90
PointCloudViewerClass · 0.90
parse_seq_pathFunction · 0.85
from_pretrainedMethod · 0.80
prepare_inputFunction · 0.70
prepare_outputFunction · 0.70
printFunction · 0.50

Tested by

no test coverage detected