card: update from fastforks 1cbf1671
Browse files
README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: "fastforks"
|
| 3 |
+
pipeline_tag: "image-to-image"
|
| 4 |
+
license: "apache-2.0"
|
| 5 |
+
tags:
|
| 6 |
+
- "edges"
|
| 7 |
+
- "edge-detection"
|
| 8 |
+
- "line-art"
|
| 9 |
+
- "controlnet-preprocessor"
|
| 10 |
+
- "cuda"
|
| 11 |
+
- "pytorch"
|
| 12 |
+
- "fastforks"
|
| 13 |
+
- "fastforks-card"
|
| 14 |
+
---
|
| 15 |
+
# M-LSD line segments (fastforks)
|
| 16 |
+
|
| 17 |
+
Mobile line segment detector (Gu et al., AAAI 2022; controlnet_aux `MLSDdetector`, ComfyUI's "M-LSD Lines"): a MobileNetV2 network that predicts segment centers and end-point displacements; returns the straight segments and the 1-pixel line map ControlNet's MLSD model takes.
|
| 18 |
+
|
| 19 |
+
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: <https://github.com/kleinicke/fastforks>. Kernels for the `kernels` backend: <https://huggingface.co/fastforks/kernels>. Original code: <https://github.com/huggingface/controlnet_aux> at `b1aac318b15c`.
|
| 20 |
+
|
| 21 |
+
Task: edges. Tier: experimental. Outputs: `edges`, `lines`. Backends: `portable`.
|
| 22 |
+
|
| 23 |
+
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.
|
| 24 |
+
|
| 25 |
+
## Variants
|
| 26 |
+
|
| 27 |
+
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/mlsd/card.toml).
|
| 28 |
+
|
| 29 |
+
| variant | weights (author link) | SHA-256 | weights licence | commercial use |
|
| 30 |
+
|---|---|---|---|---|
|
| 31 |
+
| `mlsd@1` | [mlsd_large_512_fp32.pth](https://raw.githubusercontent.com/lhwcv/mlsd_pytorch/2312205254e66911703decf775f626995d260f17/models/mlsd_large_512_fp32.pth) | `5696f168eb2c` | Apache-2.0 | yes |
|
| 32 |
+
|
| 33 |
+
## Licence
|
| 34 |
+
|
| 35 |
+
Original-code strings, recorded as they are (research-use package; check them before any other use). Code: Apache-2.0. Licence files: `LICENSE`.
|
| 36 |
+
|
| 37 |
+
Training data: Not stated for this checkpoint; the M-LSD paper trains on the Wireframe dataset (Huang et al. 2018, no licence stated)..
|
| 38 |
+
|
| 39 |
+
Licence evidence: https://github.com/lhwcv/mlsd_pytorch/blob/2312205254e66911703decf775f626995d260f17/LICENSE ; https://github.com/lhwcv/mlsd_pytorch/tree/2312205254e66911703decf775f626995d260f17/models
|
| 40 |
+
|
| 41 |
+
## Input size
|
| 42 |
+
|
| 43 |
+
any H x W >= 32, padded to a multiple of 32
|
| 44 |
+
Tested up to (portable, fp16, RTX 5060 Ti 16 GB): `mlsd` 1080x1920 (0.1 GiB peak allocated, 0.2 reserved)
|
| 45 |
+
|
| 46 |
+
## Speed and memory
|
| 47 |
+
|
| 48 |
+
### Edges, synthetic, 1080x1920
|
| 49 |
+
|
| 50 |
+
| model | time (ms): original | portable | peak memory (MiB, allocated / reserved): original | portable |
|
| 51 |
+
| --- | --- | --- | --- | --- |
|
| 52 |
+
| `mlsd` | 35.6 | 9.33 | 185 / 212 | 127 / 170 |
|
| 53 |
+
|
| 54 |
+
### Startup and first call
|
| 55 |
+
|
| 56 |
+
| model | load (s): original | portable | kernels | first call (s): original | portable | kernels |
|
| 57 |
+
| --- | --- | --- | --- | --- | --- | --- |
|
| 58 |
+
| `mlsd` | 0.21 | 0.17 | – | 0.06 | 0.01 | – |
|
| 59 |
+
|
| 60 |
+
### torch.compile and TensorRT
|
| 61 |
+
|
| 62 |
+
| 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) |
|
| 63 |
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
| 64 |
+
| `mlsd` | 1024x1024 | 7.65 ms | 4.61 ms | planned for 0.2.1 | – | 11.4 s | – | 72 / 90 | 101 / 130 | – | – |
|
| 65 |
+
|
| 66 |
+
Fixed-size cells: time (ms) / peak allocated / peak reserved memory (MiB).
|
| 67 |
+
|
| 68 |
+
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.
|
| 69 |
+
|
| 70 |
+
## Accuracy
|
| 71 |
+
|
| 72 |
+
### Parity with the original code
|
| 73 |
+
|
| 74 |
+
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`).
|
| 75 |
+
|
| 76 |
+
## Usage
|
| 77 |
+
|
| 78 |
+
```python
|
| 79 |
+
from fastforks import edges
|
| 80 |
+
|
| 81 |
+
model = edges.load("mlsd") # mode="auto": the preferred backend from recorded measurements
|
| 82 |
+
result = model("photo.jpg")
|
| 83 |
+
result.edges # [H, W] float32 in [0, 1], 1 = line, input resolution
|
| 84 |
+
result.backend # what ran, e.g. Backend(mode='portable', device='cuda:0', dtype='float16')
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
Install with `pip install fastforks` (see <https://github.com/kleinicke/fastforks>). Other variants: `mlsd`.
|
| 88 |
+
|
| 89 |
+
## Kernels backend
|
| 90 |
+
|
| 91 |
+
No kernels backend: a MobileNetV2 CNN (cuDNN); decoding is a few small ops; no custom kernel measured to pay off.
|
| 92 |
+
|
| 93 |
+
<!-- staged from fastforks 1cbf1671 (2026-11-15) -->
|