Skip to main content

Run specimen-level inference on whole slide images.

Project description

SpinPath

Continuous Integration Version on PyPI Supported Python versions

SpinPath is a command line tool to run pre-trained MIL models on whole slide images. It is the slide-level companion to WSInfer, which provides patch-level classification.

[!CAUTION] SpinPath is intended only for research purposes.

Install

SpinPath can be installed using pip. SpinPath will install PyTorch automatically if it is not installed, but this may not install GPU-enabled PyTorch even if a GPU is available. For this reason, install PyTorch before installing SpinPath.

Install PyTorch first

Please see PyTorch's installation instructions for help installing PyTorch. The installation instructions differ based on your operating system and choice of pip or conda. Thankfully, the instructions provided by PyTorch also install the appropriate version of CUDA. We refrain from including code examples of installation commands because these commands can change over time. Please refer to PyTorch's installation instructions for the most up-to-date instructions.

You will need a new-enough driver for your NVIDIA GPU. Please see this version compatibility table for the minimum versions required for different CUDA versions.

To test whether PyTorch can detect your GPU, check that this code snippet prints True.

python -c 'import torch; print(torch.cuda.is_available())'

Install SpinPath with pip

pip install spinpath

Examples

[!CAUTION] These models are intended only for research purposes.

With a model online

Jakub Kaczmarzyk has uploaded several pre-trained MIL models to HuggingFace for the community to explore. Over time, I (Jakub) hope that others may contribute MIL models too. If you are interested in this, please feel free to email me at jakub.kaczmarzyk at stonybrookmedicine dot edu.

The models are available at https://huggingface.co/kaczmarj

TP53 mutation prediction

spinpath run -m kaczmarj/pancancer-tp53-mut.tcga -i slide.svs

Cancer tissue classification

spinpath run -m kaczmarj/pancancer-tissue-classifier.tcga -i slide.svs

Metastasis prediction in axillary lymph nodes

spinpath run -m kaczmarj/breast-lymph-nodes-metastasis.camelyon16 -i slide.svs

Survival prediction in GBM-LGG

spinpath run -m kaczmarj/gbmlgg-survival-porpoise.tcga -i slide.svs

Survival prediction in kidney renal papillary cell carcinoma

spinpath run -m kaczmarj/kirp-survival-porpoise.tcga -i slide.svs

With a local (potentially private) model

You can use SpinPath with a local MIL model. The model must be saved to TorchScript format, and a model configuration file must also be written.

Here is an example of a configuration JSON file:

{
    "spec_version": "1.0",
    "type": "abmil",
    "patch_size_um": 128,
    "feature_extractor": "ctranspath",
    "num_classes": 2,
    "class_names": [
        "wildtype",
        "mutant"
    ]
}

There is a JSON schema in spinpath/schemas/model-config.schema.json for reference.

Once you have the model in TorchScript format and the configuration JSON file, you can run the model on slides. For example:

spinpath runlocal -m model.pt -c model.config.json \
    -i slides/TCGA-3L-AA1B-01Z-00-DX1.8923A151-A690-40B7-9E5A-FCBEDFC2394F.svs

How it works from 30,000 feet

The pipeline for attention-based MIL methods is rather standardized. Here are the steps that SpinPath takes. In the future, we would like to incorporate inference using graph-based methods, so this workflow will likely have to be modified.

  1. Segment the tissue in the image.
  2. Create patches of the tissue regions.
  3. Run a feature extractor on these patches.
  4. Run the pre-trained model on the extracted features.
  5. Save the results of the extracted features.

SpinPath caches steps 1, 2, and 3, as those can be reused among MIL models. Step 3 (feature extraction) is often the bottleneck of the workflow, and reusing extracted features can reduce runtime considerably.

Developers

Clone and install spinpath:

Clone the repository and make a virtual environment for it. Then install the dependencies, with dev extras.

pip install -e .[dev]

Configure pre-commit to run the formatter before commits happen.

pre-commit install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spinpath-0.2.0.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spinpath-0.2.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file spinpath-0.2.0.tar.gz.

File metadata

  • Download URL: spinpath-0.2.0.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for spinpath-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bf3aa50caa755dfe78966cc7fe1773c141acf3fd216d5fbaf9c75adad5e4df0b
MD5 f828d7c32c58cb2e8fbc5f4dcc04e72b
BLAKE2b-256 2988698ece40dd75996ee5ac809b82cd6a151adad85371dc07640e607b4f3a2e

See more details on using hashes here.

File details

Details for the file spinpath-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spinpath-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for spinpath-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b85cbaefa7030cc8d3a668048106799a93c8c2d618fda0eff891c6e7cbf443b
MD5 8d9ea2a1f44d1e00ae53533cb209fbec
BLAKE2b-256 a5e0db8baaa3d45ce864e1c5ae3527ad1303cdfedb4bc0a921760010530ffae1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page