Sovereign 8s.is mirror of standardgalactic/BCC_Patterns_XAI
  • Python 99.8%
  • Dockerfile 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-02-05 11:43:25 +01:00
assets first commit 2026-02-05 11:43:25 +01:00
Code first commit 2026-02-05 11:43:25 +01:00
.env.example first commit 2026-02-05 11:43:25 +01:00
.gitignore first commit 2026-02-05 11:43:25 +01:00
Dockerfile first commit 2026-02-05 11:43:25 +01:00
isic_files.csv first commit 2026-02-05 11:43:25 +01:00
README.md first commit 2026-02-05 11:43:25 +01:00
requirements.txt first commit 2026-02-05 11:43:25 +01:00

MultiTask Learning AI System to Assist BCC Diagnosis with Dual Explanation

This repository provides the official implementation for the research presented in the manuscript: "MultiTask Learning AI system to assist BCC diagnosis with dual explanation".

Our work introduces a clinically grounded Artificial Intelligence system designed to support teledermatology workflows, specifically for the diagnosis of Basal Cell Carcinoma (BCC). By integrating Multi-Task Learning (MTL) with a dual-explanation framework, the system provides high-accuracy triage while offering transparent, pattern-based clinical reasoning and validated visual attention maps.

BCC Diagnosis Workflow

About this Research

Basal Cell Carcinoma (BCC) represents approximately 75% of all skin cancer cases. The increasing volume of teledermatology requests has placed a significant burden on public healthcare systems, creating an urgent need for intelligent prioritization tools. However, many existing AI solutions operate as "black boxes," lacking the transparency necessary for clinical adoption.

Our approach addresses this gap by mimicking the diagnostic logic used by dermatologists:

  1. Binary Classification: Rapidly determines if a lesion is BCC or Non-BCC.
  2. Pattern Recognition: Identifies specific dermoscopic criteria—such as ovoid nests or arborizing telangiectasia—to justify the diagnosis.
  3. Visual Explanation: Generates heatmaps (Grad-CAM) that are statistically validated to align with the regions an expert dermatologist would focus on.

Core Contributions

  • Clinical Deployment: We utilized the MobileNet-V2 architecture to ensure the system is lightweight enough for real-world clinical hardware.
  • Addressing Imbalance: We implemented Focal Loss and advanced sampling to handle the inherent scarcity of certain dermatological patterns.
  • Consensus Intelligence: An Expectation-Maximization algorithm was used to derive a standard reference from multiple specialist annotations, reducing individual subjectivity.
  • Quantitative Validation: Beyond visual maps, we employed statistical energy analysis to prove that the AI's focus matches clinical reality.

Our Approach

Diagnostic Criteria

The system is built upon established dermatological rules. A diagnosis is guided by the detection of:

  • Negative Criterion: The presence of a Pigment Network (which typically suggests a Non-BCC lesion).
  • Positive BCC Patterns: Ulceration, Ovoid Nests, Multiglobules, Maple Leaf-like areas, Spoke Wheel areas, and Arborizing Telangiectasia.

The Dual-Explanation Framework

The architecture is designed to be more than a classifier. It acts as a diagnostic aid that provides two layers of insight:

  • Symbolic Reasoning: The model lists the specific patterns it detected, allowing a clinician to verify the logic.
  • Spatial Verification: Through Grad-CAM and Grad-CAM++, the system highlights the physical regions in the image that triggered the detection, which we validate against expert-drawn segmentation masks.

Repository Organization

Codebase and Modules

The implementation is organized into several key modules within the Code/ directory:

  • Training Pipelines: main_Fold_Binary.py and main_Fold_Patterns.py handle the K-Fold cross-validation for both binary triage and multi-label pattern recognition.
  • Model Logic: get_models.py and engine.py manage the architecture definitions and the core training loops.
  • Explainability Tools: GradCAM.py and GradCAM++.py generate visual maps, while energy_analysis.py provides the mathematical foundation for validating those maps.
  • Statistical Analysis: statistical_tests.py and Processing_crops_GradCAM_Statistics.py calculate metrics like Cohen's d to quantify the alignment between the AI and the dermatologist.

Documentation

  • Paper.tex: The LaTeX source file for the manuscript, containing the full narrative and experimental details.
  • assets/: Visual diagrams and workflow illustrations.

Getting Started

Prerequisites

The system is developed for Python 3.10+ environments. While a Dockerfile is provided for fully containerized execution, local installation is straightforward.

Installation and Setup

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_name>
    
  2. Install Dependencies: We recommend using a virtual environment to manage the required libraries.

    pip install -r requirements.txt
    
  3. Configure Environment: Define your local data and experiment paths in a .env file. You can use .env.example as a template.

    cp .env.example .env
    

Usage Workflow

1. Training the System

The training follows a stratified K-Fold approach to ensure results are robust and generalizable.

  • For Binary Triage: Run python Code/main_Fold_Binary.py.
  • For Pattern Recognition: Run python Code/main_Fold_Patterns.py. This stage uses specialized loss functions to account for rare clinical patterns.

2. Generating Explanations

Once a model is trained, you can generate visual heatmaps to inspect its decision-making process:

python Code/GradCAM.py

3. Validation

To perform the statistical validation described in the paper (comparing AI attention to expert masks):

python Code/Processing_GradCAM_with_energy.py
python Code/statistical_tests.py

Results and Performance

The system was rigorously evaluated on 1,559 images collected from 60 primary care centers in Andalusia, Spain.

  • Diagnostic Accuracy: The system achieved a 90% accuracy rate for BCC detection.
  • Clinical Reliability: In 99% of BCC-positive cases, the model correctly identified at least one clinically relevant pattern.
  • Expert Alignment: Statistical tests confirmed a "Very Large" effect size (Cohen's d = 1.972) in how well the AI's visual focus overlapped with the areas manually segmented by dermatologists.

Authors and Affiliations

The development of this system was a collaborative effort between engineering and medical teams:

  • Engineering: Iván Matas, Carmen Serrano, and Begoña Acha (Universidad de Sevilla).
  • Clinical: Francisca Silva-Clavería, Amalia Serrano, and Tomás Toledo-Pastrana (Hospital Universitario Virgen Macarena and Quirón Salud).

Citation

If you utilize this code or the dual-explanation framework in your research, please cite our manuscript:

@article{Matas2026BCC,
  title={MultiTask Learning AI system to assist BCC diagnosis with dual explanation},
  author={Matas, Iván and Serrano, Carmen and Silva-Clavería, Francisca and others},
  journal={Submission to Springer Nature},
  year={2026}
}