Skip to content

depth_anything_3

depth_anything_3 #

Depth Anything 3, 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 (pi3.py repeats them for the same reason). The model runs at its own processing resolution; every output is resampled to the staged image's size.

python depth_anything_3.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/depth_anything_3.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_one(model, path, arguments.output)