Wildcat-based Weakly Supervised Segmentation for Digital Pathology in Neurodegenerative Diseases
Project description
Tangle-CNN Package
This package contains Python scripts to train and apply weakly supervised segmentation models based on the WildCat algorithm (Durand, CVPR 2017) in the context of detection and segmentation of pathological inclusions, such as neurofibrillary tangles, in digital pathology images in neurodegenerative disorders. For additional details, please read (Yushkevich et al., Brain 2021), (Ravikumar et al., Nature Communications, 2024) and (Denning et al., Acta Neuropathologica, 2024).
Overview
Tangle-CNN is a deep learning toolkit for weakly supervised detection and segmentation of pathological features in histology whole-slide images. The package implements a WildCat-based approach that enables training models with image-level labels and applying them to generate pixel-level density maps of pathological structures.
Key features:
- Weakly supervised learning using WildCat architecture
- Support for multi-class classification of pathological features
- Whole-slide image processing capabilities
- Training with bounding box constraints and multi-resolution support
- Flexible data augmentation options
Installation
Requirements
- Python >= 3.8
- CUDA-capable GPU (recommended for training and inference)
Install from source
git clone https://github.com/pyushkevich/tangle-cnn-prod.git
cd tangle-cnn-prod
pip install -e .
Dependencies
The package requires the following Python libraries:
- PyTorch >= 1.6.0
- torchvision >= 0.7.0
- numpy
- scipy
- matplotlib
- openslide-python
- SimpleITK
- Pillow
- pandas
- parse
These dependencies will be automatically installed during package installation.
Usage
The package provides a command-line interface with four main subcommands:
1. Training a Model
Train a WildCat model on labeled image patches:
python -m tangle_cnn train \
--expdir /path/to/experiment \
--epochs 50 \
--batch 16 \
--kmax 0.02 \
--kmin 0.0 \
--alpha 0.7 \
--nmaps 4
Key training options:
--expdir: Experiment directory containingpatches/trainandpatches/valsubdirectories--epochs: Number of training epochs (default: 50)--batch: Batch size (default: 16)--kmax,--kmin,--alpha: WildCat hyperparameters--nmaps: Number of maps per class--bbox: Use bounding box constraints (requires manifest file)--scale: Scale patches to target resolution for multi-resolution training--color-jitter: Apply color jitter augmentation--lr: Learning rate (default: 0.01)--resume: Resume from saved checkpoint
2. Validating a Model
Evaluate a trained model on test data:
python -m tangle_cnn validate \
--expdir /path/to/experiment \
--batch 16 \
--target test
Validation options:
--expdir: Experiment directory with trained model--batch: Batch size for evaluation--target: Dataset to evaluate ('test' or other)--manifest: Manifest file (if training used --bbox or --scale)
3. Applying to Whole-Slide Images
Apply trained model to generate density maps for whole-slide images:
python -m tangle_cnn apply \
--slide /path/to/slide.svs \
--modeldir /path/to/trained/model \
--output /path/to/output_density.nii.gz \
--window 4096 \
--shrink 4
Apply options:
--slide: Input whole-slide image path--reader: Image reader to use ('openslide', 'sitk', or 'pillow')--modeldir: Directory containing trained model--output: Output density map file (.nii.gz format)--window: Window size for slide scanning (default: 4096)--shrink: Downsampling factor for output (default: 4)--region: Process only a specific region [x, y, w, h]
4. Applying to Image Patches
Apply model to pre-extracted image patches:
python -m tangle_cnn patch_apply \
--input /path/to/patches \
--modeldir /path/to/trained/model \
--outdir /path/to/output \
--batch 16
Patch apply options:
--input: Input directory or directories containing patches--modeldir: Directory containing trained model--outdir: Output directory for density maps--outstat: Output file for density statistics--batch: Batch size (default: 16)--scale: Resolution scaling factor for multi-resolution inference
Getting System Information
Check PyTorch and CUDA configuration:
python -m tangle_cnn info
Data Organization
Training Data Structure
For training, organize your data as follows:
experiment_dir/
├── patches/
│ ├── train/
│ │ ├── class1/
│ │ │ ├── image1.png
│ │ │ └── image2.png
│ │ └── class2/
│ │ ├── image1.png
│ │ └── image2.png
│ └── val/
│ ├── class1/
│ └── class2/
└── models/
├── config.json
└── wildcat_upsample.dat
Manifest File Format
When using --bbox or --scale options, provide a CSV manifest with columns:
- For bounding boxes:
filename,x,y,width,height - For scaling:
filename,mpp_x,mpp_y(microns per pixel)
References
If you use this package, please cite the following publications:
- Yushkevich et al., "Deep learning analysis of tau pathology in postmortem human hippocampus" Brain, 2021
- Ravikumar et al., "Deep learning methods detect tau pathology in early Alzheimer's disease using multimodal digitized slides" Nature Communications, 2024
- Denning et al., "Spatial quantification of tau pathology in progressive supranuclear palsy" Acta Neuropathologica, 2024
- Durand et al., "WILDCAT: Weakly Supervised Learning of Deep ConvNets for Image Classification, Pointwise Localization and Segmentation" CVPR, 2017
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE.txt file for details.
Authors
- Paul Yushkevich (pyushkevich@gmail.com)
Contributing
For bug reports and feature requests, please use the GitHub issue tracker at: https://github.com/pyushkevich/tangle-cnn-prod/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tangle_cnn-0.98.0.tar.gz.
File metadata
- Download URL: tangle_cnn-0.98.0.tar.gz
- Upload date:
- Size: 83.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a1b1ea2312ddc56c0ba59305a9d6e845945cb54b45d49959e9d268d7c6913d3
|
|
| MD5 |
50d4fa21dd44c5ec1f92c1c64f049b12
|
|
| BLAKE2b-256 |
7c5a8d95d496af0c9b5f1c6cd32aaf0e086e1d88ce1636b9eb25dbe39d6f4353
|
Provenance
The following attestation bundles were made for tangle_cnn-0.98.0.tar.gz:
Publisher:
python-publish.yml on pyushkevich/tangle-cnn-prod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tangle_cnn-0.98.0.tar.gz -
Subject digest:
4a1b1ea2312ddc56c0ba59305a9d6e845945cb54b45d49959e9d268d7c6913d3 - Sigstore transparency entry: 932509559
- Sigstore integration time:
-
Permalink:
pyushkevich/tangle-cnn-prod@024fea4eb33e2d1b1d1c29d9d3cb73c5c2772f9b -
Branch / Tag:
refs/heads/master - Owner: https://github.com/pyushkevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@024fea4eb33e2d1b1d1c29d9d3cb73c5c2772f9b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tangle_cnn-0.98.0-py3-none-any.whl.
File metadata
- Download URL: tangle_cnn-0.98.0-py3-none-any.whl
- Upload date:
- Size: 98.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39723f8d96c76c758f402c43de272ee750fe71d1ae1da011dedee0c1e2738e4b
|
|
| MD5 |
b1fee46b90657143491887f14699c6bc
|
|
| BLAKE2b-256 |
a5aa8b9f8dd0c28641dcfcd935a3aae77e08be053f85c9e4417ddf46708e375e
|
Provenance
The following attestation bundles were made for tangle_cnn-0.98.0-py3-none-any.whl:
Publisher:
python-publish.yml on pyushkevich/tangle-cnn-prod
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tangle_cnn-0.98.0-py3-none-any.whl -
Subject digest:
39723f8d96c76c758f402c43de272ee750fe71d1ae1da011dedee0c1e2738e4b - Sigstore transparency entry: 932509621
- Sigstore integration time:
-
Permalink:
pyushkevich/tangle-cnn-prod@024fea4eb33e2d1b1d1c29d9d3cb73c5c2772f9b -
Branch / Tag:
refs/heads/master - Owner: https://github.com/pyushkevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@024fea4eb33e2d1b1d1c29d9d3cb73c5c2772f9b -
Trigger Event:
workflow_dispatch
-
Statement type: