Nodes/ComfyUI-DepthAnythingAccel/Estimate Depth (ONNX)
ComfyUI Node

Estimate Depth (ONNX)

Same picture as PyTorch, about 1.4× the speed

By PineCookie·Created a day ago·Updated a day ago· 0
Estimate Depth (ONNX)
  • onnx_model
  • image
  • depth

Identical node shape to the PyTorch estimator - an image in, a depth map out, nothing to configure. The difference is entirely in what's behind it, and if you set this up correctly you should not be able to tell the two outputs apart.

What it does

The front half is shared with every other backend in the pack: your image is patch-aligned to a multiple of 14 rather than squashed to a square, normalized with the ImageNet stats, and run through the ONNX session. The depth that comes back is min-max normalized per image, resized back to your original resolution, and expanded into three channels so it drops into ComfyUI's IMAGE type and wires straight into anything downstream.

The back half is where ONNX Runtime earns its keep. On CUDA the estimator skips the usual NumPy round trip: it allocates the output tensor on your device, binds both buffers into ORT by raw pointer, and runs on the session's creation stream. Because ComfyUI is itself pipelined, the code synchronizes the current stream against ORT's before handing over a pointer and again before you read the result - which is exactly the kind of detail that turns into a "my depth map has a stripe of garbage in frame 3 of a video" bug when it's missing.

Batch handling is per-sample (for sample in prepared), same as the PyTorch path, so a batch of four images just works - unlike TensorRT, whose engine profile this pack builds at batch 1.

Inputs, output, wiring

  • onnx_model - the DEPTHACCEL_ONNX_MODEL handle from Load Depth Model (ONNX), or chained straight off Export to ONNX / Fuse ONNX Attention in the same run.
  • image - the image to estimate on.

One output, depth, an IMAGE at your original resolution. Wire it to ControlNetApplyAdvanced with a depth ControlNet (weight 0.8–1.0 for strict layout matching, 0.4–0.7 when you want the composition guided but the details free, and consider an end-step around 0.5 so the ControlNet stops shaping the late detailing), to a Save Image to inspect it, or to a warp/parallax node. Relative depth - nearer versus farther, no metres - is what depth conditioning wants, which is the whole reason Depth Anything V2 Large has been the default preprocessor since 2024.

Speed, and why this is the version most people should run

From the pack's own measurements on an RTX 5070 Ti at 784×1176 FP16: Small 20.5 ms, Base 37.4 ms, Large 93.5 ms - against 29.1 / 51.0 / 127.3 ms for PyTorch and 7.5 / 16.5 / 47.3 ms for TensorRT. So ONNX is roughly 1.4× PyTorch, and TensorRT is another 2–2.7× on top.

The reason to stop here rather than go all the way: TensorRT asks you to build an engine, pin a resolution profile, and rebuild when you upgrade the runtime or change GPUs. ONNX asks you to export once. For still images the entire argument is academic - 127 ms versus 47 ms is not a thing you will feel. For a batch or a video pass, it adds up fast. ONNX is the sweet spot for a stills workflow that occasionally does fifty images in a row.

One correctness note

The resolution guard applies here too, but it reads the precision from the graph, not from a widget - an FP16 ONNX model gets the generous ~4.7MP budget, an FP32 one gets ~2.6MP. This is why the node sometimes tells you to use an FP16 ONNX backend when the PyTorch estimator turns your 2K image away: it's not a suggestion, it's the same budget table applied one layer down. And if you're ever suspicious of the accelerated output, run the same image through Estimate Depth (PyTorch) and diff them. All three backends are verified against the FP32 reference at correlation ≈ 1.0 and normalized error ≈ 1e-3, so a visible difference means something is actually wrong - wrong checkpoint, wrong precision expectation, or a fused graph you thought you were running but aren't.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/PineCookie/ComfyUI-DepthAnythingAccel
cd ComfyUI-DepthAnythingAccel
python -m pip install safetensors huggingface-hub onnxruntime-gpu

Manager: search DepthAnythingAccel. The pipeline:

[Load Depth Model (PyTorch)] → [Export to ONNX] → [Fuse ONNX Attention] → [Estimate Depth (ONNX)]

Drop the fuse step if you'd rather not deal with two files, or if you're heading to TensorRT instead - fused graphs can't be parsed by the TensorRT builder.

CategoryDepthAnythingAccel/ONNX

Inputs (2)

NameTypeDefaultDescription
onnx_modelDEPTHACCEL_ONNX_MODEL
imageIMAGE

Outputs (1)

NameTypeDescription
depthIMAGE