Submitted:
23 March 2025
Posted:
26 March 2025
You are already at the latest version
Abstract
Keywords:
1. Introduction
- Algorithmic Optimization: A novel thresholding technique that selectively retains high-importance activations to reduce computational cost.
- Unified Evaluation Suite: End-to-end benchmarking, including speed, memory, and explanation quality metrics (faithfulness, completeness, sensitivity, and Intersection over Union).
- Edge Device Deployment: Detailed analysis of running the framework on low-power devices, showing practical feasibility.
- User Study and Statistical Validation: A user study (n=120) indicating a 67.6% faster interpretation time, and large-scale statistical tests confirming significance.
2. Related Work
2.1. Explainable AI Techniques
2.2. Lightweight Architectures and Edge Deployment
2.3. Threshold-Based Explanation Simplification
3. Methodology
3.1. Grad-CAM Recap
3.2. Lightweight Enhancements
3.3. Implementation Details
3.4. Pseudocode Implementations for Core Algorithms
3.4.1. Threshold-Based Simplification Algorithm
3.4.2. Dynamic Threshold Search Algorithm
3.4.3. Optimized Grad-CAM Generation Algorithm
4. Extensions for Additional Architectures
4.0.1. Vision Transformers: transformer_explainability.py
4.0.2. Recurrent Neural Networks: rnn_explainability.py
4.0.3. Graph Neural Networks: gnn_explainability.py
4.0.4. Universal Explainability: universal_explainability.py
4.0.5. Performance on Vision and Text Transformers
4.0.6. Performance on Recurrent Neural Networks
5. System Architecture Diagram
6. Evaluation
6.1. Performance Benchmarks
6.2. Explanation Quality Metrics
6.2.1. Explanation of Key Evaluation Metrics
- Faithfulness: Measures how well the generated heatmap aligns with the features that the model used to make its prediction. A high faithfulness score indicates that the explanation accurately reflects the model’s decision-making process.
- Completeness: Evaluates the extent to which the explanation covers all the important features required for the model’s prediction. A more complete explanation captures all relevant information.
- Sensitivity: Assesses how the explanation changes in response to small variations in the input. High sensitivity may indicate that the explanation is closely tied to the input data.
- Intersection over Union (IoU): Commonly used in segmentation tasks, IoU measures the overlap between the predicted explanation region and the ground truth region. It is calculated as the area of overlap divided by the area of union.
- Precision: Indicates the proportion of the explained regions that are actually relevant.
- Recall: Measures the proportion of all relevant regions that are captured in the explanation.
- Dice Coefficient: A similarity metric that compares the overlap between two sets (e.g., the explanation and the ground truth), similar to IoU but with a different formulation.
- Boundary F1 Score: Evaluates how well the boundaries of the explanation match the boundaries of the ground truth regions.
6.3. Mobile Device Performance
6.4. Large-Scale Statistical Testing
6.5. User Study Analysis
7. Discussion
- Transformers: By leveraging each layer’s attention weights, we efficiently produce localized saliency maps for both vision-oriented (e.g., ViT, Swin) and text-based (e.g., BERT, RoBERTa, DistilBERT) Transformers. This enables our method to highlight the most influential tokens or patches with minimal computational overhead.
- RNN-based Models: Capturing hidden states and gradients across time steps allows our framework to identify pivotal intervals or features in LSTM, GRU, and BiLSTM architectures. This approach yields rapid, interpretable explanations for tasks involving extended sequences or time-series data.
- Investigate Attention-Threshold Interplay: Examine how different heads and layers influence threshold-based explanations in large-scale or multi-modal Transformers, optimizing the balance between interpretability and computational cost.
- Enhance Long-Sequence Interpretability: Develop specialized thresholding strategies (e.g., chunk-based or hierarchical) for tasks with extended inputs, ensuring stable performance and clarity of insights in RNN architectures.
- Customize for Domain-Specific Needs: Adapt threshold parameters and feature-fusion techniques for specialized contexts (e.g., medical text or financial forecasting), preserving robustness under domain-specific constraints.
- Broaden Benchmarking Efforts: Evaluate our framework on additional datasets and tasks (e.g., speech recognition, multi-modal classification) to confirm its suitability for a wide range of real-world scenarios.
- Local Gradient Overload: In regions with dense textures or intricate patterns, Grad-CAM explanations may be dominated by high-frequency local gradients, obscuring globally important features. Proposed Solution: Incorporate multi-scale feature fusion or adaptive smoothing to mitigate noise and stabilize saliency maps across different spatial scales.
- Contrast Sensitivity: In low-contrast scenes, gradient magnitudes alone may not suffice to distinguish foreground from background. Proposed Solution: Apply contrast enhancement techniques (e.g., histogram equalization) or domain-specific normalization to sharpen boundaries, coupled with threshold tuning to preserve subtle but crucial details.
- Overlapping or Multiple Objects: When multiple objects or features coexist, thresholding can merge them into a single salient zone or discard them entirely. Proposed Solution: Use semantic-aware thresholding that leverages object boundaries or class labels, ensuring distinct objects remain identifiable in the saliency map.
- Conduct Ablation Studies: Evaluate the impact of multi-scale vs. single-scale approaches, contrast-enhancement vs. raw images, and semantic vs. purely gradient-based thresholding in different failure-prone settings.
- Expand Data Diversity: Incorporate more samples with dense textures, complex backgrounds, and low-contrast conditions during both model training and evaluation, thus improving overall robustness.
- Develop Domain-specific Modules: Tailor threshold parameters and feature-fusion methods to specific application areas (e.g., medical imaging, autonomous driving) where texture and contrast variations are prevalent.
7.1. Key Conclusions and Impact Enhancements
- Consistent performance across diverse domains: The framework works effectively on natural images, medical scans, satellite imagery, autonomous driving scenes, and document images, with a 50% threshold providing optimal results across all tested domains.
-
Competitive performance vs specialized libraries: The baseline comparison shows:
- -
- Captum is faster (approximately 2.82x) but our implementation achieves comparable explanation quality.
- -
- Our lightweight implementation has minimal memory overhead (0.45MB vs 0.39MB for the baseline).
- -
- Our approach requires significantly fewer lines of code (approximately 120 vs 600) and has simpler dependencies.
- Adaptive thresholding effectiveness: The adaptive thresholding visualizations demonstrate that our strategies effectively handle complex cases, with a hybrid approach performing best across different image types.
- Stability metrics: Evaluations on diverse datasets reveal high thresholding stability with consistent energy retention (around 0.7–0.8) and average precision (approximately 0.9–0.94) across domains.
-
Technical Depth Improvements
- 1.1.
- Transformer and RNN Support: Dedicated modules (transformer_explainability.py and rnn_explainability.py) have been implemented, featuring thresholding strategies for Transformers and temporal importance analysis for LSTM/GRU models. Benchmarks show a 370x speedup over traditional methods.
- 1.2.
- Dynamic Threshold Scheduling: Adaptive thresholding is implemented in examples/adaptive_thresholding.py with content-aware thresholding, domain-specific rules for medical imaging, confidence-based threshold selection, and multi-peak detection.
- 1.3.
- Multi-objective Optimization: The framework now simultaneously optimizes speed, memory usage, and explanation quality using reinforcement learning and evaluation metrics such as IoU and Dice coefficients.
-
Expanded Experiments
- 2.1.
- Domain-specific applications have been developed for medical imaging (examples/medical_imaging_example.py), autonomous driving (examples/autonomous_driving_example.py), and financial fraud detection.
- 2.2.
- User studies have been expanded to include larger and more diverse samples, incorporating trust, decision support measurements, and cross-cultural preference analysis.
-
Fairness and Ethics Analysis
- 3.1.
- Fairness assessments have been added in examples/fairness_assessment.py, testing across demographic groups using Equalized Odds and Demographic Parity metrics, with bias mitigation strategies.
- 3.2.
- Regulatory compliance is addressed through documentation for GDPR and HIPAA, audit logging, and built-in transparency principles.
-
Practical Applications
- 4.1.
- Enhanced cross-platform support now includes additional embedded devices (e.g., Jetson Nano) and multiple frameworks (TensorFlow, ONNX), with examples for commercial integration.
8. Enhanced Evaluation Metrics and Visual Results
8.1. Precision-Recall Curves for Different Threshold Values
8.2. Ablation Studies
8.3. Comparison with Other Lightweight Explainability Methods
8.4. Visualization Examples Across Different Datasets

8.5. Failure Cases Analysis
- Complex textures: High-frequency details can produce fragmented or diffuse explanations, as the method struggles to isolate relevant signals from noise.
- Multi-object interference: Overlapping or closely spaced objects may merge into a single salient region or be partially discarded.
- Fine-grained classifications: Subtle inter-class distinctions can be lost when thresholding suppresses minor yet important features.
- Low-contrast scenes: Foreground and background may blend, making it difficult to retain truly critical areas.
- Local Feature Over-reliance.Cause: In highly textured or cluttered regions, Grad-CAM explanations can fluctuate significantly across adjacent areas, revealing the model’s over-dependence on localized patterns. Remedy: Multi-scale feature fusion can incorporate broader contextual information, stabilizing explanations in densely textured scenes.
- Contrast Sensitivity.Cause: In low-contrast images, salient boundaries become blurred, making it difficult to isolate key features. Remedy: Adaptive contrast enhancement or specialized attention modules can clarify important regions, improving the saliency map’s discrimination ability.
- Multi-object Interference.Cause: Multiple objects or overlapping features can lead threshold-based methods to discard relevant segments or merge distinct objects. Remedy: Dynamic thresholding with semantic cues (e.g., object boundaries) prevents under- or over-segmentation in multi-object scenarios.
- Limited Training Coverage.Cause: Models trained on primarily simple or high-contrast data may struggle in more complex or low-contrast situations. Remedy: Augmentation with challenging samples enhances both the model’s robustness and the fidelity of its explanations.
8.6. Ground Truth Comparisons

| Dataset | Method | IoU | Dice | Boundary F1 | Precision | Recall |
|---|---|---|---|---|---|---|
| PASCAL VOC | Baseline Grad-CAM | 0.48 | 0.58 | 0.45 | 0.52 | 0.75 |
| My (5%) | 0.43 | 0.53 | 0.41 | 0.61 | 0.56 | |
| My (10%) | 0.46 | 0.56 | 0.44 | 0.58 | 0.62 | |
| MS COCO | Baseline Grad-CAM | 0.51 | 0.63 | 0.48 | 0.55 | 0.79 |
| My (5%) | 0.45 | 0.57 | 0.42 | 0.64 | 0.58 | |
| My (10%) | 0.49 | 0.61 | 0.46 | 0.61 | 0.65 | |
| Medical | Baseline Grad-CAM | 0.58 | 0.68 | 0.52 | 0.63 | 0.76 |
| My (5%) | 0.51 | 0.62 | 0.47 | 0.72 | 0.59 | |
| My (10%) | 0.55 | 0.65 | 0.50 | 0.68 | 0.65 |
8.7. Explainability Methods Comparison
| Method | Avg Time (s) | Avg Memory (MB) | Avg IoU |
|---|---|---|---|
| My Lightweight | 0.4184 | 0.45 | N/A |
| RISE | 7.5119 | 21.95 | 0.1000 |
| LIME | 46.2515 | 58.69 | 0.0887 |
| Method | Speedup vs LIME |
|---|---|
| My Lightweight | 110.55x |
| RISE | 6.16x |
| LIME | 1.00x |
| Method | Memory Reduction vs LIME (%) |
|---|---|
| My Lightweight | 99.23% |
| RISE | 62.60% |
| LIME | 0.00% |

9. Addressing Thresholding Limitations Across Architectures
9.0.1. Documentation Enhancements
9.0.2. Core Implementation
9.0.3. Advanced Thresholding Techniques
9.0.4. Demonstration Script
9.0.5. Utility Functions
10. Conclusion and Future Work
Data Availability Statement
Acknowledgments
References
- Selvaraju, R. R. , Cogswell, M., Das, A., Vedantam, R., Parikh, D., & Batra, D. (2017). "Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization." Proceedings of the IEEE International Conference on Computer Vision (ICCV).
- Simonyan, K. , Vedaldi, A., & Zisserman, A. (2013). "Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps. arXiv preprint arXiv:1312.6034, arXiv:1312.6034.
- Zeiler, M. D. , & Fergus, R. (2014). "Visualizing and Understanding Convolutional Networks." European Conference on Computer Vision (ECCV).
- Howard, A. G. , et al. (2017). "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications. arXiv preprint arXiv:1704.04861, arXiv:1704.04861.
- Zhang, X. , Zhou, X., Lin, M., & Sun, J. (2018). "ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices." Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR).
- Tan, M. , & Le, Q. (2019). "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks." International Conference on Machine Learning (ICML).
- Felzenszwalb, P. F. , & Huttenlocher, D. P. (2004). "Efficient Graph-Based Image Segmentation." International Journal of Computer Vision, 59(2), 167–181.




| Model | Type | Avg Time (s) | Avg Memory (MB) |
|---|---|---|---|
| ViT | Vision Transformer | 1.0393 | 3.66 |
| Swin | Vision Transformer | 0.3341 | 3.62 |
| BERT | Text Transformer | 0.4423 | 3.15 |
| RoBERTa | Text Transformer | 0.4782 | 3.38 |
| DistilBERT | Text Transformer | 0.2759 | 2.67 |
| Model | Type | Avg Time (s) | Avg Memory (MB) |
|---|---|---|---|
| LSTM | LSTM Classifier | 0.0245 | 0.01 |
| GRU | GRU Classifier | 0.0124 | 0.01 |
| BILSTM | Bidirectional LSTM | 0.0309 | 0.01 |
| TS_LSTM | Time Series LSTM | 0.0299 | 0.01 |
| Threshold | Time (ms) | Memory (MB) | Speedup | Mem Reduction (%) | Faithfulness |
|---|---|---|---|---|---|
| Baseline | 100 | 256 | 1.0x | 0% | 1.00 |
| 1% | 0.31 | 158 | 324.74x | 38.15% | 1.00 |
| 5% | 0.29 | 163 | 346.89x | 36.21% | 1.00 |
| 10% | 0.35 | 169 | 284.96x | 33.80% | 1.00 |
| 20% | 0.31 | 182 | 322.08x | 28.95% | 1.00 |
| Dynamic | 0.32 | 175 | 310.45x | 31.67% | 1.00 |
| Device | Baseline (ms) | 10% (ms) | Speedup | FPS |
|---|---|---|---|---|
| Raspberry Pi | 350 | 4.8 | 72.3x | 208.3 |
| Android | 420 | 4.4 | 94.6x | 227.3 |
| iPhone | 560 | 4.5 | 123.8x | 222.2 |
| Configuration | Time (ms) | Memory (MB) | Speedup | Quality Score |
|---|---|---|---|---|
| Baseline Grad-CAM | 100.0 | 256 | 1.0x | 1.0 |
| + Optimized Hook Implementation | 65.3 | 248 | 1.53x | 1.0 |
| + Gradient Memory Release | 43.8 | 205 | 2.28x | 1.0 |
| + Vectorized Operations | 28.7 | 195 | 3.48x | 1.0 |
| + 10% Threshold Simplification | 0.35 | 169 | 285.7x | 0.97 |
| + Dynamic Threshold (Full Impl.) | 0.32 | 175 | 312.5x | 0.98 |
| Method | Time (ms) | Memory (MB) | Quality Score | Mobile Compatible |
|---|---|---|---|---|
| My Framework (10% threshold) | 0.35 | 169 | 0.97 | Yes |
| Guided Backpropagation | 1.82 | 215 | 0.85 | Partial |
| LIME (reduced samplings) | 240.5 | 352 | 0.91 | No |
| Integrated Gradients (5 steps) | 4.76 | 297 | 0.89 | Partial |
| SHAP (5 samples) | 320.8 | 412 | 0.94 | No |
| Occlusion (4x4 grid) | 15.3 | 184 | 0.82 | Limited |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).