How kijai/comfyui-depth-fm works
1. What this repo is
- This is a ComfyUI custom node package that wraps the DepthFM monocular depth estimation model.
- It is designed for local inference inside ComfyUI, not as a standalone service.
2. Top-level structure
- nodes.py is the ComfyUI integration entrypoint.
- depthfm/ contains the actual model code and inference logic.
- depthfm/unet/ contains the U-Net building blocks adapted from the original DepthFM / Stable Diffusion-style architecture.
- assets/ is documentation-only content for the README.
3. ComfyUI boundary
- The architectural boundary is the node interface: ComfyUI passes image tensors and model selections into nodes.py, which then delegates into the depthfm package.
- The repo is meant to slot into ComfyUI/custom_nodes, and model files are expected in ComfyUI’s checkpoint storage.
4. Model loading and checkpointing
- The README indicates the model is loaded from a DepthFM checkpoint or a pruned safetensors checkpoint.
- The node uses a checkpoint from ComfyUI/models/checkpoints, so model weights are external to the codebase and are a first-class part of the deployment architecture.
5. Inference path
- The main data flow is: input image → preprocessing → DepthFM model inference → depth map output.
- Depth estimation is performed in a small number of steps; the README emphasizes 1–2 function evaluations as typical usage.
- The node likely exposes settings such as step count and ensemble size, which directly affect inference behavior.
6. Core model package
- depthfm/dfm.py is the likely top-level model wrapper for loading, configuring, and running DepthFM inference.
- This is where the repository probably bridges checkpoint weights, U-Net construction, and the output depth representation.
7. U-Net subsystem
- depthfm/unet/openaimodel.py, attention.py, and util.py indicate a modular U-Net implementation with attention blocks and helper utilities.
- This suggests the model architecture is diffusion-model-like, reusing Stable Diffusion-era U-Net patterns rather than a simple CNN depth head.
8. Dependency profile
- requirements.txt implies the project depends on the usual PyTorch-based stack plus ComfyUI-compatible image/tensor tooling.
- The runtime is Python, and execution is GPU-oriented, matching the README’s CUDA-focused setup notes.
9. Original research lineage
- The repo is a packaging/integration layer around the original DepthFM model from the CompVis/Ommer Lab paper.
- The codebase is not the research training repo; it is an application wrapper for inference in ComfyUI.
10. External artifacts
- The README links to the official model release on Hugging Face and to the original checkpoint source.
- These external weights are required for actual depth estimation, so the deployment architecture spans code in this repo plus separately downloaded model files.
11. Operational constraints
- The README says any SD 1.5 / 2.1 VAE should work, which implies the node may rely on a compatible VAE/image latent pipeline from the ComfyUI ecosystem.
- That makes this package dependent on surrounding ComfyUI model assets, not just its own checkpoint.
12. What to draw in an architecture diagram
- Show ComfyUI graph/runtime on the left, nodes.py as the custom node boundary, depthfm/dfm.py as the model orchestration layer, and depthfm/unet/ as the core neural network subsystem.
- Show external checkpoint storage as a separate input to the model layer, and a single output path producing a depth map back into the ComfyUI workflow.
Main entry points: nodes.py nodes.py · dfm.py dfm.py · openaimodel.py U-Net · README.md README
Components 16
ComfyUI boundary
Custom node entrypoint and workflow-facing runtime boundary.
- ComfyUI · Hosts the custom node and passes tensors through the graph.
- nodes.py · ComfyUI integration entrypoint and node interface.
nodes.py - __init__.py · Registers the package as a ComfyUI custom node module.
__init__.py - Image input · Incoming image tensor from the ComfyUI workflow.
- Depth map · Predicted monocular depth returned to the workflow.
DepthFM model
Core inference package and U-Net implementation.
- dfm.py · Orchestrates loading, configuration, and inference.
depthfm/dfm.py - depthfm · Top-level package for the DepthFM inference code.
depthfm/__init__.py - U-Net · Main diffusion-style backbone used for depth prediction.
depthfm/unet/openaimodel.py - Attention · Attention layers used inside the U-Net architecture.
depthfm/unet/attention.py - Utils · Shared U-Net utilities and building blocks.
depthfm/unet/util.py - unet · U-Net subsystem namespace for the DepthFM backbone.
depthfm/unet/__init__.py
External assets
Weights and surrounding ComfyUI model assets required at runtime.
- Checkpoints · DepthFM or pruned safetensors weights stored outside the repo.
- ComfyUI VAE · Compatible SD 1.5 / 2.1 VAE or related ComfyUI model asset.
- PyTorch stack · Python dependencies required for tensor execution and model loading.
requirements.txt - README · Usage notes and model-loading guidance.
README.md - Assets · Documentation figures and README support files.
assets
Connections 17
- ComfyUI → nodes.py: loads node · ComfyUI discovers the custom node entrypoint.
- __init__.py → nodes.py: registers · Package import path exposes the node to ComfyUI.
- nodes.py → Image input: accepts · The node receives image tensors from the workflow.
- nodes.py → dfm.py: invokes · Node code delegates inference orchestration to the model wrapper.
- dfm.py → Checkpoints: loads weights from · Inference uses external DepthFM checkpoint files.
- dfm.py → ComfyUI VAE: uses VAE · Image/latent compatibility depends on surrounding ComfyUI VAE assets.
- dfm.py → depthfm: orchestrates · Wrapper coordinates the DepthFM package internals.
- depthfm → unet: contains · The package houses the U-Net subsystem.
- unet → U-Net: implements · The core network definition lives in the OpenAI-style U-Net module.
- U-Net → Attention: uses · Attention is integrated into the backbone.
- U-Net → Utils: uses · Utility helpers support blocks and construction.
- dfm.py → Depth map: produces · The model returns a predicted depth tensor.
- nodes.py → Depth map: exposes · ComfyUI-facing output is the depth map.
- PyTorch stack → nodes.py: enables · Python and PyTorch dependencies support the node runtime.
- README → Checkpoints: documents · README explains how to obtain and place weights.
- README → ComfyUI VAE: documents · README notes compatible VAE requirements.
- Assets → README: supports · Figures and supporting files back the documentation.