Configuration Parsing Warning:Invalid JSON for config file config.json

C-Fast-FoundationStereo for AX650

C-Fast-FoundationStereo is NVIDIA's real-time zero-shot stereo matching model (EdgeNeXt student backbone + CNN/transformer matching + a small convGRU refinement module, 14.6M parameters). Given a rectified binocular stereo pair, it predicts a per-pixel disparity map. Disparity can be converted to metric depth with Z = f_px * baseline / disparity, where f_px and disparity use the same image scale.

This repository provides AX650-ready artifacts produced with Pulsar2 8.0, along with an FP32 ONNX reference and standalone inference scripts. All spatial sizes are multiples of 32, so no padding is required at runtime.

Quick start

Run a single rectified stereo pair using the sample images (left.png, right.png) included in this repository:

  • On AX650 board (axengine):
python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left left.png \
    --right right.png \
    --output results/board_480x640
  • On host (onnxruntime, FP32 reference):
python3 infer/infer_onnx.py \
    --model c-fast-foundationstereo_480x640_maxdisp256_iters16.onnx \
    --left left.png \
    --right right.png \
    --output results/onnx_480x640 \
    --dump-npz

Available artifacts & performance summary (AX650)

Measured with ax_run_model on AX650 in NPU3 mode (3 Core, VNPU disabled), warmup 3, repeat 100, batch auto, parallel off (Pulsar2 8.0 e9a1aa15, engine 2.13.0sp). Latency is the median over 100 runs; CMM usage is the model's reported cmm size (1 MiB = 1,048,576 bytes).

AXModel builds (U16, NPU3)

File Build Median NPU latency CMM usage
c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel 480×640, max_disp=120, 16 iters, U16 887.065 ms 424.3 MiB
c-fast_foundationstereo_800x800_maxdisp150_iters12_u16_npu3_ax650.axmodel 800×800, max_disp=150, 12 iters, U16 1662.377 ms 719.9 MiB
c-fast_foundationstereo_960x960_maxdisp180_iters12_u16_npu3_ax650.axmodel 960×960, max_disp=180, 12 iters, U16 2387.193 ms 1343.1 MiB
c-fast_foundationstereo_960x960_maxdisp384_iters12_u16_npu3_ax650.axmodel 960×960, max_disp=384, 12 iters, U16 3055.711 ms 1737.0 MiB
c_fast_foundationstereo_960x960_maxdisp416_iters12_u16_npu3_ax650.axmodel 960×960, max_disp=416, 12 iters, U16 3319.064 ms 1855.9 MiB

Pay attention to the filename prefix when copying commands: the maxdisp416 build uses c_fast_... (underscore), whereas the other four builds use c-fast_... (hyphen).

ONNX reference

  • c-fast-foundationstereo_480x640_maxdisp256_iters16.onnx — FP32 reference (480×640, max_disp=256, 16 iters).

Model interface

ONNX (FP32 reference, 480×640 / 256 / 16)

Tensor Shape Type Layout / meaning
left_image [1, 3, 480, 640] float32 NCHW, RGB, ImageNet-normalized
right_image [1, 3, 480, 640] float32 NCHW, RGB, ImageNet-normalized
disparity [1, 1, 480, 640] float32 disparity in pixels at model-input scale

The ONNX model uses opset 17 / IR 8 and has 6432 nodes. Normalize with (pixel / 255 - mean) / std, mean = [0.485, 0.456, 0.406], std = [0.229, 0.224, 0.225].

AXModel (U16, NPU3)

Tensor Shape Type Layout / meaning
left_image [1, H, W, 3] uint8 NHWC, RGB
right_image [1, H, W, 3] uint8 NHWC, RGB
disparity [1, 1, H, W] float32 disparity in pixels at model-input scale

H×W is the resolution in the filename. The AXModel has the ImageNet normalization and the NHWC→NCHW conversion fused into its input processors, so feed uint8 RGB directly. The output is dequantized to float32 by the runtime. The authoritative input dtype and layout are what session.get_inputs() reports on the board; the contract above is what these files were built with.

Usage

Single-pair output naming difference: infer/infer_axmodel.py saves files as <left_stem>__<right_stem>.disparity.{npy,png} (and .npz), e.g. left__right.disparity.npy. infer/infer_onnx.py preserves the left filename as <left.name>.disparity.{npy,png} (and .npz), e.g. left.png.npz.

Python (axengine, on the board)

infer/infer_axmodel.py is a standalone board-side script: it imports nothing else from this repository, so you can copy the script next to the .axmodel and your images. It needs the AX650 runtime axengine plus opencv-python, numpy and tqdm.

The script reads the real input contract from session.get_inputs(). For these U16 builds (uint8 NHWC RGB) it resizes to the model's fixed input size and sends the uint8 image directly, because normalization is fused into the model. If a build exposes float32 NCHW inputs instead, it applies ImageNet normalization automatically. Inputs must be a rectified pair of the same size; the script does not rectify.

Single pair (always writes disparity, visualization and timing):

python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left left.png \
    --right right.png \
    --output results/board_480x640

It prints NPU inference time, CPU processing time, end-to-end time and per-stage timings, and writes <left_stem>__<right_stem>.disparity.npy, <left_stem>__<right_stem>.disparity.png and npu_timing.json. Add --dump-npz to also save the raw model output as <left_stem>__<right_stem>.npz.

Dataset (pairs are matched by relative path, progress shown with tqdm):

python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left data/left \
    --right data/right \
    --output results/board_dataset

By default this is a fast performance mode: it measures read / preprocess / npu / diagnostics and writes only npu_timing.json. Add --full-output to also restore the disparity to the original image size, draw the visualization and write the per-pair *.disparity.npy, *.disparity.png and *.npz. --limit N processes only the first N pairs.

Compare against the host FP32 reference:

# single pair: --ref-npz is a file
python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left left.png --right right.png \
    --output results/board_check \
    --ref-npz results/onnx_480x640/left.png.npz

# dataset: --ref-npz is a directory of same-relative-path .npz files
python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left data/left --right data/right \
    --output results/board_check \
    --ref-npz results/onnx_dataset --full-output

The comparison reports max / mean / p99 absolute disparity error in model-input pixels. Use the same input size and preprocessing on both sides.

Option Meaning
--axmodel compiled .axmodel (required)
--left, --right rectified pair: two files or two directories with matching relative paths (required)
--output result directory (required)
--color-order rgb (default) or bgr; these files were built for RGB
--warmup warmup runs excluded from timing, default 1
--limit dataset mode only; process the first N pairs
--full-output dataset mode only; enable disparity restore, visualization and file output
--debug print input/output shape, dtype, min, max, mean and NaN/Inf counts
--dump-npz single-pair mode only; save the raw disparity NPZ
--ref-npz reference NPZ file (single) or directory (dataset); dataset requires --full-output

Single-image timings include the runtime's first-execution overhead; use dataset mode for performance numbers.

ONNX Runtime

infer/infer_onnx.py is the host-side FP32 reference script and is also standalone. It requires onnxruntime, opencv-python, numpy and tqdm:

pip install onnxruntime opencv-python numpy tqdm

Single pair:

python3 infer/infer_onnx.py \
    --model c-fast-foundationstereo_480x640_maxdisp256_iters16.onnx \
    --left left.png \
    --right right.png \
    --output results/onnx_480x640 \
    --dump-npz

The model has a fixed 480×640 input, so --height/--width are optional here; if you pass them they must match the model and be multiples of 32. The script resizes to the target size, replicate-pads to a multiple of 32 when needed, converts BGR→RGB, applies (pixel / 255 - mean) / std with the ImageNet mean/std and runs float32 NCHW. It restores the disparity by removing padding, resizing to the original image size and scaling by original_width / resized_width. Outputs are <left.name>.disparity.npy, <left.name>.disparity.png, optionally <left.name>.npz, and host_timing.json.

Dataset:

python3 infer/infer_onnx.py \
    --model c-fast-foundationstereo_480x640_maxdisp256_iters16.onnx \
    --left data/left \
    --right data/right \
    --output results/onnx_dataset

Like the board script, dataset mode is fast by default (timing only, no per-pair files). Add --full-output to write disparity, visualization and NPZ for every pair. The built-in default --output is derived from the script location and may not be what you expect, so pass --output explicitly.

Compare two runs:

python3 infer/infer_onnx.py \
    --model c-fast-foundationstereo_480x640_maxdisp256_iters16.onnx \
    --left left.png --right right.png \
    --output results/onnx_check \
    --dump-npz \
    --ref-npz results/onnx_480x640/left.png.npz

--ref-npz is a file in single-pair mode and a directory in dataset mode; dataset comparison requires --full-output.

Option Meaning
--model FP32 ONNX file (required)
--left, --right rectified pair: two files or two directories (required)
--output result directory; the default is derived from the script location, pass it explicitly
--height, --width optional resize size; must be given together and be multiples of 32
--warmup warmup runs excluded from timing, default 1
--full-output dataset mode only; enable disparity restore, visualization and file output
--debug print input/output statistics
--dump-npz save the raw disparity NPZ (dataset --full-output always saves it)
--ref-npz reference NPZ file (single) or directory (dataset)

Both scripts write their timing report (npu_timing.json or host_timing.json) with per-stage mean / p50 / p90 / p99 values, the detected input contract, FPS and per-sample results. Stage names are read, preprocess, npu (ONNX: onnx), diagnostics, postprocess, visualize, write and total; stages skipped in fast mode stay at zero.

Board demo (AX650)

A captured run on an AX650 board with the 480×640, max_disp=120, 16-iteration U16 build (a different variant from the 256/16 ONNX reference, exposing the same interface and running with the same standalone script):

python3 infer/infer_axmodel.py \
    --axmodel c-fast_foundationstereo_480x640_maxdisp120_iters16_u16_npu3_ax650.axmodel \
    --left left.png \
    --right right.png \
    --output results/sample

Key console output:

输入契约: [('left_image', (480, 640), 'NHWC', 'uint8'), ('right_image', (480, 640), 'NHWC', 'uint8')]
输出契约: [('disparity', [1, 1, 480, 640])]
输入尺寸: (480, 640),颜色顺序: rgb
U8 输入:归一化由 axmodel input_processors 完成
NPU 推理: 889.31 ms;CPU 处理: 1048.96 ms;端到端: 1049.03 ms(单图含首次执行开销;性能请用目录模式)
原图视差: min=26.332 max=119.980 mean=83.566 px

This run writes results/sample/left__right.disparity.npy and results/sample/left__right.disparity.png. The panel below is the output from this 480×640 / max_disp=120 / 16-iteration U16 build, showing the rectified left image next to the predicted disparity colormap.

Rectified left image and predicted disparity

The contract above is auto-detected from session.get_inputs() / session.get_outputs(). For this U16 build it is uint8 NHWC RGB: the ImageNet normalization and the NHWC→NCHW conversion are fused into the input processors, so the script feeds the uint8 image directly and only the output is dequantized to float32.

Downloads last month
23
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for AXERA-TECH/c-fast-foundationstereo

Quantized
(1)
this model