![]() |
DetoxAI is a Python package for debiasing neural networks in image classification tasks. It transforms biased models into fair and balanced ones with minimal code changes. |
---|---|
Website and demo: https://detoxai.github.io | Documentation: https://detoxai.readthedocs.io |
Install DetoxAI from PyPI:
pip install detoxai
import detoxai
model = ...
dataloader = ... # should output (input, label, protected attributes)
corrected = detoxai.debias(model, dataloader)
metrics = corrected["SAVANIAFT"].get_all_metrics()
model = corrected["SAVANIAFT"].get_model()
Minimal runnable example:
import torch
import torchvision
import detoxai
model = torchvision.models.resnet18(pretrained=True)
model.fc = torch.nn.Linear(model.fc.in_features, 2)
X = torch.rand(128, 3, 224, 224)
Y = torch.randint(0, 2, size=(128,))
PA = torch.randint(0, 2, size=(128,))
dataloader = torch.utils.data.DataLoader(list(zip(X, Y, PA)), batch_size=32)
results: dict[str, detoxai.CorrectionResult] = detoxai.debias(model, dataloader)
More examples: see examples/
folder.
DetoxAI transforms biased neural networks into fair models with simple code integration.
Learn how to add your own method →
- Saliency maps with Layer-wise Relevance Propagation (paper)
- Side-by-side comparisons of original vs. debiased models
- Aggregate visualizations to track model focus shift
Before/After Saliency Map | Aggregate Bias Visualization |
---|---|
![]() |
![]() |
Saliency maps show model focus during classification. | Aggregate visualizations show focus shift after debiasing. |
- Works with existing PyTorch models
- Standard dataloaders
- Single function call for multiple debiasing methods
curl -LsSf https://astral.sh/uv/install.sh | sh
# or pip install uv
uv venv
uv pip install -r pyproject.toml
source .venv/bin/activate
python main.py
pip install .
# or pip install -e . for editable install
pre-commit install
pre-commit run --all-files
chmod u+x ./build_docs.sh
./build_docs.sh
If you use DetoxAI, please cite:
@misc{detoxai2025,
author={Ignacy Stepka and Lukasz Sztukiewicz and Michal Wilinski and Jerzy Stefanowski},
title={DetoxAI: a Python Toolkit for Debiasing Deep Learning Models in Computer Vision},
year={2025},
url={https://github.com/DetoxAI/detoxai},
}
MIT License