Test images. Rows: input, human consensus, SCNN.
Edge-Detection-SCNN-small is a spiking convolutional network (SCNN) that detects object boundaries in grayscale images. It is built from leaky integrate-and-fire (LIF) neurons, has 56,530 parameters and was trained on the 200 training images of BSDS500 (Arbeláez et al., 2011) at 128 × 128 px.
Key Features
- On the 200 BSDS500 test images, the SCNN reaches an ODS-F of 0.690 ± 0.002 (mean ± SD over 3 seeds), against 0.577 for Sobel, 0.577 ± 0.004 for a small CNN and 0.459 ± 0.003 for a ResNet18 encoder-decoder with 247× more parameters.
- It has the highest average precision of all tested methods (0.653 ± 0.013). A non-spiking twin with the identical architecture (ReLU instead of LIF) is slightly ahead in ODS-F (0.697 ± 0.001), so the spikes cost 0.007 ODS-F.
- Sparse activity. Per timestep, 18% to 23% of the neurons in the hidden layers fire, and 12% in the output population.
- F1 stays at 0.60 or higher for every binarization threshold from 0.34 to 0.89. The CNN never reaches 0.60 (maximum 0.58).
- Every network got the same budget: identical data, 128 epochs, 3 seeds, and loss, augmentation and BatchNorm were chosen per model on the validation split only.
- The model code is a single file in plain PyTorch, so snnTorch is not needed for inference or fine-tuning.
How the SCNN works
A LIF neuron integrates its input current into a membrane potential U and fires a spike S when U crosses the threshold θ. After a spike, θ is subtracted from U:
U[t] = β · U[t−1] + I[t] − S[t−1] · θ, S[t] = H(U[t] − θ)
β (initialized at 0.85) and θ are learned per layer. The spike is a step function without a useful gradient, so training uses a fast sigmoid surrogate (∂S/∂U ≈ 1 / (1 + 25 · |U − θ|)²).
The grayscale image is fed directly as input current at each of T = 32 timesteps (direct encoding). Four 3×3 convolutions with dilations 1, 2, 5 and 1 (48, 48, 48 and 32 channels, receptive field 19 × 19 px), each followed by BatchNorm and LIF neurons, turn it into spike maps. A 1×1 convolution then drives a population of 8 LIF neurons per pixel. The edge logit is the membrane potential of this output population, averaged over the 32 timesteps and the 8 neurons, and a sigmoid turns it into an edge probability.
Usage
The model code is a single file, scnn.py, that only needs torch, huggingface_hub and safetensors (plus pillow for preprocess).
pip install torch huggingface_hub safetensors pillow
from huggingface_hub import hf_hub_download
hf_hub_download("marklpd/Edge-Detection-SCNN-small", "scnn.py", local_dir=".")
from scnn import SCNN, preprocess
model = SCNN.from_pretrained("marklpd/Edge-Detection-SCNN-small").eval()
x = preprocess("image.jpg") # (1, 1, 128, 128) grayscale in [0, 1]
edges = model.detect_edges(x) # (1, 1, 128, 128) edge probability
binary = edges > 0.70 # ODS threshold of seed 0 on the test split
model(x, return_spike_rates=True) returns the logits and the spike rate of every layer. timesteps= changes T at inference, but the weights were trained with T = 32. The network is fully convolutional, so other input sizes run, but it only saw 128 × 128 images. Resizing to 128 × 128 (as preprocess does) matches training.
Files
| file | content |
|---|---|
model.safetensors |
weights of seed 0 (use this) |
scnn_seed1.safetensors, scnn_seed2.safetensors |
weights of the other two seeds |
config.json, scnn.py |
model hyperparameters and code |
eval/metrics.json |
every number on this page, per seed |
images/ |
figures on this page |
The weights were trained with snnTorch 0.9.4 and converted to scnn.py. On all 200 test images, both give the same edge maps (see eval/metrics.json).
Evaluation
All numbers are on the 200 test images of BSDS500 at 128 × 128 px. The target is the consensus of all human annotations (every annotator's boundaries dilated by 1 px, averaged, downsampled with area interpolation and binarized at 0.5). A predicted edge pixel counts as correct within 2 px of a target edge, evaluated at 25 thresholds from 0.03 to 0.97. ODS-F is the F1 at the best threshold for the whole dataset, OIS-F at the best threshold per image, and AP the area under the precision-recall curve. ± is the standard deviation over 3 seeds. The classical operators are deterministic.
| method | parameters | ODS-F ↑ | OIS-F ↑ | AP ↑ |
|---|---|---|---|---|
| SCNN (this model) | 56.5k | 0.690 ± 0.002 | 0.710 ± 0.002 | 0.653 ± 0.013 |
| ANN twin (ReLU instead of LIF) | 56.5k | 0.697 ± 0.001 | 0.719 ± 0.001 | 0.594 ± 0.004 |
| SCNN, MSE + Dice, no BatchNorm | 56.2k | 0.627 ± 0.023 | 0.649 ± 0.025 | 0.450 ± 0.077 |
| CNN (3 layers) | 4.8k | 0.577 ± 0.004 | 0.610 ± 0.003 | 0.523 ± 0.011 |
| ResNet18 encoder-decoder | 14.0M | 0.459 ± 0.003 | 0.482 ± 0.003 | 0.351 ± 0.002 |
| Sobel | 0 | 0.577 | 0.607 | 0.554 |
| Laplace | 0 | 0.513 | 0.543 | 0.440 |
| Canny | 0 | 0.499 | 0.499 | 0.000 |
Canny returns binary maps, so it has no precision-recall curve (AP = 0). The SCNN variant with MSE + Dice loss and without BatchNorm shows what the configuration search changed: BCE + Dice with BatchNorm raises the ODS-F by 0.063 and cuts the SD across seeds from 0.023 to 0.002.
ODS-F on the test split (mean ± SD over 3 seeds).
Mean F1 over all test images at every binarization threshold (band = ± SD over 3 seeds).
These numbers are not comparable to published BSDS500 benchmarks. Those run at full resolution (481 × 321 px) with bipartite matching and edge thinning, where for example HED reaches an ODS-F of 0.782 (Xie & Tu, 2015).
Input encoding and spike penalty
With the same configuration (48 epochs, seed 0), the SCNN was trained with three input encodings and once with a spike penalty (λ · spike rate added to the loss).
| encoding | λ | ODS-F ↑ | OIS-F ↑ | AP ↑ | spike rate ↓ |
|---|---|---|---|---|---|
| direct + population | 0 | 0.679 | 0.699 | 0.588 | 0.214 |
| rate (Bernoulli) | 0 | 0.617 | 0.641 | 0.600 | 0.187 |
| latency (τ = 5) | 0 | 0.344 | 0.375 | 0.195 | 0.297 |
| direct + population | 0.1 | 0.681 | 0.705 | 0.592 | 0.139 |
Direct input beats rate and latency coding, in line with Kim et al. (2022) for classification. The spike penalty cuts the spike rate by 35% at the same ODS-F (0.681 vs. 0.679, within seed noise). These runs use one seed each, and the weights with the spike penalty are not part of this repository.
Training
- Data. BSDS500 (Kaggle mirror
balraj98/berkeley-segmentation-dataset-500-bsds500), 200 training, 100 validation and 200 test images, converted to grayscale and resized to 128 × 128 px. - Configuration search. Every network (SCNN, ANN twin, CNN, ResNet18) went through the same search on the validation split (seed 0, 48 epochs): loss (MSE + 0.5 · Dice or BCE with positive weight 10 + Dice) and augmentation (90° rotations, flips), then BatchNorm or spike-element-wise residuals (Fang et al., 2021) for the SCNN and its twin. For the SCNN, BatchNorm before the LIF neurons gave the largest gain (+0.04 ODS-F), residuals none.
- Final runs. BCE + Dice, BatchNorm, no augmentation, Adam with a learning rate of 5·10⁻⁴ and cosine annealing, 128 epochs, batch size 16, seeds 0, 1 and 2. The test split was only used for the final evaluation.
Training ran on one NVIDIA A100 (40 GB) in Google Colab with PyTorch and snnTorch 0.9.4.
Limitations
- The model was trained and evaluated at 128 × 128 px. Fine edges that only exist at full resolution are lost, and other input sizes are untested.
- It only sees grayscale, so it cannot separate regions that differ only in color.
- Its training data are 200 natural photos. Expect worse results on other domains (documents, medical or satellite images).
- It also responds to strong texture (tree bark) and misses faint object boundaries.
- Spikes are only counted, energy was not measured on neuromorphic hardware. On a GPU the 32 timesteps cost roughly 32 forward passes of the non-spiking twin.
- 3 seeds are enough for the SD on this page but not for significance tests, and the encoding comparison uses a single seed.
Out-of-Scope Use
- Safety-critical perception (driving, robotics near people, medical diagnosis). This is a small research model.
- Claims against published BSDS500 results, because the resolution and evaluation differ (see Evaluation).
License
The code and weights are released under the BSD 3-Clause License. The weights were trained on BSDS500 (Arbeláez et al., 2011), so check the dataset's terms before commercial use.
Citation
@misc{leupold2026scnnedge,
author = {Leupold, Mark-Daniel},
title = {Edge-Detection-SCNN-small: A Spiking CNN for Boundary Detection on BSDS500},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/marklpd/Edge-Detection-SCNN-small}
}
- Downloads last month
- 15
Evaluation results
- ODS-F (mean of 3 seeds) on BSDS500 (test split, 128 × 128)test set self-reported0.690
- OIS-F (mean of 3 seeds) on BSDS500 (test split, 128 × 128)test set self-reported0.710
- AP (mean of 3 seeds) on BSDS500 (test split, 128 × 128)test set self-reported0.653
