MCPcopy Create free account
hub / github.com/apple/ml-sharp / predict_cli

Function predict_cli

src/sharp/cli/predict.py:76–155  ·  view source on GitHub ↗

Predict Gaussians from input images.

(
    input_path: Path,
    output_path: Path,
    checkpoint_path: Path,
    with_rendering: bool,
    device: str,
    verbose: bool,
)

Source from the content-addressed store, hash-verified

74)
75@click.option("-v", "--verbose", is_flag=True, help="Activate debug logs.")
76def predict_cli(
77 input_path: Path,
78 output_path: Path,
79 checkpoint_path: Path,
80 with_rendering: bool,
81 device: str,
82 verbose: bool,
83):
84 """Predict Gaussians from input images."""
85 logging_utils.configure(logging.DEBUG if verbose else logging.INFO)
86
87 extensions = io.get_supported_image_extensions()
88
89 image_paths = []
90 if input_path.is_file():
91 if input_path.suffix in extensions:
92 image_paths = [input_path]
93 else:
94 for ext in extensions:
95 image_paths.extend(list(input_path.glob(f"**/*{ext}")))
96
97 if len(image_paths) == 0:
98 LOGGER.info("No valid images found. Input was %s.", input_path)
99 return
100
101 LOGGER.info("Processing %d valid image files.", len(image_paths))
102
103 if device == "default":
104 if torch.cuda.is_available():
105 device = "cuda"
106 elif torch.mps.is_available():
107 device = "mps"
108 else:
109 device = "cpu"
110 LOGGER.info("Using device %s", device)
111
112 if with_rendering and device != "cuda":
113 LOGGER.warning("Can only run rendering with gsplat on CUDA. Rendering is disabled.")
114 with_rendering = False
115
116 # Load or download checkpoint
117 if checkpoint_path is None:
118 LOGGER.info("No checkpoint provided. Downloading default model from %s", DEFAULT_MODEL_URL)
119 state_dict = torch.hub.load_state_dict_from_url(DEFAULT_MODEL_URL, progress=True)
120 else:
121 LOGGER.info("Loading checkpoint from %s", checkpoint_path)
122 state_dict = torch.load(checkpoint_path, weights_only=True)
123
124 gaussian_predictor = create_predictor(PredictorParams())
125 gaussian_predictor.load_state_dict(state_dict)
126 gaussian_predictor.eval()
127 gaussian_predictor.to(device)
128
129 output_path.mkdir(exist_ok=True, parents=True)
130
131 for image_path in image_paths:
132 LOGGER.info("Processing %s", image_path)
133 image, _, f_px = io.load_rgb(image_path)

Callers

nothing calls this directly

Calls 7

create_predictorFunction · 0.90
PredictorParamsClass · 0.90
save_plyFunction · 0.90
SceneMetaDataClass · 0.90
predict_imageFunction · 0.85
render_gaussiansFunction · 0.85
toMethod · 0.80

Tested by

no test coverage detected