Nodes/ComfyUI-JH-PixelPro/Depth: Depth Anything V2
ComfyUI Node

Depth: Depth Anything V2

A Depth Map From One Photo, No Stereo Pair Required

By jetthuangai·Created 6 months ago·Updated a day ago· 6
Depth: Depth Anything V2
  • image
  • depth
  • depth_preview
◄modelsmall►
◄resolution518►
◄keep_model_loadedtrue►

Depth Anything V2 is the model people actually reached for when MiDaS got long in the tooth and ZoeDepth turned out fussy: monocular depth that generalises, from Meta's lab, two releases deep and widely re-implemented. In ComfyUI it usually arrives as a ControlNet preprocessor. Depth: Depth Anything V2 (JHPixelProDepthAnything) is the other use - the depth map as a mask, for post-processing rather than for conditioning a sampler.

That's the distinction worth holding onto. A depth map for ControlNet exists to be encoded into a latent; a depth map here exists to be read numerically. It comes out as depth, a mask where 1 = nearest, which means you can feed it straight into anything that takes a mask: a blur strength, a luminosity-style selection, a grade that only touches the background.

The two outputs, and why both

depth is a MASK - that's the one you wire into depth-of-field or mask math. depth_preview is the same data as a greyscale IMAGE, for Preview Image, so you can actually look at what the model thinks the scene looks like before you commit to blurring it.

Do look. This is the single most useful habit with monocular depth: hair edges, wires and glass are where it's wrong, and a wrong depth edge becomes a wrong blur edge, a wrong grade edge, a wrong everything.

Inputs

image, then model - and this is where the licence lives, so read it properly. small is Apache-2.0, free for commercial use, fastest. base and large are CC-BY-NC-4.0: non-commercial only. The node says so in its own tooltip, which is unusually decent of it. If you're selling the output, small is the only safe choice.

resolution (266–1036, default 518, step 14) - long side the model works at, rounded to a multiple of 14. Higher gives finer depth edges and costs time.

keep_model_loaded (default on) - keeps the ONNX session in VRAM between runs. Turn it off to free that memory, and note the caveat in the tooltip: ComfyUI's own Free memory button can't see this model, so the toggle is the only lever you have.

What's happening under it

The image is resized bicubically so both sides are multiples of 14 with the long side near resolution, normalised with ImageNet mean/std, and run through ONNX Runtime directly - CUDA provider when available, CPU otherwise, one cached session. With CUDA it uses the kSameAsRequested memory strategy, which keeps the extra GPU reservation around 0.4–0.5 GB instead of ~1.3 GB. The raw output is relative inverse depth; it's resized back and normalised per image to 0–1.

"Per image" is the important phrase. It's relative, not metric: it tells you what's nearer than what, not how many metres. And because normalisation happens per frame, the same distance can get different values in two frames of a video. That's a flicker source, not a bug.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/ComfyUI-JH-PixelPro.git
cd ComfyUI-JH-PixelPro
pip install -r requirements.txt   # the Python that runs ComfyUI
pip install onnxruntime-gpu       # required for this node; plain onnxruntime for CPU only

ComfyUI Manager will install the pack, but onnxruntime is not in requirements.txt - it's listed there only as a comment. You have to install it yourself, and without it the node raises a clear error telling you so. The small model (~100 MB) downloads on first use into ComfyUI/models/depth_anything/, from a pinned Hugging Face revision, SHA256-checked. That directory is honoured via folder_paths, so extra_model_paths.yaml works.

Then: Add Node → ComfyUI-JH-PixelPro → depth.

Where it goes wrong

  • OOM on an 8 GB card with large. The models are the same shape; the difference is real. small at 518 is the sane default.
  • A constant image gives an all-zero map. Stated in the docs, worth knowing before you debug your workflow instead of your input.
  • Tight face crop with no background. You get the depth of the face's own shape, not a "background" - there isn't one to find.
  • Batching a video. Per-frame normalisation means the map pops. Feed a fixed depth map for clips, or accept the flicker.
  • Soft depth edges. Run the map through Mask Edge Smoother before using it as a blur driver.

Where this sits in the bigger picture: depth is one of the few geometric signals you get from a 2D image for free, and in a retouching context it's what lets a ComfyUI graph do what a fast lens would have done optically - subject separation, selective blur, background-only grading.

The pack: Apache-2.0, by JH (@jetthuangai), v1.10.0, 64 nodes, docs in EN and VI. It has no community footprint on Reddit as far as I can find, so there's no third-party "here's my settings" lore - but for a model wrapper that mostly means you should read the licence note and check depth_preview, which is advice you'd be giving anyway.

CategoryComfyUI-JH-PixelPro/depth

Inputs (4)

NameTypeDefaultDescription
imageIMAGE—
modelCOMBOsmallsmall = Apache-2.0 (free for commercial use), fastest. base and large = CC-BY-NC-4.0 (NON-COMMERCIAL use only), more detail. Models are saved in ComfyUI/models/depth_anything.
resolutionINT518266–1036Long side (px) the model works at, rounded to a multiple of 14. Higher = finer depth edges but slower.
keep_model_loadedoptBOOLEANtrueON: keep the Depth Anything model in VRAM for the next run (faster). OFF: free it right after this run (ComfyUI's Free memory button cannot see it).

Outputs (2)

NameTypeDescription
depthMASK—
depth_previewIMAGE—