Skip to content

SegClarity: An attribution-based XAI workflow for layer-wise interpretability in semantic segmentation

License

Notifications You must be signed in to change notification settings

iheb-brini/SegClarity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SegClarity

Semantic Segmentation & Explainable AI Framework for Documents and Urban Scenes

Python
PyTorch
License
Paper

SegClarity is a unified framework designed for semantic segmentation and explainable AI, supporting both:

  • Document Layout Analysis
  • Urban Scene Understanding (Cityscapes)

It provides pre-trained models, attribution methods, visualization utilities, and experiment notebooks.


✨ Features

πŸ—‚ Document Segmentation

  • Models trained on UTP and splitAB1 datasets
  • Layout segmentation using UNet & LUNet architectures

πŸ™ Urban Scene Segmentation

  • UNet models trained on Cityscapes
  • Full semantic segmentation pipeline

πŸ” Explainable AI

  • Attribution methods via Captum
  • Integrated Gradients, GradCAM, Occlusion, and more
  • Visual explainability on documents & scenes

πŸ“Š Visualization Tools

  • Side-by-side predictions
  • Attribution heatmaps
  • Overlay masks, saliency, and class‑wise contributions

πŸ“ Project Structure

SegClarity/
β”œβ”€β”€ Modules/
β”‚   β”œβ”€β”€ Architecture/         # UNet, LUNet implementations
β”‚   β”œβ”€β”€ Dataset/              # Dataset loaders & transforms
β”‚   β”œβ”€β”€ CityscapeDataset/     # Cityscapes utilities
β”‚   β”œβ”€β”€ ModelXAI/             # Explainable AI methods
β”‚   β”œβ”€β”€ Attribution/          # Attribution pipeline
β”‚   β”œβ”€β”€ Visualization/        # Plotting & rendering utils
β”‚   └── ...
β”œβ”€β”€ Notebooks/                # Experiment notebooks
β”œβ”€β”€ models/                   # Pre-trained weights
β”œβ”€β”€ datasets/                 # Document datasets
└── requirements.txt

πŸš€ Installation

1. Clone the repository

git clone https://github.com/iheb-brini/SegClarity.git
cd SegClarity

2. Create a virtual environment

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

πŸ“Œ Note: Requirements include PyTorch with CUDA 12.6. Adjust if needed.


πŸ“¦ Pre‑trained Models

Download the weights from the release page:
https://github.com/iheb-brini/SegClarity/releases/tag/model_weights

Place them under:

models/
β”œβ”€β”€ cityscapes/
β”œβ”€β”€ splitAB1/
└── UTP/

πŸ—„ Datasets

πŸ“„ Document Datasets (UTP & splitAB1)

Already included in:

datasets/

πŸ™ Cityscapes Dataset (optional)

Download from: https://www.cityscapes-dataset.com/file-handling/?packageID=3

Required files:

  • leftImg8bit_trainvaltest.zip
  • gtFine_trainvaltest.zip

Extract into:

datasets/cityscapes/
β”œβ”€β”€ leftImg8bit/
└── gtFine/

πŸ§ͺ Running Experiments

Install Jupyter:

pip install jupyter notebook

Run:

jupyter notebook

Provided notebooks:

  • 01_Model_predictions_on_documents.ipynb β€” Document segmentation evaluation
  • 02_Model_predictions_on_cityscapes.ipynb β€” Urban scene segmentation
  • 03_Attributions_on_documents.ipynb β€” Document explainability
  • 04_Attributions_on_cityscapes.ipynb β€” Scene explainability

Each notebook allows configuration of:

  • Dataset
  • Architecture (UNet / LUNet)
  • Pretrained model choice
  • CPU/GPU runtime

βš™οΈ System Requirements

  • Python 3.10–3.12
  • CUDA 12.6 (optional)
  • RAM: 8GB minimum, 16GB recommended
  • Disk: ~15GB for datasets + models

❗ Troubleshooting

1. CUDA Out of Memory

  • Reduce batch size
  • Use CPU mode

2. Missing Model Weights

Ensure the structure is:

models/<dataset>/<architecture>/<model>.pth

3. Dataset Not Found

Check path:

datasets/<dataset-name>/

4. Import Errors

Reinstall dependencies:

pip install -r requirements.txt

πŸ“š Citation

If you use SegClarity in your research, please cite:

@article{Brini2025SegClarity,
  author    = {Iheb Brini and others},
  title     = {SegClarity: Semantic Segmentation with Explainable AI},
  journal   = {Journal of Imaging},
  volume    = {11},
  number    = {12},
  pages     = {424},
  year      = {2025},
  publisher = {MDPI},
  doi       = {10.3390/jimaging11120424},
  url       = {https://www.mdpi.com/2313-433X/11/12/424}
}

πŸ“„ License

This project is licensed under the MIT License.
See the LICENSE file for more information.

About

SegClarity: An attribution-based XAI workflow for layer-wise interpretability in semantic segmentation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages