Hybrid-Attention-Segformer extends the SegFormer architecture for semantic segmentation by integrating hybrid attention modules that improve both local detail and global context modeling. The project includes training and evaluation scripts for datasets like Mapillary Vistas, as well as demo utilities for visualization.
0
stars
10
commits
Python
primary language
Jan 11, 2026
updated
The paper introduces a hybrid attention module that fuses local and global token dependencies.
.
├── dataset_preprocessed_512x512
│ ├── config_v1.2.json
│ ├── training
│ │ ├── images
│ │ │ ├── -0C1J9CvgFP4BTVLXNeNZA.jpg
│ │ │ └── ...
│ │ └── labels
│ │ ├── -0C1J9CvgFP4BTVLXNeNZA.png
│ │ └── ...
│ └── validation
│ ├── images
│ │ ├── -3-MmXdwhyIQhtb4-8NqHQ.jpg
│ │ └── ...
│ └── labels
│ ├── -3-MmXdwhyIQhtb4-8NqHQ.png
│ └── ...
│
├── trainer
│ ├── config.py
│ ├── dataset.py
│ ├── main.py
│ ├── model.py
│ ├── train.py
│ └── windowedLocalSelfAttention.py
│
├── outputs
│ ├── Segformer_B2
│ │ ├── model.pt
│ │ ├── predictions
│ │ │ ├── -3-MmXdwhyIQhtb4-8NqHQ
│ │ │ │ ├── image.jpg
│ │ │ │ ├── mask.png
│ │ │ │ └── pred.png
│ │ │ └── ...
│ │ └── training_log.csv
│ └── ...
│
└── demo
├── demo_config.py
└── demo.py
This project uses a custom pre-processed version of the Mapillary Vistas Dataset. All images are initially resized to a height of 512 px, with the width scaled proportionally. They are then center-cropped to ensure all final input images are a square size of 512x512 pixels.
Install gdown:
pip3 install gdown
Download the Dataset:
gdown 11ZPJbu9ZVcWOaSFcyV6tUnwuW107nrM3
Unzip the File:
unzip dataset_preprocessed_512x512.zip
Place into Structure:
Place the extracted dataset_preprocessed_512x512 directory in the project root, matching the structure detailed in the Project Structure section.
This section contains instruction on how to train the model. In this project, we evaluated five distinct configurations based on the SegFormer backbone.
Before starting training, ensure all necessary dependencies are installed and that the dataset is correctly placed in the dataset_preprocessed_512x512 directory.
Change Directory:
cd trainer
Run Training Command:
Choose one of the following commands to start training the desired model architecture. The training parameters (e.g. epochs, batch size) are managed within config.py but can be overriden with command line arguments (e.g. --epochs).
# SegFormer Baseline Models
python3 main.py --model Segformer_B0
python3 main.py --model Segformer_B2
# Modified Models (with Windowed Local Self-Attention)
python3 main.py --model Segformer_B0_modified_1
python3 main.py --model Segformer_B0_modified_2
python3 main.py --model Segformer_B2_modified_1
../outputs/ directory, categorized by model name (e.g. ../outputs/Segformer_B2/).model.pt within the corresponding model folder.predictions directory.The live demonstration uses the demo.py script to perform real-time segmentation using one of the trained models.
model.pt) is available in your outputs/ directory.To change to a different model for real-time segmentation, you can specify it in the demo_config.py or override it in the command line arguments:
--model specifies which trained model architecture to load (e.g., Segformer_B2, etc.).--model_filepath specifies the filepath to saved trained model (model.pt).Change Directory:
cd demo
Run the Demo:
python3 demo.py
10 commits
Python
100.0%
Hybrid-Attention-Segformer extends the SegFormer architecture for semantic segmentation by integrating hybrid attention modules that improve both local detail and global context modeling. The project includes training and evaluation scripts for datasets like Mapillary Vistas, as well as demo utilities for visualization.
0
stars
10
commits
Python
primary language
Jan 11, 2026
updated
The paper introduces a hybrid attention module that fuses local and global token dependencies.
.
├── dataset_preprocessed_512x512
│ ├── config_v1.2.json
│ ├── training
│ │ ├── images
│ │ │ ├── -0C1J9CvgFP4BTVLXNeNZA.jpg
│ │ │ └── ...
│ │ └── labels
│ │ ├── -0C1J9CvgFP4BTVLXNeNZA.png
│ │ └── ...
│ └── validation
│ ├── images
│ │ ├── -3-MmXdwhyIQhtb4-8NqHQ.jpg
│ │ └── ...
│ └── labels
│ ├── -3-MmXdwhyIQhtb4-8NqHQ.png
│ └── ...
│
├── trainer
│ ├── config.py
│ ├── dataset.py
│ ├── main.py
│ ├── model.py
│ ├── train.py
│ └── windowedLocalSelfAttention.py
│
├── outputs
│ ├── Segformer_B2
│ │ ├── model.pt
│ │ ├── predictions
│ │ │ ├── -3-MmXdwhyIQhtb4-8NqHQ
│ │ │ │ ├── image.jpg
│ │ │ │ ├── mask.png
│ │ │ │ └── pred.png
│ │ │ └── ...
│ │ └── training_log.csv
│ └── ...
│
└── demo
├── demo_config.py
└── demo.py
This project uses a custom pre-processed version of the Mapillary Vistas Dataset. All images are initially resized to a height of 512 px, with the width scaled proportionally. They are then center-cropped to ensure all final input images are a square size of 512x512 pixels.
Install gdown:
pip3 install gdown
Download the Dataset:
gdown 11ZPJbu9ZVcWOaSFcyV6tUnwuW107nrM3
Unzip the File:
unzip dataset_preprocessed_512x512.zip
Place into Structure:
Place the extracted dataset_preprocessed_512x512 directory in the project root, matching the structure detailed in the Project Structure section.
This section contains instruction on how to train the model. In this project, we evaluated five distinct configurations based on the SegFormer backbone.
Before starting training, ensure all necessary dependencies are installed and that the dataset is correctly placed in the dataset_preprocessed_512x512 directory.
Change Directory:
cd trainer
Run Training Command:
Choose one of the following commands to start training the desired model architecture. The training parameters (e.g. epochs, batch size) are managed within config.py but can be overriden with command line arguments (e.g. --epochs).
# SegFormer Baseline Models
python3 main.py --model Segformer_B0
python3 main.py --model Segformer_B2
# Modified Models (with Windowed Local Self-Attention)
python3 main.py --model Segformer_B0_modified_1
python3 main.py --model Segformer_B0_modified_2
python3 main.py --model Segformer_B2_modified_1
../outputs/ directory, categorized by model name (e.g. ../outputs/Segformer_B2/).model.pt within the corresponding model folder.predictions directory.The live demonstration uses the demo.py script to perform real-time segmentation using one of the trained models.
model.pt) is available in your outputs/ directory.To change to a different model for real-time segmentation, you can specify it in the demo_config.py or override it in the command line arguments:
--model specifies which trained model architecture to load (e.g., Segformer_B2, etc.).--model_filepath specifies the filepath to saved trained model (model.pt).Change Directory:
cd demo
Run the Demo:
python3 demo.py
10 commits
Python
100.0%