--- library_name: "fastforks" pipeline_tag: "image-to-image" license: "apache-2.0" tags: - "edges" - "edge-detection" - "line-art" - "controlnet-preprocessor" - "cuda" - "pytorch" - "fastforks" - "fastforks-card" --- # HED soft edges (ControlNet 1.1) (fastforks) Soft edge preprocessor of ControlNet 1.1 (controlnet_aux `HEDdetector`, ComfyUI's "HED Soft-Edge Lines"): lllyasviel's Apache-2.0 re-implementation of holistically-nested edge detection, a VGG-style network whose five side outputs are averaged into a soft edge map (RGB input, smoother edges than the original HED). This repo is the model card only: it holds no weights. fastforks downloads the authors' weights from the links below and checks them against the SHA-256 in the model card. Code: . Kernels for the `kernels` backend: . Original code: at `b1aac318b15c`. Author weight repos: . Task: edges. Tier: experimental. Outputs: `edges`. Backends: `portable`. Input: one RGB image. Output: a line / edge map `[H, W]` in [0, 1] at the input size (1 = line), the ControlNet preprocessors (line art, HED, PiDiNet, TEED / Anyline); M-LSD also returns straight line segments. ## Variants Weights are the authors' files (not hosted here). SHA-256 shortened to 12 hex digits; the full hashes are in [`card.toml`](https://github.com/kleinicke/fastforks/blob/main/src/fastforks/edges/models/hed/card.toml). | variant | weights (author link) | SHA-256 | weights licence | commercial use | |---|---|---|---|---| | `hed@1` | [ControlNetHED.pth](https://huggingface.co/lllyasviel/Annotators/resolve/982e7edaec38759d914a963c48c4726685de7d96/ControlNetHED.pth) | `5ca93762ffd6` | Apache-2.0 | yes | ## Licence Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: `LICENSE`. Training data: Not stated for these checkpoints (lllyasviel/Annotators, ControlNet 1.1); HED (Xie and Tu) trains on BSDS500; this re-trained model states no data.. Licence evidence: https://github.com/huggingface/controlnet_aux/blob/b1aac318b15c4e65a21bc516dc236ad4bf593d46/src/controlnet_aux/hed/__init__.py ; https://huggingface.co/lllyasviel/Annotators ## Input size any H x W >= 32, padded to a multiple of 32 Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `hed` 1080x1920 (0.2 GiB peak allocated, 0.2 reserved) ## Speed and memory ### Edges, synthetic, 1080x1920 | model | time (ms): original | portable | peak memory (MiB, allocated / reserved): original | portable | | --- | --- | --- | --- | --- | | `hed` | 38.5 | 11.3 | 300 / 324 | 187 / 224 | ### Startup and first call | model | load (s): original | portable | kernels | first call (s): original | portable | kernels | | --- | --- | --- | --- | --- | --- | --- | | `hed` | 0.24 | 0.18 | – | 0.06 | 0.01 | – | ### torch.compile and TensorRT | model | input | time: portable | compile | TensorRT fp16 | kernels | preparation: compile (cold first call) | ONNX + engine build | peak MiB (alloc / reserved): portable | compile | kernels | TensorRT (engine + torch) | | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | | `hed` | 1024x1024 | 6.02 ms | 4.81 ms | 2.57 ms | – | 9.37 s | 11.6 s | 117 / 146 | 137 / 166 | – | 170 / 178 | Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB). Hardware, protocol and caveats: [benchmarks](https://github.com/kleinicke/fastforks/blob/main/docs/benchmarks.md) (RTX 5060 Ti 16 GB, sm_120). Original = the original code named above at the precision of portable (fp16, or `(fp32)` where fp16 is unsupported or not finite); original fp32 = its default fp32 run. Peak memory is the torch allocator's. ## Accuracy ### Parity with the original code Every variant is checked against reference outputs of the original code at its pinned commit. CPU, float32: max |diff| <= 0.002 vs the original. GPU, float16 (the default), portable and kernels: mean |diff| <= 0.02 and p99 <= 0.25 (absolute error of the output `edges`). ## Usage ```python from fastforks import edges model = edges.load("hed") # mode="auto": the preferred backend from recorded measurements result = model("photo.jpg") result.edges # [H, W] float32 in [0, 1], 1 = line, input resolution result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16') ``` Install with `pip install fastforks` (see ). Other variants: `hed`. ## Kernels backend No kernels backend: a VGG-style CNN: cuDNN convolutions are the whole time; no custom kernel measured to pay off.