All Projects

SkinCBM: Concept Bottleneck Models for Interpretable Skin Lesion Diagnosis

Implementation of Concept Bottleneck Models for interpretable skin lesion diagnosis, enabling clinician-guided concept intervention at inference time using the 7-point checklist protocol.

Matthew J. Cockayne
active
PyTorch Python Jupyter ResNet

Overview

SkinCBM implements Concept Bottleneck Models (CBMs) for dermoscopic image classification, building on Koh et al. (2020). Unlike conventional black-box classifiers, CBMs enforce an interpretable intermediate representation — predicted clinical concepts — through which all diagnostic reasoning must pass.

Architecture

A CBM decomposes classification into two stages:

Image --> Concept Encoder --> Concept Predictions --> Task Predictor --> Diagnosis
          (ResNet-50)         (7-point checklist)     (Linear layer)

The concept encoder predicts clinically meaningful attributes (e.g. pigment network, blue-whitish veil), and a linear task predictor maps these to a binary melanoma diagnosis. Because reasoning is constrained to pass through the concept bottleneck, clinicians can inspect predicted concepts and override incorrect values at inference time.


Capabilities

Interpretable classification – Two-stage architecture with per-concept prediction heads and a linear task predictor whose weights directly indicate concept importance.

Concept intervention – At inference time, individual concept predictions can be overridden to correct errors and observe the effect on the diagnosis. This enables systematic analysis of which concepts are most influential.

Multiple training strategies – Joint, sequential, and independent training modes, each offering different trade-offs between concept accuracy and task performance.

Reproducible demos – Four sample dermoscopy cases are included in the repository, allowing the full pipeline to be exercised without access to the complete dataset. Three Jupyter notebooks provide worked examples.


Visual Examples

Concept Prediction Examples

Case 578: Melanoma with high 7-point score

Case 578: Melanoma with multiple positive concepts (7-point score: 7)

Case 596: Melanoma with moderate features

Case 596: Melanoma with moderate dermatological features

Individual Case Intervention Analysis

Intervention analysis for Case 578

Intervention Impact: Effect of correcting each concept on diagnosis confidence

Intervention analysis for Case 7

Case 7 Analysis: Identifying critical concepts through systematic intervention

Systematic Intervention Analysis

Intervention analysis across the full test set, showing how concept corrections affect predictions.

Performance comparison: Original vs Corrected predictions

Performance Comparison: Original model accuracy vs. accuracy after concept intervention.

Concept impact analysis showing relative importance

Concept Importance: Relative impact of each dermatological concept on diagnosis accuracy.

Intervention direction analysis

Intervention Direction: Asymmetric effects of correcting false negatives (0 to 1) vs. false positives (1 to 0).

Confusion matrices before and after intervention

Confusion Matrices: Predictions before (left) and after (right) systematic concept correction.

Key findings:

  • Concept intervention improves accuracy by approximately 15–20% on previously misclassified cases.
  • Blue-whitish veil and atypical vascular pattern show the highest individual impact on diagnosis.
  • Correcting false negatives (absent to present) has a larger effect than correcting false positives, consistent with clinical literature on melanoma indicators.

Interactive Tutorials

Explore the complete implementation through interactive Jupyter notebooks:

1. Quick Demo with Sample Data

No dataset required! Try CBMs on 4 sample dermoscopy images.

View Tutorial (Click to expand)

Tutorial covers: Loading images, concept prediction, model interpretation, basic intervention

View on GitHub →

2. Concept Intervention Deep Dive

Learn how to correct model predictions by intervening on concept predictions.

View Tutorial (Click to expand)

Tutorial covers: Single concept intervention, systematic analysis, visualization techniques

View on GitHub →

3. Full Training Walkthrough

Complete training pipeline on the Derm7pt dataset with evaluation and analysis.

View Tutorial (Click to expand)

Tutorial covers: Data loading, model training, evaluation metrics, information-theoretic analysis

View on GitHub →


Technical Details

Architecture

Concept Encoder: ResNet-50 backbone with independent concept heads

ConceptEncoder(
    backbone='resnet50',        # Pretrained on ImageNet
    num_concepts=7,              # 7-point dermatological checklist
    dropout=0.3                  # Regularization for small datasets
)

Task Predictor: Linear classifier for maximum interpretability

LinearTaskPredictor(
    num_concepts=7,
    num_classes=2               # Melanoma vs. Nevus
)

Training Strategies

  1. Joint Training (default): Train concepts and task predictor simultaneously
  2. Sequential Training: Train concepts first, then freeze and train task predictor
  3. Independent Training: Use ground-truth concepts for task predictor training

Performance

On Derm7pt dataset (~2,000 dermoscopy images):

Metric 50 Epochs 100 Epochs
Concept Accuracy 75-80% 75-82%
Task F1 Score 68-72% 70-75%
Training Time (V100) ~10 min ~20 min

Trade-off: Approximately 5% accuracy reduction compared to black-box models, in exchange for full interpretability and intervention capability.


Quick Start

Installation

git clone https://github.com/Matt-Cockayne/SynergyCBM.git
cd SynergyCBM/SkinCBM
pip install -r requirements.txt

Quick Demo

python3 examples/demo_sample_data.py

Train on Full Dataset

python3 examples/train_basic_cbm.py \
    --data_path /path/to/derm7pt \
    --epochs 50 \
    --output_dir ./outputs/my_cbm

Use Trained Model

from src.models.basic_cbm import ConceptBottleneckModel

# Load model
model = ConceptBottleneckModel.load("outputs/my_cbm/best_model.pth")

# Predict concepts and diagnosis
concepts, logits = model(image)

# Intervene on incorrect concept
concepts[:, 2] = 1.0  # Correct concept 2
corrected_logits = model.predict_from_concepts(concepts)

Repository Structure

SkinCBM/
├── src/
│   ├── models/
│   │   └── basic_cbm.py              # Core CBM implementation
│   ├── data/
│   │   ├── base_loader.py            # Abstract dataset interface
│   │   └── derm7pt_loader.py         # Derm7pt dataset loader
│   ├── training/
│   │   └── trainer.py                # Training utilities
│   └── utils/
│       └── visualization.py          # Plotting and visualisation
│
├── examples/
│   ├── train_basic_cbm.py            # Full training script
│   ├── demo_sample_data.py           # Quick demo (4 samples)
│   ├── demo_intervention.py          # Intervention examples
│   └── intervention_analysis.py      # Systematic analysis
│
├── notebooks/
│   ├── 01_cbm_training_walkthrough.ipynb
│   ├── 02_demo_with_sample_data.ipynb
│   ├── 03_demo_intervention.ipynb
│   └── sample_data_derm7pt/          # 4 sample cases
│
└── docs/
    ├── ARCHITECTURE.md
    ├── QUICKSTART.md
    └── DATASETS.md

Clinical Significance

Why Interpretability Matters in Medical AI

  1. Trust: Clinicians can validate model reasoning against medical knowledge
  2. Safety: Identify reliance on spurious correlations or dataset artifacts
  3. Regulation: Meet explainability requirements for medical device approval
  4. Education: Train residents by showing which features indicate malignancy
  5. Collaboration: Enable human-AI partnership through concept intervention

7-Point Checklist

The model uses the clinically validated 7-point checklist for melanoma diagnosis:

  1. Atypical pigment network (2 points)
  2. Blue-whitish veil (2 points)
  3. Atypical vascular pattern (2 points)
  4. Irregular streaks (1 point)
  5. Irregular pigmentation (1 point)
  6. Irregular dots and globules (1 point)
  7. Regression structures (1 point)

Clinical rule: Score ≥ 3 suggests melanoma, requiring biopsy.


Documentation

Guides available in the repository:


Research Context

This implementation builds on foundational CBM research:

  • Koh et al. (2020): Concept Bottleneck Models - Original CBM paper
  • Argaw et al. (2022): Clinical validation of 7-point checklist in melanoma diagnosis

Future Directions

Planned Enhancements

  • Concept discovery: Automatic extraction of concepts from data
  • Multi-task learning: Extend to multiple skin lesion types
  • Uncertainty quantification: Confidence intervals for concepts and predictions
  • Active learning: Identify which concepts need human annotation
  • Comparative analysis: Benchmark against other interpretability methods

Research Questions

  • Can CBMs match black-box performance with higher-quality concept supervision?
  • What is the optimal number of concepts for completeness vs. redundancy?
  • How does concept intervention affect model trust in clinical settings?

Citation

If you use SkinCBM in your research, please cite:

@software{skincbm2025,
  title={SkinCBM: Concept Bottleneck Models for Interpretable Skin Lesion Diagnosis},
  author={Cockayne, Matthew J.},
  year={2025},
  url={https://github.com/Matt-Cockayne/SynergyCBM/tree/main/SkinCBM}
}

Resources

  • GitHub Repository: SkinCBM on GitHub
  • Interactive Tutorials: 3 Jupyter notebooks (see above)
  • Sample Data: 4 dermoscopy cases included in repository
  • Documentation: Guides in docs/ folder