-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade MHub to uv and python3.11 (#100)
- The base image now ships with uv 0.4.4 - The mhubio and segdb packages are now installed in a virtual environment using python 3.11 (bumped from 3.8) - All dependency versions are fixed now (and will be moved into package dependencies with a future update) - Some models require python 3.8, we created a new .venv38 environment with python 3.8 and installed the model dependencies there. The model logic is then outsourced into a cli script that is called from the Runner module. - Future base images likely will contain updated versions of uv since uv is actively developed and receives frequent improvements and fixes.
- Loading branch information
Showing
16 changed files
with
168 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/bash | ||
PYTHON=$(which python3) | ||
$PYTHON -m mhubio.run "$@" | ||
# PYTHON=$(uv run which python3) | ||
# $PYTHON -m mhubio.run "$@" | ||
uv run python -m mhubio.run "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/bash | ||
PYTHON=$(which python3) | ||
$PYTHON -m pip uninstall -y mhubio segdb | ||
$PYTHON -m pip install git+https://github.com/MHubAI/mhubio.git git+https://github.com/MHubAI/segdb.git | ||
uv pip uninstall mhubio segdb | ||
uv pip install git+https://github.com/MHubAI/mhubio.git git+https://github.com/MHubAI/segdb.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,21 @@ LABEL authors="[email protected],[email protected],lnuernbe | |
# Install system dependencies for OpenCV | ||
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y | ||
|
||
# create new virtual environment | ||
RUN uv venv --python-preference only-managed -p 3.8 .venv38 | ||
|
||
# Install required dependencies for lobe segmentation (CUDA-enabled) | ||
RUN pip3 install --no-cache-dir \ | ||
opencv-python \ | ||
# SimpleITK==1.2.4 is required for legacy Resample::Execute operation | ||
RUN uv pip install -n -p .venv38 \ | ||
pydicom==2.4.4 packaging==24.1 psutil==6.0.0 \ | ||
opencv-python==4.10.0.84 \ | ||
torch==2.0.1 torchvision==0.15.2 \ | ||
dgl==1.1.2 -f https://data.dgl.ai/wheels/cu118/repo.html | ||
SimpleITK==1.2.4 | ||
|
||
# SimpleITK downgrade required for legacy Resample::Execute operation | ||
RUN pip3 install --no-cache-dir --force-reinstall SimpleITK==1.2.4 | ||
# Install dgl (CUDA-enabled) | ||
# NOTE: uv pip install -f option doesn't work as intended | ||
RUN uv pip install -n -p .venv38 pip \ | ||
&& uv run -p .venv38 pip install dgl==1.1.2 -f https://data.dgl.ai/wheels/cu118/repo.html | ||
|
||
# Import the MHub model definiton | ||
ARG MHUB_MODELS_REPO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import numpy as np | ||
import SimpleITK as sitk | ||
|
||
from src.test import segment_lobe, segment_lobe_init | ||
|
||
def run(input_image_path: str, output_image_path: str): | ||
|
||
img_itk = sitk.ReadImage(input_image_path) | ||
img_np = sitk.GetArrayFromImage(img_itk) | ||
|
||
# apply lobe segmentation | ||
origin = img_itk.GetOrigin()[::-1] | ||
spacing = img_itk.GetSpacing()[::-1] | ||
direction = np.asarray(img_itk.GetDirection()).reshape(3, 3)[::-1].flatten().tolist() | ||
meta_dict = { | ||
"uid": os.path.basename(input_image_path), | ||
"size": img_np.shape, | ||
"spacing": spacing, | ||
"origin": origin, | ||
"original_spacing": spacing, | ||
"original_size": img_np.shape, | ||
"direction": direction | ||
} | ||
|
||
handle = segment_lobe_init() | ||
seg_result_np = segment_lobe(handle, img_np, meta_dict) | ||
|
||
# store image | ||
print(f"Writing image to {output_image_path}") | ||
seg_itk = sitk.GetImageFromArray(seg_result_np) | ||
seg_itk.CopyInformation(img_itk) | ||
sitk.WriteImage(seg_itk, output_image_path) | ||
|
||
# cli | ||
if __name__ == "__main__": | ||
import argparse | ||
parser = argparse.ArgumentParser(description='Run Xie2020 Lobe Segmentation') | ||
parser.add_argument('input_image_path', type=str, help='Path to input image') | ||
parser.add_argument('output_image_path', type=str, help='Path to output image') | ||
args = parser.parse_args() | ||
|
||
run(args.input_image_path, args.output_image_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,6 @@ FROM mhubai/base:latest | |
# Specify/override authors label | ||
LABEL authors="[email protected]" | ||
|
||
# Install pipenv (for a custom Python/Pip environment for ASAP-2.1 and the other algorithm requirements) | ||
RUN pip3 install --no-cache-dir pipenv | ||
|
||
# Set environment variables for pipenv (installs into /app/.venv) | ||
ENV PIPENV_VENV_IN_PROJECT=1 | ||
|
||
# Install ASAP 2.1 | ||
RUN apt-get update && \ | ||
apt-get -y install curl libpython3.8-dev && \ | ||
|
@@ -26,16 +20,17 @@ RUN git clone --depth 1 --branch 0.1.0 https://github.com/DIAGNijmegen/tiger_vun | |
rm -rf /vuno/.git | ||
|
||
# Setup and install algorithm pipenv environment | ||
# 1. Ensure we configure a new empty pipenv for Python 3.8 | ||
# 1. Ensure we configure a new empty virtual environment for Python 3.8 | ||
# 2. Link ASAP libraries into our environment | ||
# 3. Install required torch and torchvision dependencies | ||
# 4. Install tiger LB2 dependencies from requirements.txt | ||
# 5. Upgrade version of numpy and numba to function correctly with ASAP | ||
RUN pipenv install --python 3.8 && \ | ||
echo "/opt/ASAP/bin" > /app/.venv/lib/python3.8/site-packages/asap.pth && \ | ||
pipenv run pip install --no-cache-dir torch==2.0.1+cu118 torchvision==0.15.2+cu118 -f https://download.pytorch.org/whl/torch_stable.html && \ | ||
pipenv run pip install --no-cache-dir -r /vuno/requirements.txt && \ | ||
pipenv run pip install --no-cache-dir --upgrade numpy==1.24.4 numba==0.58.1 | ||
RUN uv venv --python 3.8 .venv38 \ | ||
&& echo "/opt/ASAP/bin" > /app/.venv38/lib/python3.8/site-packages/asap.pth \ | ||
&& uv pip install -n -p .venv38 -f https://download.pytorch.org/whl/torch_stable.html \ | ||
torch==2.0.1+cu118 torchvision==0.15.2+cu118 \ | ||
&& uv pip install -n -p .venv38 -r /vuno/requirements.txt \ | ||
&& uv pip install -n -p .venv38 --upgrade numpy==1.24.4 numba==0.58.1 | ||
|
||
# Download and install model weights file from zenodo | ||
RUN rm -rf /vuno/pretrained_weights && \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,9 @@ FROM mhubai/base:latest | |
# Update authors label | ||
LABEL authors="[email protected]" | ||
|
||
# Install pipenv (for a custom Python/Pip environment for ASAP-2.1 and the other algorithm requirements) | ||
RUN pip3 install --no-cache-dir pipenv | ||
|
||
# Set environment variables for pipenv (installs into /app/.venv) | ||
ENV PIPENV_VENV_IN_PROJECT=1 | ||
|
||
# Install ASAP 2.1 | ||
RUN apt-get update && \ | ||
apt-get -y install curl libpython3.8-dev && \ | ||
apt-get -y install libpython3.8-dev && \ | ||
curl --remote-name --location "https://github.com/computationalpathologygroup/ASAP/releases/download/ASAP-2.1/ASAP-2.1-py38-Ubuntu2004.deb" && \ | ||
dpkg --install ASAP-2.1-py38-Ubuntu2004.deb || true && \ | ||
apt-get -f install --fix-missing --fix-broken --assume-yes && \ | ||
|
@@ -25,15 +19,15 @@ RUN apt-get update && \ | |
# 3. Upgrade pip | ||
# 4. Upgrade version of numpy and numba to function correctly with ASAP | ||
# 5. Install required dependencies for algorithm | ||
RUN pipenv install --python 3.8 && \ | ||
echo "/opt/ASAP/bin" > /app/.venv/lib/python3.8/site-packages/asap.pth && \ | ||
pipenv run pip install --no-cache-dir --upgrade pip && \ | ||
pipenv run pip install --no-cache-dir --upgrade numpy==1.24.4 numba==0.58.1 && \ | ||
pipenv run pip install --no-cache-dir scipy==1.10.1 scikit-image==0.21.0 h5py==3.11.0 | ||
RUN uv venv --python 3.8 .venv38 && \ | ||
echo "/opt/ASAP/bin" > /app/.venv38/lib/python3.8/site-packages/asap.pth && \ | ||
uv pip install -n -p .venv38 --upgrade numpy==1.24.4 numba==0.58.1 && \ | ||
uv pip install -n -p .venv38 scipy==1.10.1 scikit-image==0.21.0 h5py==3.11.0 | ||
|
||
# build/install Tensorflow 2.11.0 with GPU support (without conda), with CUDA 11 toolkit and cudnn 8 | ||
# tensorflow-2.11.0 Python 3.7-3.10 cuDNN >= 8.1 CUDA >= 11.2 | ||
RUN pipenv run pip install --no-cache-dir \ | ||
RUN uv pip install -n -p .venv38 pip \ | ||
&& uv run -p .venv38 pip install --no-cache-dir \ | ||
nvidia-cuda-runtime-cu11 \ | ||
nvidia-cusolver-cu11 \ | ||
nvidia-curand-cu11 \ | ||
|
@@ -46,8 +40,8 @@ RUN pipenv run pip install --no-cache-dir \ | |
--extra-index-url https://pypi.ngc.nvidia.com | ||
|
||
# Configure required paths for tensorflow with GPU support | ||
ENV NVIDIA_DIR /app/.venv/lib/python3.8/site-packages/nvidia | ||
ENV LD_LIBRARY_PATH /app/.venv/lib/python3.8/site-packages/tensorrt:$NVIDIA_DIR/cublas/lib:$NVIDIA_DIR/cuda_runtime/lib:$NVIDIA_DIR/cudnn/lib:$NVIDIA_DIR/cufft/lib:$NVIDIA_DIR/curand/lib:$NVIDIA_DIR/cusolver/lib:$NVIDIA_DIR/cusparse/lib | ||
ENV NVIDIA_DIR /app/.venv38/lib/python3.8/site-packages/nvidia | ||
ENV LD_LIBRARY_PATH /app/.venv38/lib/python3.8/site-packages/tensorrt:$NVIDIA_DIR/cublas/lib:$NVIDIA_DIR/cuda_runtime/lib:$NVIDIA_DIR/cudnn/lib:$NVIDIA_DIR/cufft/lib:$NVIDIA_DIR/curand/lib:$NVIDIA_DIR/cusolver/lib:$NVIDIA_DIR/cusparse/lib | ||
|
||
# Import the MHub model definiton | ||
ARG MHUB_MODELS_REPO | ||
|
Oops, something went wrong.