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

Estimate Depth (TensorRT)

7.5 ms a frame, and one profile-shaped trap

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

Same two inputs, same depth map out. What's different is that this is the fastest depth estimation this pack can do, and the one where a resolution mistake produces a specific, loud error rather than a slow render.

What it does

Identical preprocessing to the other two estimators - patch-align to a multiple of 14, ImageNet normalization, run, min-max normalize per image, resize back to your original resolution, expand to three channels. That consistency is the point: swap backends and the picture shouldn't change. On the pack's measurements all three land at correlation ≈ 1.0 against the FP32 reference with normalized error around 1e-3, which is why you can move a working graph from PyTorch to TensorRT without re-tuning your ControlNet weight.

The difference is underneath. The engine runs on its own CUDA stream, and the node orders the work explicitly: it makes the engine's stream wait on the PyTorch stream that filled the input buffer, executes, then makes the current stream wait on the engine's output. Without that handshake you'd get a half-written input or a not-yet-finished output the moment ComfyUI pipelined two nodes - the classic way an accelerated backend works in a test script and glitches in a video workflow.

Inputs, output, wiring

  • trt_model - the handle from Load Depth Model (TensorRT) or straight off Build TensorRT Engine in the same run.
  • image - the image to estimate on.

One output: depth, an IMAGE at original resolution. Feed it into ControlNetApplyAdvanced with a depth ControlNet - weight around 0.8 if you need the spatial layout matched closely, 0.4–0.7 when you want the depth to set composition and let the prompt do the rest - into a saver, or into a parallax node. Relative depth (nearer versus farther, not absolute distance) is the right input for control, and it's what has kept Depth Anything V2 the ecosystem's default preprocessor.

The profile is your resolution limit

There's no megapixel guard on this node, because there doesn't need to be: the engine's optimization profile is the wall. Inputs must land inside [Min W, Max W] and [Min H, Max H] as you set them on the builder, and the aligned shape is what gets checked - remember the image gets floored to a multiple of 14 first, so the comparison happens one rounding step after what you typed.

With the default 2016×2016 ceiling, a 2048-wide image is rejected. Not because 2048 is huge, but because 2048 floors to 2044, which is over the profile. Your options are to resize to something under the ceiling, or rebuild with a bigger Max W. Raise it too far and you're just making the engine slower and bigger for shapes you'll never use.

And yes, alignment cuts the other way too: because the estimator runs the aligned shape, an engine profiled to 2016 handles an honest 2016 input with no interpolation at all - if your source is already a 14-multiple, the native-resolution promise is literally true and nothing gets resampled.

The other structural limit is batch. The profile this pack builds is batch 1, so the estimator loops one sample at a time and a five-image batch runs five sequential inferences. That's fine - it's still faster end-to-end than the alternatives - but it means TensorRT's advantage is per-image, not parallel.

Is it worth the build?

At 784×1176 FP16 the numbers are Small 7.5 ms, Base 16.5 ms, Large 47.3 ms, against 20.5 / 37.4 / 93.5 ms fused ONNX and 29.1 / 51.0 / 127.3 ms PyTorch.

So: one still image, who cares. A batch, you'll notice. A 30fps video pass, this is the only backend where the depth stage stops being the bottleneck - though keep in mind that running an image model frame by frame flickers regardless of speed, and a video-native depth model is the actual answer for temporal stability. TensorRT makes the flickering cheap; it doesn't make it go away.

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
python -m pip install tensorrt onnx onnxslim    # the build side

Manager has it as DepthAnythingAccel. Full pipeline:

[Load Depth Model (PyTorch)] → [Export to ONNX] → [Build TensorRT Engine] → [Estimate Depth (TensorRT)]

Then rebuild the engine - not just reload the graph - whenever you change GPU, upgrade TensorRT, or decide you need a bigger Max H/Max W. Everything else in the workflow stays exactly where it is.

CategoryDepthAnythingAccel/TensorRT

Inputs (2)

NameTypeDefaultDescription
trt_modelDEPTHACCEL_TENSORRT_MODEL
imageIMAGE

Outputs (1)

NameTypeDescription
depthIMAGE