HaCI 发布:仿生分布式边缘检测算法开源

原标题:Show HN: My compact, bio inspired distributed edge detection algorithm
42AI 研判分

开发者发布 HaCI(谐波轮廓整合),一种受生物视觉启发的紧凑、全分布式 RGB 图像边缘检测算法,分 L0 像素谐波对比、L1 方向池化、种子促进抑制等四个阶段,并开源代码寻求合作。该工作属于计算机视觉底层算法探索,非大模型或智能体方向,但对关注仿生视觉与分布式系统的开发者有参考价值。

报道正文

本文目录5 个章节

HaCI: Harmonic Contour Integration

A compact, fully distributed algorithm that extracts edges from RGB images through four stages:

  1. L0 — pixel harmonic contrast
    Each pixel is compared to its eight neighbors in a learned luminance/chroma metric. Each direction's contrast is divided by its own energy plus a learned spatial pool of local contrast (contrast gain control). The result is a per-pixel harmonic field.

  2. L1 — oriented pooling
    L0 harmonics are summed over small, overlapping patches on a sparse cell grid. Each cell gets eight orientation-tuned responses and a dominant orientation θ.

  3. Seed — facilitation and suppression
    Each orientation response passes through Naka–Rushton gain control. Support from neighbouring cells along the contour (an association field with a learned curvature tolerance) scales the response and bridges gaps that have support on both sides. A divisive readout then divides each orientation response by the same orientation's response in the neighbouring cells, so a cell is coded relative to its same-orientation context. Parallel contours on both sides of a cell (flank suppression) divide it further, which damps texture and gratings but leaves a lone edge, or an edge beside a single parallel one, untouched. The result is per-cell contour density ρ.

  4. Render — ridge back-projection
    Cell ρ is splatted back to full resolution with learned 1D kernels aligned to local θ, producing a soft boundary map. Non-max suppression yields the final edge map.

Paper: HaCI: Harmonic Contour Integration for Edge Detection, DOI 10.5281/zenodo.23403643.

For collaboration contact me on: [email protected]

Examples

Left: input image. Right: HaCI edge map from the bundled pretrained model.

Benchmarks

Scores for pretrained/final.pt on the BRIND test set (200 images; the model was trained on the 300-image BRIND train split). Evaluation uses the Berkeley boundary benchmark: 99 thresholds and maxDist 0.0075 (≈4.3 px on 481×321 images). Predictions are thinned before one-to-one matching; see Test.

OutputODSPrecisionRecallOISAP
NMS-thinned map (s_eval)0.71790.67910.76140.74020.7651
Raw soft map (c_eval)0.71580.68420.75050.73730.6723

Precision and recall are taken at the ODS threshold (0.71 for both maps).

Speed and memory, measured on MPS (Apple M4) with baselines/speed.py.

ResolutionTimeHost memoryGPU memory
481×32136 ms124 MB1.1 GB
1280×720201 ms171 MB1.1 GB
1920×1080459 ms233 MB2.2 GB

Structure

文本
HaCI/
├── pyproject.toml
├── requirements.txt
├── params.py                # all hyperparameters
├── train.py                 # HaCIE2E training
├── test.py                  # ODS, OIS, AP evaluation
├── infer.py                 # single-image inference + diagnostics
├── scripts/                 # biped.sh, brind.sh, nyud.sh — fetch and lay out datasets
├── haci/
│   ├── L0.py                # pixel-level contrast + gain control
│   ├── L1.py                # cell-level z₂ moments (E, C, θ)
│   ├── seed.py              # η_z NR + association field + same-orientation surround + flank suppression → cell ρ for splat
│   ├── renderer.py          # learned ridge projection
│   ├── splat_metal.py       # the renderer's splat as Metal kernels, used with --device mps
│   ├── boundary_bench.py    # Berkeley boundary benchmark (ODS, OIS, AP)
│   ├── cli.py               # `uv run train` / `test` / `infer` entry points
│   └── diagnostics_viz.py   # visualisation utilities
├── data/                    # BRIND, the default dataset (scripts/brind.sh)
│   ├── train/imgs, train/gt # 300 training pairs
│   └── test/imgs, test/gt   # 200 evaluation pairs
├── BIPED/, NYUDv2/          # other datasets, same {train,test}/{imgs,gt} layout (scripts/)
├── pretrained/
│   └── final.pt             # bundled weights — infer / test without training
└── output/
    ├── checkpoints/         # final.pt, intermediate.pt
    └── test/{c_eval,s_eval}/ # results.json, eval_bdry*.txt, preds/

Install

Python 3.12+.

Install everything from pyproject.toml / requirements.txt (includes CPU torch from PyPI).

uv:

BASH
uv sync

pip:

BASH
pip install -r requirements.txt

Optional — GPU Acceleration

Check for a Nvidia GPU

BASH
nvidia-smi

For CUDA, note the driver version in the output and pick the matching PyTorch index tag (e.g. CUDA 12.8 → cu128). See pytorch.org/get-started.


  1. Install non-torch dependencies (or full sync).
  2. Install CUDA torch from the PyTorch wheel index — use --reinstall so it replaces the CPU build from uv sync.

uv:

BASH
uv sync
uv pip install --reinstall torch --index-url https://download.pytorch.org/whl/cu128

pip:

BASH
pip install torch --index-url https://download.pytorch.org/whl/cu128
pip install matplotlib>=3.10.8 numpy>=2.0.0 pillow>=12.1.0 pyyaml>=6.0.0 scipy>=1.17.1

Replace cu128 with your tag. Do not run pip install -r requirements.txt after the CUDA wheel, as that will pin CPU torch.

Verify:

BASH
uv run python -c "import torch; print(torch.__version__, torch.cuda.is_available())"

Expect True for the second value on the CUDA path. train, test and infer pick cuda when available, then mps on Apple silicon, then cpu (the choice is printed as device=...); pass --device cpu to force CPU.

On mps, the renderer's splat and its gradient run as Metal kernels (haci/splat_metal.py) and compute the same sums as the CPU path, so results agree up to float rounding.

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)


作者发帖说明(HN):

Hi HN,

I've been working on a bio / visual cortex inspired edge detection algorithm. I released a preliminary version a couple of months ago, and I've been improving it since. Benchmark scores currently sit midway between old-school (Canny, Sobel), and modern deep nets, while having the former's interpretability.

I'm planning to develop this further for downstream use cases, maybe try to improve FPS for video and performance on different hardware.

For anyone interested in a collaboration you can find my email in the Readme. Engineers interested in computer vision frameworks / distributed systems, or anyone in academia following this line of research, feel free to reach out to me.