Skip to content

pi3

pi3 #

Pi3X, run by cgr.depth inside the GPU interpreter.

Only torch, numpy and PIL are imported here, never capturegraph: this is a standalone script, so its argument parsing, image loading and output writing are its own (depth_anything_3.py repeats them for the same reason). Pi3X is a multi-view model; without --multiview it is run one image at a time. It outputs no intrinsics, so the focal length is recovered from the local point map it predicts; the principal point is taken as the image centre.

python pi3.py --images DIR --weights DIR --output DIR [--multiview]

Reads NNNNN.<ext> from --images in sorted order and writes, per image, NNNNN.npy (float32 depth) and NNNNN_conf.npy (float32 confidence in [0, 1]) into --output. With --multiview the images are posed together and cameras.json (camera-to-world 4×4 and pixel intrinsics per image, OpenCV convention), points.npy (N×3 float32) and colors.npy (N×3 uint8) are written beside them.

main() #

Predict depth for every staged image and write the contract's outputs.

Source code in capturegraph-recipes/capturegraph_recipes/depth/models/drivers/pi3.py
def main() -> None:
    """Predict depth for every staged image and write the contract's outputs."""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--images", type=Path, required=True)
    parser.add_argument("--weights", type=Path, required=True)
    parser.add_argument("--output", type=Path, required=True)
    parser.add_argument("--multiview", action="store_true")
    arguments = parser.parse_args()
    arguments.output.mkdir(parents=True, exist_ok=True)
    paths = sorted(path for path in arguments.images.iterdir() if path.is_file())
    model = _load_model(arguments.weights)
    if arguments.multiview:
        _predict_together(model, paths, arguments.output)
    else:
        for path in paths:
            _predict_together(model, [path], arguments.output, with_cameras=False)