DehazeSNN integrates a U-Net-like encoder-decoder architecture with Spiking Neural Networks (SNNs), using an Orthogonal Leaky-Integrate-and-Fire Block (OLIFBlock) for efficient cross-channel communication. This yields competitive dehazing quality with fewer parameters and MACs compared to Transformer-based methods.
1# Clone the DehazeSNN repository (for model code + custom CUDA kernels)
2git clone https://github.com/HaoranLiu507/DehazeSNN.git
3cd DehazeSNN
4
5# Create environment (requires CUDA 12.x)
6conda create -n DehazeSNN python=3.11 -y
7conda activate DehazeSNN
8
9# Install PyTorch with CUDA 12.1
10conda install pytorch=2.1.2 torchvision pytorch-cuda=12.1 -c pytorch -c nvidia -y
11
12# Install dependencies
13pip install huggingface_hub safetensors cupy-cuda12x timm
1import torch
2from PIL import Image
3import numpy as np
4
5# Import from the cloned repository
6from models.hub import DehazeSNNHub
7
8# Load model (default: DehazeSNN-L trained on RESIDE-ITS)
9model = DehazeSNNHub.from_pretrained("FengShaner/DehazeSNN")
10model.cuda().eval()
11
12# Load a different variant
13# model = DehazeSNNHub.from_pretrained("FengShaner/DehazeSNN", revision="m-reside-6k")
14
15# Prepare input image (RGB, normalized to [-1, 1])
16img = Image.open("hazy_image.jpg").convert("RGB")
17img_np = np.array(img).astype(np.float32) / 255.0
18img_tensor = torch.from_numpy(img_np).permute(2, 0, 1).unsqueeze(0) # [1, 3, H, W]
19img_tensor = (img_tensor - 0.5) / 0.5 # normalize to [-1, 1]
20img_tensor = img_tensor.cuda()
21
22# Inference
23with torch.no_grad():
24 output = model(img_tensor).clamp(-1, 1)
25
26# Convert output back to image
27output = (output * 0.5 + 0.5).squeeze(0).permute(1, 2, 0).cpu().numpy()
28output = (output * 255).astype(np.uint8)
29Image.fromarray(output).save("dehazed_image.jpg")
1@INPROCEEDINGS{11228727,
2 author={Li, Huibin and Liu, Haoran and Liu, Mingzhe and Xiao, Yulong and Li, Peng and Zan, Guibin},
3 booktitle={2025 International Joint Conference on Neural Networks (IJCNN)},
4 title={U-Net-Like Spiking Neural Networks for Single Image Dehazing},
5 year={2025},
6 pages={1-9},
7 doi={10.1109/IJCNN64981.2025.11228727}
8}
This project is released under the MIT License.