Abstract
While machine learning fairness has made significant progress in recent years, most existing solutions focus on tabular data and are poorly suited for vision-based classification tasks, which rely heavily on deep learning. To bridge this gap, we introduce DetoxAI, an open-source Python library for improving fairness in deep learning vision classifiers through post-hoc debiasing. DetoxAI implements state-of-the-art debiasing algorithms, fairness metrics, and visualization tools. It supports debiasing via interventions in internal representations and includes attribution-based visualization tools and quantitative algorithmic fairness metrics to show how bias is mitigated. This paper presents the motivation, design, and use cases of DetoxAI, demonstrating its tangible value to engineers and researchers.
Introduction
As algorithmic fairness gains traction, existing tools often fall short for computer vision practitioners. Popular libraries like AIF360 and Fairlearn are primarily designed for tabular data, assuming datasets fit in memory and using structures (like Pandas/NumPy) that are incompatible with the batch-processing requirements of high-dimensional image data. Furthermore, many existing methods are "black-box" in nature, adjusting only final classification thresholds without addressing the biased internal representations that drive model decisions.
DetoxAI bridges these gaps by providing a PyTorch-native library that targets the internal layers of vision models. It allows practitioners to visualize, quantify, and eliminate bias by intervening directly in a model's internal representations—all without requiring full model retraining.
Methodology and Design
DetoxAI provides a unified, object-oriented API centered around the detoxai.debias(...) function. The toolkit implements several state-of-the-art post-hoc debiasing techniques:
- Representation-level Interventions: Methods such as LEACE (Linear Concept Erasure) and Savani/Zhang-based algorithms modify internal neural network activations to "erase" information related to protected attributes (e.g., race or gender).
- Artifact Removal Adaptation: The library repurposes Class-Artifact Compensation (ClArC), originally designed for removing image artifacts, as a tool for fairness.
- Output Calibration: For simpler use cases, it includes Threshold Optimization to adjust the final decision boundary.
The library utilizes PyTorch hooks to automatically adapt to various model architectures, ensuring seamless integration into existing workflows without requiring manual code rewrites.
Evaluation and Results
The toolkit's utility is demonstrated through tasks such as Facial Expression Recognition. In one use case, the model was found to be biased by the presence of a "necktie" when detecting smiles. DetoxAI allows for both qualitative and quantitative assessment of the debiasing process.
Qualitative Identification
By integrating saliency maps, DetoxAI enables researchers to visually confirm if a model has stopped relying on biased features. For example, saliency maps shift from focusing on a necktie to focusing on relevant facial features like the mouth after debiasing.
Quantitative Assessment
DetoxAI explicitly quantifies the fairness-performance trade-off. It provides built-in tools to plot the relationship between predictive performance (e.g., F1 Score) and fairness metrics such as Equalized Odds, Demographic Parity, and Accuracy Parity. This allows engineers to measure the reduction in "GAP"—the performance difference across protected groups.
Discussion and Future Work
DetoxAI offers a highly efficient post-hoc approach, allowing engineers to "fix" pre-trained models (like ResNet50) without the massive computational cost of retraining from scratch. However, several areas for future development remain:
- Task Complexity: The current toolkit is optimized for binary classification and binary protected attributes. Expanding to multi-class and multi-label scenarios is a priority.
- Framework Support: While powerful for the PyTorch ecosystem, the library does not yet support TensorFlow or JAX.
- Data Requirements: Although faster than retraining, representation-level interventions still require a "debiasing dataset" and some computational overhead to calculate transformations.
By lowering the barrier to entry for production engineers, DetoxAI provides a standardized, accessible path toward more equitable computer vision systems.
Summary updated