Switch to unified view

a b/docs-source/source/installation.rst
1
Installation
2
============
3
4
.. figure:: https://github.com/user-attachments/assets/53d5c1f8-8fbc-4e0f-bd62-db16797492b0
5
6
Slideflow is tested on **Linux-based systems** (Ubuntu, CentOS, Red Hat, and Raspberry Pi OS) and **macOS** (Intel and Apple). Windows support is experimental.
7
8
Requirements
9
************
10
11
- Python >= 3.7 (<3.10 if using `cuCIM <https://docs.rapids.ai/api/cucim/stable/>`_)
12
- `PyTorch <https://pytorch.org/>`_ (1.9+) *or* `Tensorflow <https://www.tensorflow.org/>`_ (2.5-2.11)
13
    - Core functionality, including tile extraction, data processing, and tile-based model training, is supported for both PyTorch and Tensorflow. Additional advanced tools, such as Multiple-Instance Learning (MIL), GANs, and pretrained foundation models, require PyTorch.
14
15
Optional
16
--------
17
18
- `Libvips >= 8.9 <https://libvips.github.io/libvips/>`_ (alternative slide reader, adds support for \*.scn, \*.mrxs, \*.ndpi, \*.vms, and \*.vmu files)
19
- Linear solver (for site-preserved cross-validation):
20
21
  - `CPLEX 20.1.0 <https://www.ibm.com/docs/en/icos/12.10.0?topic=v12100-installing-cplex-optimization-studio>`_ with `Python API <https://www.ibm.com/docs/en/icos/12.10.0?topic=cplex-setting-up-python-api>`_
22
  - *or* `Pyomo <http://www.pyomo.org/installation>`_ with `Bonmin <https://anaconda.org/conda-forge/coinbonmin>`_ solver
23
24
25
Download with pip
26
*****************
27
28
Slideflow can be installed either with PyPI or as a Docker container. To install via pip:
29
30
.. code-block:: bash
31
32
    # Update to latest pip
33
    pip install --upgrade pip wheel
34
35
    # Current stable release, Tensorflow backend
36
    pip install slideflow[tf] cucim cupy-cuda11x
37
38
    # Alternatively, install with PyTorch backend
39
    pip install slideflow[torch] cucim cupy-cuda11x
40
41
The ``cupy`` package name depends on the installed CUDA version; `see here <https://docs.cupy.dev/en/stable/install.html#installing-cupy>`_ for installation instructions. ``cucim`` and ``cupy`` are not required if using Libvips.
42
43
44
Run a Docker container
45
**********************
46
47
Alternatively, pre-configured `docker images <https://hub.docker.com/repository/docker/jamesdolezal/slideflow>`_ are available with cuCIM, Libvips, and either PyTorch 1.11 or Tensorflow 2.9 pre-installed. Using a preconfigured `Docker <https://docs.docker.com/install/>`_ container is the easiest way to get started with compatible dependencies and GPU support.
48
49
To run a Docker container with the Tensorflow backend:
50
51
.. code-block:: bash
52
53
    docker pull jamesdolezal/slideflow:latest-tf
54
    docker run -it --gpus all jamesdolezal/slideflow:latest-tf
55
56
To run a Docker container with the PyTorch backend:
57
58
.. code-block:: bash
59
60
    docker pull jamesdolezal/slideflow:latest-torch
61
    docker run -it --shm-size=2g --gpus all jamesdolezal/slideflow:latest-torch
62
63
Build from source
64
*****************
65
66
To build Slideflow from source, clone the repository from the project `Github page <https://github.com/slideflow/slideflow>`_:
67
68
.. code-block:: bash
69
70
    git clone https://github.com/slideflow/slideflow
71
    cd slideflow
72
    conda env create -f environment.yml
73
    conda activate slideflow
74
    python setup.py bdist_wheel
75
    pip install dist/slideflow* cupy-cuda11x
76
77
78
Extensions
79
**********
80
81
The core Slideflow package is licensed under the **Apache-2.0** license. Additional functionality, such as pretrained foundation models, are distributed in separate packages according to their licensing terms. Available extensions include:
82
83
- **Slideflow-GPL**: GPL-3.0 licensed extensions (`GitHub <https://github.com/slideflow/slideflow-gpl>`__)
84
    - Includes: `RetCCL <https://www.sciencedirect.com/science/article/abs/pii/S1361841522002730>`__, `CTransPath <https://www.sciencedirect.com/science/article/abs/pii/S1361841522002043>`__, and `CLAM <https://www.nature.com/articles/s41551-020-00682-w>`__.
85
- **Slideflow-NonCommercial**: CC BY-NC 4.0 licensed extensions for non-commercial use (`GitHub <https://github.com/slideflow/slideflow-noncommercial>`__)
86
    - Includes: `HistoSSL <https://www.medrxiv.org/content/10.1101/2023.07.21.23292757v2.full.pdf>`__, `PLIP <https://www.nature.com/articles/s41591-023-02504-3>`__, `GigaPath <https://aka.ms/gigapath>`__, `UNI <https://www.nature.com/articles/s41591-024-02857-3>`__, `BISCUIT <https://www.nature.com/articles/s41467-022-34025-x>`__, and `StyleGAN3 <https://nvlabs-fi-cdn.nvidia.com/stylegan3/stylegan3-paper.pdf>`__.
87
88
These extensions can be installed via pip. The GigaPath feature extractor has additional, more restrictive dependencies that must be installed separately.
89
90
.. code-block:: bash
91
92
    # Install Slideflow-GPL and Slideflow-NonCommercial
93
    pip install slideflow-gpl slideflow-noncommercial
94
95
    # Install GigaPath dependencies, if desired
96
    pip install slideflow-noncommercial[gigapath] git+ssh://git@github.com/prov-gigapath/prov-gigapath
97
98
99
.. note::
100
    The Slideflow-GPL and Slideflow-NonCommercial extensions are not included in the default Slideflow package due to their licensing terms. Please review the licensing terms of each extension before use.
101
102
103
PyTorch vs. Tensorflow
104
**********************
105
106
Slideflow supports both PyTorch and Tensorflow, with cross-compatible TFRecord storage. Slideflow will default to using PyTorch if both are available, but the backend can be manually specified using the environmental variable ``SF_BACKEND``. For example:
107
108
.. code-block:: bash
109
110
    export SF_BACKEND=tensorflow
111
112
.. _slide_backend:
113
114
cuCIM vs. Libvips
115
*****************
116
117
By default, Slideflow reads whole-slide images using `cuCIM <https://docs.rapids.ai/api/cucim/stable/>`_. Although much faster than other openslide-based frameworks, it supports fewer slide scanner formats. Slideflow also includes a `Libvips <https://libvips.github.io/libvips/>`_ backend, which adds support for \*.scn, \*.mrxs, \*.ndpi, \*.vms, and \*.vmu files. You can set the active slide backend with the environmental variable ``SF_SLIDE_BACKEND``:
118
119
.. code-block:: bash
120
121
    export SF_SLIDE_BACKEND=libvips
122
123
124
.. warning::
125
    A bug in the pixman library (version=0.38) will corrupt downsampled slide images, resulting in large black boxes across the slide. We have provided a patch for version 0.38 that has been tested for Ubuntu, which is provided in the project `Github page <https://github.com/slideflow/slideflow>`_ (``pixman_repair.sh``), although it may not be suitable for all environments and we make no guarantees regarding its use. The `Slideflow docker images <https://hub.docker.com/repository/docker/slideflow/slideflow>`_ already have this applied. If you are installing from source, have pixman version 0.38, and are unable to apply this patch, the use of downsampled image layers must be disabled to avoid corruption (pass ``enable_downsample=False`` to tile extraction functions).