Skip to content

Add MC-Dropout uncertainty estimation for patch classification - #1104

Open
Pier45 wants to merge 7 commits into
TissueImageAnalytics:developfrom
Pier45:feature/mc-dropout-uncertainty
Open

Add MC-Dropout uncertainty estimation for patch classification#1104
Pier45 wants to merge 7 commits into
TissueImageAnalytics:developfrom
Pier45:feature/mc-dropout-uncertainty

Conversation

@Pier45

@Pier45 Pier45 commented Jul 27, 2026

Copy link
Copy Markdown

Adds Monte Carlo Dropout-based uncertainty quantification (epistemic + aleatoric)
for patch classification models.

TIAToolbox's pretrained classification models (AlexNet, MobileNet, etc.) don't
expose uncertainty estimates, only point predictions. This adds a lightweight,
non-invasive wrapper to enable MC-Dropout sampling and uncertainty decomposition.

  • bayesian_wrapper.py: wraps any model, injects dropout at inference if needed
  • mc_dropout.py: runs N stochastic forward passes
  • uncertainty.py: computes epistemic/aleatoric/total uncertainty
  • Includes unit tests

@shaneahmed
shaneahmed requested a review from measty July 27, 2026 09:13
@shaneahmed shaneahmed added this to the Release v2.2.0 milestone Jul 27, 2026
@shaneahmed shaneahmed added the enhancement New feature or request label Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.25843% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.85%. Comparing base (8d13267) to head (f0e6efe).

Files with missing lines Patch % Lines
tiatoolbox/models/architecture/bayesian_wrapper.py 87.23% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1104      +/-   ##
===========================================
- Coverage    99.90%   99.85%   -0.05%     
===========================================
  Files           93       96       +3     
  Lines        11911    12000      +89     
  Branches      1562     1573      +11     
===========================================
+ Hits         11900    11983      +83     
- Misses           5        9       +4     
- Partials         6        8       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

shaneahmed and others added 5 commits August 7, 2026 11:34
- bayesian_wrapper: cover RuntimeError on failed dropout injection (lines 85-91)
  and __getattr__ delegation/AttributeError (lines 125-131)
- mc_dropout: cover TypeError branches in inject_dropout_before_classifier,
  AlphaDropout/FeatureAlphaDropout detection, and mc_dropout_mode.__exit__
  with exception restore

Fixes Codecov coverage gaps reported in PR TissueImageAnalytics#1104
   - Add tests covering Codecov gaps in bayesian_wrapper (lines 85-91, 125-131)
     and mc_dropout (TypeError branches, AlphaDropout, __exit__ with exception)
   - Fix FLK-D402: rewrite DummyCNNModel.infer_batch docstring
   - Fix PTC-W0063: wrap next() in try-except with CPU fallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants