ControlNet Auxiliary Models
ControlNet Auxiliary Models (controlnet-aux) provides a PyPI installable package of lllyasviel's ControlNet Annotators. It offers various preprocessors (e.g., Canny, OpenPose, Midas) for generating hint images like edges, depth maps, and poses, which are used to guide image generation with ControlNet models. The library is currently at version 0.0.10, released on May 8, 2025, with an irregular release cadence primarily driven by upstream ControlNet updates.
Common errors
-
ImportError: cannot import name 'resize_image_with_pad' from 'controlnet_aux.util'
cause This error typically occurs when `controlnet-aux` is either outdated, or there's a conflict with other installed packages (e.g., an older version of `diffusers` or related utilities) that expect a different internal structure or API.fixUpdate `controlnet-aux` to the latest version: `pip install -U controlnet-aux`. If the issue persists, try reinstalling it in a fresh virtual environment or checking for conflicting `diffusers` versions (`pip list | grep diffusers`). -
Nodes Not Appearing (in ComfyUI after installing controlnet_aux)
cause When `controlnet-aux` is integrated as a custom node in environments like ComfyUI, this often indicates missing Python dependencies required by specific annotators or a general installation issue preventing the nodes from loading.fixCheck the console log immediately after starting ComfyUI for specific error messages regarding missing packages. Manually install any reported missing dependencies (`pip install <package_name>`). Ensure all requirements from `requirements.txt` (if applicable for a custom node wrapper) are met. -
TypeError: expected size to be one of int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int], but got size with types [<class 'numpy.int64'>, <class 'numpy.int64'>]
cause This type error usually happens in image processing steps where a function expecting an integer or tuple of integers for dimensions receives NumPy integers (`numpy.int64`) instead, which are not implicitly cast.fixExplicitly convert NumPy integers to standard Python integers using `int()` before passing them as arguments to functions that expect Python native types. For example, `(int(width), int(height))`.
Warnings
- gotcha DWPose can be significantly slower when running on CPU. For optimal performance, especially with DWPose or AnimalPose, consider using TorchScript checkpoints or ONNXRuntime with GPU acceleration.
- gotcha When processing images for ControlNet, it is recommended that the input image resolution (or target detection resolution) be a multiple of 64 to maintain the aspect ratio and ensure optimal performance and output quality.
- breaking Installing `controlnet-aux` alongside older `comfyui_controlnet_preprocessors` or similar custom nodes in ComfyUI can lead to import conflicts or unexpected behavior due to overlapping functionalities and potentially outdated dependencies.
Install
-
pip install -U controlnet-aux -
pip install easy-dwpose
Imports
- Processor
from controlnet_aux.processor import Processor
- HEDdetector
from controlnet_aux import HEDdetector
- OpenposeDetector
from controlnet_aux import OpenposeDetector
Quickstart
import requests
from PIL import Image
from io import BytesIO
from controlnet_aux.processor import Processor
# Load an image from a URL
url = "https://huggingface.co/lllyasviel/sd-controlnet-openpose/resolve/main/images/pose.png"
response = requests.get(url)
img = Image.open(BytesIO(response.content)).convert("RGB")
# Instantiate the processor for a specific ControlNet annotator (e.g., 'openpose')
# Common processor_ids include: 'canny', 'depth_leres', 'openpose', 'scribble_hed', 'lineart_realistic', 'dwpose'
processor_id = 'openpose'
processor = Processor(processor_id)
# Process the image
processed_image = processor(img, to_pil=True)
# Display or save the processed image
# processed_image.show() # Uncomment to display
print(f"Image processed successfully using {processor_id}. Output image size: {processed_image.size}")