Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: update app dockerfiles + add mypy/flake8 to github ci + support weights from timm #51

Merged
merged 18 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
python -m pip install --upgrade pip setuptools wheel
python -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu
python -m pip install --editable .[dev] --find-links https://girder.github.io/large_image_wheels
- name: Check style
run: python -m flake8 wsinfer/
- name: Check types
run: python -m mypy wsinfer/
- name: Run tests
run: |
python -m pytest --verbose tests/
run: python -m pytest --verbose tests/
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM pytorch/pytorch:1.12.1-cuda11.3-cudnn8-runtime
WORKDIR /opt/wsi-classification
WORKDIR /opt/wsinfer
COPY . .
RUN apt-get update \
&& apt-get install -y --no-install-recommends gcc git libopenslide0 \
Expand All @@ -15,4 +15,5 @@ RUN mkdir -p "$TORCH_HOME" \
&& chmod a+s "$TORCH_HOME"
WORKDIR /work
ENTRYPOINT ["wsinfer"]
CMD ["--help"]
LABEL maintainer="Jakub Kaczmarzyk <[email protected]>"
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Original H&E | Heatmap of Tumor Probability
🔥 🚀 Blazingly fast pipeline to run patch-based classification models on whole slide images.

![Continuous Integration](https://github.com/kaczmarj/patch-classification-pipeline/actions/workflows/ci.yml/badge.svg)
![Supported Python versions](https://img.shields.io/pypi/pyversions/wsinfer)
![Version on PyPI](https://img.shields.io/pypi/v/wsinfer.svg)

# Table of contents

Expand Down Expand Up @@ -268,6 +270,8 @@ Define a new model with a YAML configuration file. Please see the example below
an overview of the specification.

```yaml
# The version of the spec. At this time, only "1.0" is valid. (str)
version: "1.0"
# Models are referenced by the pair of (architecture, weights), so this pair must be unique.
# The name of the architecture. We use timm to supply hundreds or network architectures,
# so the name can be one of those models. If the architecture is not provided in timm,
Expand Down
6 changes: 3 additions & 3 deletions dockerfiles/tils.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# Note about versioning: We should not use the 'latest' tag because it is a moving
# target. We should prefer using a versioned release of the wsinfer pipeline.
FROM kaczmarj/patch-classification-pipeline:v0.2.1
FROM kaczmarj/wsinfer:v0.2.1

# The CLI will use these env vars for model and weights.
ENV WSINFER_MODEL="inceptionv4"
ENV WSINFER_MODEL="inceptionv4nobn"
ENV WSINFER_WEIGHTS="TCGA-TILs-v1"

# Download the weights.
RUN python -c "from wsinfer.modellib import models; models.$WSINFER_MODEL(\"$WSINFER_WEIGHTS\")" \
RUN python -c "from wsinfer.modellib.models import get_model_weights; get_model_weights(architecture=\"$WSINFER_MODEL\", name=\"$WSINFER_WEIGHTS\").load_model()" \
# Downloaded models are mode 0600. Make them readable by all users.
&& chmod -R +r $TORCH_HOME/hub/checkpoints/
4 changes: 2 additions & 2 deletions dockerfiles/tumor-brca.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# Note about versioning: We should not use the 'latest' tag because it is a moving
# target. We should prefer using a versioned release of the wsinfer pipeline.
FROM kaczmarj/patch-classification-pipeline:v0.2.1
FROM kaczmarj/wsinfer:v0.2.1

# The CLI will use these env vars for model and weights.
ENV WSINFER_MODEL="resnet34"
ENV WSINFER_WEIGHTS="TCGA-BRCA-v1"

# Download the weights.
RUN python -c "from wsinfer.modellib import models; models.$WSINFER_MODEL(\"$WSINFER_WEIGHTS\")" \
RUN python -c "from wsinfer.modellib.models import get_model_weights; get_model_weights(architecture=\"$WSINFER_MODEL\", name=\"$WSINFER_WEIGHTS\").load_model()" \
# Downloaded models are mode 0600. Make them readable by all users.
&& chmod -R +r $TORCH_HOME/hub/checkpoints/
4 changes: 2 additions & 2 deletions dockerfiles/tumor-luad.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# Note about versioning: We should not use the 'latest' tag because it is a moving
# target. We should prefer using a versioned release of the wsinfer pipeline.
FROM kaczmarj/patch-classification-pipeline:v0.2.1
FROM kaczmarj/wsinfer:v0.2.1

# The CLI will use these env vars for model and weights.
ENV WSINFER_MODEL="resnet34"
ENV WSINFER_WEIGHTS="TCGA-LUAD-v1"

# Download the weights.
RUN python -c "from wsinfer.modellib import models; models.$WSINFER_MODEL(\"$WSINFER_WEIGHTS\")" \
RUN python -c "from wsinfer.modellib.models import get_model_weights; get_model_weights(architecture=\"$WSINFER_MODEL\", name=\"$WSINFER_WEIGHTS\").load_model()" \
# Downloaded models are mode 0600. Make them readable by all users.
&& chmod -R +r $TORCH_HOME/hub/checkpoints/
6 changes: 3 additions & 3 deletions dockerfiles/tumor-paad.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# Note about versioning: We should not use the 'latest' tag because it is a moving
# target. We should prefer using a versioned release of the wsinfer pipeline.
FROM kaczmarj/patch-classification-pipeline:v0.2.1
FROM kaczmarj/wsinfer:v0.2.1

# The CLI will use these env vars for model and weights.
ENV WSINFER_MODEL="resnet34_preact"
ENV WSINFER_MODEL="preactresnet34"
ENV WSINFER_WEIGHTS="TCGA-PAAD-v1"

# Download the weights.
RUN python -c "from wsinfer.modellib import models; models.$WSINFER_MODEL(\"$WSINFER_WEIGHTS\")" \
RUN python -c "from wsinfer.modellib.models import get_model_weights; get_model_weights(architecture=\"$WSINFER_MODEL\", name=\"$WSINFER_WEIGHTS\").load_model()" \
# Downloaded models are mode 0600. Make them readable by all users.
&& chmod -R +r $TORCH_HOME/hub/checkpoints/
4 changes: 2 additions & 2 deletions dockerfiles/tumor-prad.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# Note about versioning: We should not use the 'latest' tag because it is a moving
# target. We should prefer using a versioned release of the wsinfer pipeline.
FROM kaczmarj/patch-classification-pipeline:v0.2.1
FROM kaczmarj/wsinfer:v0.2.1

# The CLI will use these env vars for model and weights.
ENV WSINFER_MODEL="resnet34"
ENV WSINFER_WEIGHTS="TCGA-PRAD-v1"

# Download the weights.
RUN python -c "from wsinfer.modellib import models; models.$WSINFER_MODEL(\"$WSINFER_WEIGHTS\")" \
RUN python -c "from wsinfer.modellib.models import get_model_weights; get_model_weights(architecture=\"$WSINFER_MODEL\", name=\"$WSINFER_WEIGHTS\").load_model()" \
# Downloaded models are mode 0600. Make them readable by all users.
&& chmod -R +r $TORCH_HOME/hub/checkpoints/
24 changes: 12 additions & 12 deletions scripts/build_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@ fi
version=$1

# Main image.
docker build -t kaczmarj/patch-classification-pipeline:$version .
docker build -t kaczmarj/wsinfer:$version .

# TILs
docker build -t kaczmarj/patch-classification-pipeline:$version-tils - < dockerfiles/tils.dockerfile
docker build -t kaczmarj/wsinfer:$version-tils - < dockerfiles/tils.dockerfile

# Tumor BRCA
docker build -t kaczmarj/patch-classification-pipeline:$version-tumor-brca - < dockerfiles/tumor-brca.dockerfile
docker build -t kaczmarj/wsinfer:$version-tumor-brca - < dockerfiles/tumor-brca.dockerfile

# Tumor LUAD
docker build -t kaczmarj/patch-classification-pipeline:$version-tumor-luad - < dockerfiles/tumor-luad.dockerfile
docker build -t kaczmarj/wsinfer:$version-tumor-luad - < dockerfiles/tumor-luad.dockerfile

# Tumor PAAD
docker build -t kaczmarj/patch-classification-pipeline:$version-tumor-paad - < dockerfiles/tumor-paad.dockerfile
docker build -t kaczmarj/wsinfer:$version-tumor-paad - < dockerfiles/tumor-paad.dockerfile

# Tumor PRAD
docker build -t kaczmarj/patch-classification-pipeline:$version-tumor-prad - < dockerfiles/tumor-prad.dockerfile
docker build -t kaczmarj/wsinfer:$version-tumor-prad - < dockerfiles/tumor-prad.dockerfile

# Push images.
push_images="${2:-0}"
if [ $push_images -eq 0 ]; then
echo "Not pushing images. Pass a 1 to the script to push images."
else
echo "Pushing images."
docker push kaczmarj/patch-classification-pipeline:$version
docker push kaczmarj/patch-classification-pipeline:$version-tils
docker push kaczmarj/patch-classification-pipeline:$version-tumor-brca
docker push kaczmarj/patch-classification-pipeline:$version-tumor-luad
docker push kaczmarj/patch-classification-pipeline:$version-tumor-paad
docker push kaczmarj/patch-classification-pipeline:$version-tumor-prad
docker push kaczmarj/wsinfer:$version
docker push kaczmarj/wsinfer:$version-tils
docker push kaczmarj/wsinfer:$version-tumor-brca
docker push kaczmarj/wsinfer:$version-tumor-luad
docker push kaczmarj/wsinfer:$version-tumor-paad
docker push kaczmarj/wsinfer:$version-tumor-prad
fi
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ dev =
mypy
pytest
tifffile
types-Pillow
types-PyYAML
types-tqdm

[options.entry_points]
console_scripts =
Expand All @@ -68,6 +71,24 @@ max-line-length = 88
extend-ignore = E203
exclude = wsinfer/_version.py

[mypy]
[mypy-h5py]
ignore_missing_imports = True
[mypy-large_image]
ignore_missing_imports = True
[mypy-cv2]
ignore_missing_imports = True
[mypy-torchvision.*]
ignore_missing_imports = True
[mypy-openslide]
ignore_missing_imports = True
[mypy-pandas]
ignore_missing_imports = True
[mypy-timm]
ignore_missing_imports = True
[mypy-scipy.stats]
ignore_missing_imports = True

[versioneer]
VCS = git
style = pep440
Expand Down
Loading