Official PyTorch implementation of the TCSVT paper "Superpixel Segmentation With Edge Guided Local-Global Attention Network".
Mingzhu Xu1, Zhengyu Sun1, Yijun Hu1, Haoyu Tang1, Yupeng Hu1*, Xuemeng Song2*, Liqiang Nie3
1 Shandong University
2 Shandong University, Qingdao
3 Harbin Institute of Technology (Shen Zhen)
* Corresponding author
- Paper:
IEEE Xplore - Code Repository:
GitHub
- Introduction
- Highlights
- Project Structure
- Installation
- Data Preparation
- Usage
- Evaluation
- Demo / Visualization
- Citation
- License
This project is the official implementation of the paper "Superpixel Segmentation With Edge Guided Local-Global Attention Network" (ELGANet).
Superpixel segmentation is a fundamental task in computer vision. ELGANet introduces an Edge-Guided mechanism and a Local-Global Attention network, significantly improving boundary adherence and semantic consistency.
This repository provides:
- Complete training and inference code.
- Implementation of the edge-guided local-global attention network.
- Full preprocessing and evaluation pipeline based on the BSDS500 dataset.
- Edge-Guided Attention: Utilizes edge information to refine superpixel boundaries.
- Local-Global Context: Captures both local details and global contextual information.
- High Efficiency: Optimized PyTorch implementation with Cython-based post-processing to ensure connectivity.
- State-of-the-art Performance: Achieves strong results on ASA, CO, and BR-BP metrics.
.
├── data_preprocessing/ # BSDS500 data preprocessing scripts
├── eval_spixel/ # Evaluation scripts (bash & MATLAB)
├── third_party/ # External dependencies (including Cython connectivity module)
├── main.py # Main training script
├── run_demo.py # Inference demo
├── requirements.txt # Environment dependencies
└── LICENSE # License file
git clone [https://github.com/iLearn-Lab/ELGANet.git](https://github.com/iLearn-Lab/ELGANet.git)
cd ELGANetTo ensure superpixel connectivity, you need to compile the components in third_party:
cd third_party/cython/
python setup.py install --user
cd ../..pip install -r requirements.txt- Download the raw dataset from BSDS500 and extract it to
<BSDS_DIR>. - Run the preprocessing scripts to generate training and testing data:
cd data_preprocessing
python pre_process_bsd500.py --dataset=<BSDS_DIR> --dump_root=<DUMP_DIR>
python pre_process_bsd500_ori_sz.py --dataset=<BSDS_DIR> --dump_root=<DUMP_DIR>
cd ..The generated directory structure includes /train, /val, and /test folders, along with corresponding .txt path files.
Start training with the prepared dataset:
python main.py --data=<DUMP_DIR> --savepath=<CKPT_LOG_DIR>Fine-tune or resume training using a pretrained model:
python main.py --data=<DUMP_DIR> --savepath=<CKPT_LOG_DIR> --pretrained=<PATH_TO_THE_CKPT> Generate superpixel visualization results for images in a specific directory:
python run_demo.py --data_dir=PATH_TO_IMAGE_DIR --output=./demo The results will be saved in the ./demo/spixel_viz directory.
Following the evaluation protocol of FCN, we use the superpixel benchmark for evaluation.
- Download and compile the benchmark code according to the instructions。
- Edit variables in
eval_spixel/my_eval.sh(e.g.,IMG_PATH,GT_PATH,SEG_PATH). - Run the evaluation script:
cp eval_spixel/my_eval.sh <path/to/benchmark>/examples/bash/ cd <path/to/benchmark>/examples/ bash my_eval.sh
- Configure the paths in
plot_benchmark_curve.min MATLAB and run it to visualize ASA, CO, and BR-BP curves.
For your convenience in comparative analysis, we have provided the final results of the ELGANet model on four datasets (BSDS, NYU, KITTI, and DRIVE) at the following link Baidu Netdisk, which you may download at any time for comparison.
If you use this code or method in your research, please cite our work:
@ARTICLE{ELGANet2025TCSVT,
author={Xu, Mingzhu and Sun, Zhengyu and Hu, Yijun and Tang, Haoyu and Hu, Yupeng and Song, Xuemeng and Nie, Liqiang},
journal={IEEE Transactions on Circuits and Systems for Video Technology},
title={Superpixel Segmentation With Edge Guided Local-Global Attention Network},
year={2025},
volume={35},
number={12},
pages={11922-11934},
doi={10.1109/TCSVT.2025.3587485}}
- Thanks to SSN for providing the connectivity implementation.
- Thanks to superpixel-benchmark for providing the standard evaluation toolkit.
This project is released under the Apache License 2.0.