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

[ADD] vgg16 tils model #112

Merged
merged 10 commits into from
Apr 7, 2023
14 changes: 14 additions & 0 deletions dockerfiles/tils-vgg16.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tumor-infiltrating lymphocyte detection model.
#
# 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/wsinfer:0.3.6

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

# Download the weights.
RUN python -c "from wsinfer 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: 4 additions & 0 deletions scripts/build_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ docker build -t kaczmarj/wsinfer:$version .
# TILs
build $version-tils dockerfiles/tils.dockerfile

# TILs VGG16
build $version-tils-vgg16 dockerfiles/tils-vgg16.dockerfile

# Tumor BRCA
build $version-tumor-brca dockerfiles/tumor-brca.dockerfile

Expand All @@ -64,6 +67,7 @@ else
echo "Pushing images."
docker push kaczmarj/wsinfer:$version
docker push kaczmarj/wsinfer:$version-tils
docker push kaczmarj/wsinfer:$version-tils-vgg16
docker push kaczmarj/wsinfer:$version-tumor-brca
docker push kaczmarj/wsinfer:$version-tumor-luad
docker push kaczmarj/wsinfer:$version-tumor-paad
Expand Down
1 change: 1 addition & 0 deletions scripts/convert_tf_to_pytorch_til_vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def convert_tf_to_pytorch(input_path, output_path, num_classes: int):
elif "fc" in tf_weights:
if tf_weights == "vgg_16/fc6/weights":
# [7, 7, 512, 4096] -> [25088, 4096]
tf_weight_array = tf_weight_array.transpose([2, 0, 1, 3])
tf_weight_array = tf_weight_array.reshape((25088, 4096))
# E.g., go from shape [1, 1, 4096, 1000] to [1000, 4096]
tf_weight_array = tf_weight_array.squeeze().T
Expand Down
11 changes: 10 additions & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ def test_cli_run_args(tmp_path: Path):
200,
441,
),
# VGG16 TCGA-TILs-v1
(
"vgg16",
"TCGA-TILs-v1",
["notils", "tils"],
[0.9987693428993224, 0.0012305785203352],
200,
441,
),
# Vgg16mod TCGA-BRCA-v1
(
"vgg16mod",
Expand Down Expand Up @@ -950,7 +959,7 @@ def test_jit_compile(model_name: str, weights_name: str):
out_nojit = model(x).detach().cpu()
time_nojit = time.perf_counter() - t0
model_nojit = model
model = jit_compile(model)
model = jit_compile(model) # type: ignore
if model is model_nojit:
pytest.skip("Failed to compile model (would use original model)")
with torch.no_grad():
Expand Down
20 changes: 20 additions & 0 deletions wsinfer/modeldefs/vgg16_tcga-tils-v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Configuration of a tumor infiltrating lymphocyte detection model (VGG16).
version: "1.0"
architecture: vgg16
name: TCGA-TILs-v1
url: https://stonybrookmedicine.box.com/shared/static/0orxxw2aai3l3lztetvukwqetvr3z4lr.pt
url_file_name: vgg16-tils-20220112-3088cb70.pt
num_classes: 2
transform:
resize_size: 224
# Normalize to [-1, 1]
mean: [0.5, 0.5, 0.5]
std: [0.5, 0.5, 0.5]
patch_size_pixels: 100
spacing_um_px: 0.5
class_names:
- notils
- tils
metadata:
notes: |
Original code available at https://github.com/SBU-BMI/u24_lymphocyte.