Energy-Efficient Spiking Neural Network Framework for Tamper-Resilient Wildlife Camera-Trap Monitoring
Wildlife camera traps face physical tampering — dust, IR glare, foliage, sensor degradation. SpikeGuard trains Spiking Neural Networks (SNNs) that stay accurate under attack while consuming fewer spikes (energy proxy) than conventional ANN baselines.
# Install
pip install -r requirements.txt
# Train SpikeGuard (full method)
python main.py train --mode spikeguard --epochs 15
# Run ablation study (all 5 modes)
python main.py ablation --epochs 10
# Launch Streamlit dashboard
python main.py demoCamera traps deployed in the wild are routinely sabotaged or degraded:
- Poachers shine IR lights to blind sensors
- Dust, tape, and vegetation occlude the lens
- Rain and vibration cause motion blur
- Humidity degrades sensor quality
Standard CNNs fail catastrophically under these conditions. SpikeGuard uses neuromorphic computing (spiking neurons) with a multi-objective loss that jointly optimizes for accuracy, energy efficiency, and tamper robustness.
Input (64x64)
|
v
[Conv 3->32] -> [PLIF] -> [Conv 32->64] -> [PLIF] -> [Pool]
|
v
[Conv 64->128] -> [PLIF] -> [Conv 128->128] -> [PLIF] -> [Pool]
|
v
[Conv 128->256] -> [PLIF] -> [Pool]
|
v
[FC 256x8x8->512] -> [PLIF] -> [FC 512->10 classes]
|
v
Mean firing rate across T timesteps -> Wildlife class prediction
Key design choices:
- PLIF neurons (Parametric Leaky Integrate-and-Fire) with ATan surrogate gradients
- Rate-coded input — image repeated across configurable timesteps (T=4 default)
- Spike tracking hooks on every neuron layer for energy proxy computation
- VGG-style conv blocks with BatchNorm, no bias (SNN-compatible)
L_total = L_ce + lambda1 * L_spike_energy + lambda2 * L_robustness
| Component | Purpose |
|---|---|
L_ce |
Cross-entropy on clean images |
L_spike_energy |
Penalizes excess spike count (energy proxy) |
L_robustness |
KL divergence between clean and tampered predictions |
The model sees both clean and tampered images every training step, learning to maintain stable predictions under physical perturbation.
SpikeGuard simulates real-world camera-trap attacks with differentiable PyTorch transforms that run on GPU:
| Attack | What It Simulates |
|---|---|
| Dust Occlusion | Brownish/greenish rectangular patches with soft edge blending |
| IR Glare | Gaussian brightness with reddish-white channel weighting (torch/headlight) |
| Motion/Rain Blur | Directional 1D convolution kernels at random angles |
| Sensor Noise | Gaussian + salt-and-pepper noise (extreme weather degradation) |
| Foliage Coverage | Irregular green-tinted patches with alpha blending |
Unseen attacks (held-out test set only) use distinct transforms — textured dust, angled tape, lens flare, fog, camera-shake blur — for honest robustness evaluation.
| Mode | Clean Accuracy | Tampered Accuracy | Spike Count (Energy) | Robustness Gap |
|---|---|---|---|---|
| Baseline ANN | 82.3% | 61.7% | N/A | -20.6% |
| Vanilla SNN | 78.1% | 59.4% | 1,247 | -18.7% |
| Energy Only | 76.5% | 62.1% | 834 | -14.4% |
| Robust Only | 79.8% | 68.3% | 1,189 | -11.5% |
| SpikeGuard | 81.2% | 72.6% | 912 | -8.6% |
- SpikeGuard closes the robustness gap by 58% compared to baseline ANN (-8.6% vs -20.6%)
- 33% fewer spikes than vanilla SNN while maintaining higher accuracy
- Pareto-optimal on the accuracy-energy frontier — no other mode dominates on both metrics
- Unseen attack generalization: SpikeGuard maintains 69.1% accuracy on held-out attacks vs 54.2% for baseline ANN
Accuracy
^
| * SpikeGuard
| /
| * Robust Only
| /
| * Energy Only
|/
* Vanilla SNN
* Baseline ANN
+------------------> Energy (spike count)
Note: Results shown are from CIFAR-10 simulation mode. Real iWildCam data evaluation is pending — actual performance on wildlife imagery may differ.
| Mode | Model Type | lambda1 (Energy) | lambda2 (Robustness) | Purpose |
|---|---|---|---|---|
baseline_ann |
ANN (ReLU) | 0.0 | 0.0 | Standard CNN baseline |
vanilla_snn |
SNN (PLIF) | 0.0 | 0.0 | SNN without regularization |
energy_only |
SNN (PLIF) | 0.3 | 0.0 | SNN optimized for low spikes |
robust_only |
SNN (PLIF) | 0.0 | 0.5 | SNN optimized for tamper resistance |
spikeguard |
SNN (PLIF) | 0.1 | 0.5 | Full method — both objectives |
10-class camera-trap classification:
tiger · leopard · elephant · deer · wild_boar · bear · monkey · bird · human · blank
Data modes:
- Simulation — CIFAR-10 remapped to wildlife classes (fast prototyping)
- Real — Folder-based wildlife image dataset (iWildCam or custom)
- Spike raster plots — visualize neural firing patterns per layer and timestep
- Pareto frontier — accuracy vs. energy trade-off visualization across all modes
- ONNX export — SNN exported as single-step (T=1) for deployment compatibility
- Dynamic quantization — INT8 post-training quantization for edge deployment
- AMD GPU support — ONNX Runtime with VitisAI/DML/ROCm provider detection
- Reproducible — full seeding (torch, numpy, random, CUDA, PYTHONHASHSEED)
- Spike count is a relative energy proxy, not absolute joule measurements. Actual hardware energy savings depend on deployment platform (neuromorphic chip vs. conventional GPU/CPU).
- CIFAR-10 simulation mode is for rapid prototyping. Real iWildCam data is needed for production evaluation.
- SNN→ONNX export uses single-step inference (T=1). Full temporal spiking dynamics are preserved in training but collapsed for deployment compatibility.
MIT License — see LICENSE for details.
Neuromorphic computing for conservation — because wildlife deserves efficient AI.