Skip to content

730 retinal oct rpd segmentation #748

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

Draft
wants to merge 23 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e57a2e
First commit for forked branch.
ybagdasa Mar 10, 2025
1e02cc5
Deleted the zip file download in inference.py. Updated urls in large_…
ybagdasa Mar 12, 2025
3ac9f28
Implemented unit testing and added sample_data.
ybagdasa Mar 25, 2025
0676427
Applied changes from isort, black, flake in runtests.sh. Ran pytype s…
ybagdasa Mar 25, 2025
f7e9de6
Removed configargparser and added PNG naming instructions in readme.
ybagdasa Mar 25, 2025
0b8f1ef
Merge branch 'dev' into 730-retinalOCT_RPD_segmentation. Upstream
ybagdasa Mar 25, 2025
30dabf9
Moved large_files.yaml into retinalOCT_RPD_Segmentation into bundle r…
ybagdasa Apr 1, 2025
efb5da8
Updated dependencies. Updated depreciated pandas api. Updated install…
ybagdasa Apr 29, 2025
b831e50
Merge from upstream.
ybagdasa Apr 29, 2025
7cd1394
fix isort and update cit for detectron2
yiheng-wang-nv May 16, 2025
d171542
Fixed pre-commit and flake8 errors. Added torchvision to metadata.json.
ybagdasa May 16, 2025
50238f8
Merge branch '730-retinalOCT_RPD_segmentation' of github.com:uw-biome…
ybagdasa May 16, 2025
e271884
fix pre-commit and black checks
yiheng-wang-nv May 19, 2025
db0d0d6
skip part of tests and rrevert changes in UNEST bundles
yiheng-wang-nv May 19, 2025
ea0ef49
Fixed flake8 errors. runtests.sh failing at ptype.
ybagdasa May 19, 2025
992391e
enable different py env for ci tests
yiheng-wang-nv May 29, 2025
52cce77
fix precommit
yiheng-wang-nv May 29, 2025
03525b8
add conda init for cpu test
yiheng-wang-nv May 29, 2025
ee65966
update premerge cpu script
yiheng-wang-nv May 29, 2025
33cc537
add conda init
yiheng-wang-nv May 29, 2025
f767da8
adjust conda init way
yiheng-wang-nv May 29, 2025
a07021c
update init conda env
yiheng-wang-nv May 29, 2025
310742b
Merge branch 'dev' into 730-retinalOCT_RPD_segmentation
yiheng-wang-nv Jun 3, 2025
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
63 changes: 52 additions & 11 deletions .github/workflows/premerge-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,70 @@ jobs:
premerge-cpu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.10.14 # This will be the default Python

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
# The python-version here is for Conda's base, if activated.
# We set auto-activate-base to false, so actions/setup-python's version remains default.
python-version: 3.10.14
auto-activate-base: false # Crucial: ensures the Python 3.10 from actions/setup-python is the default

- name: Initialize Conda for shell integration
shell: bash
run: |
conda init bash
eval "$(conda shell.bash hook)"

- name: cache weekly timestamp
id: pip-cache
id: pip-cache-ts
run: |
echo "::set-output name=datew::$(date '+%Y-%V')"
- name: cache for pip
echo "datew=$(date '+%Y-%V')" >> $GITHUB_OUTPUT

- name: Get pip cache directory
id: pip-cache-dir
# This runs using the default Python (3.10)
shell: bash
run: echo "dir=$(python -m pip cache dir)" >> $GITHUB_OUTPUT

- name: Cache pip dependencies (for Python 3.10 global env)
uses: actions/cache@v4
id: cache-pip
with:
path: ${{ steps.pip-cache-dir.outputs.dir }}
key: ${{ runner.os }}-pip-3.10-${{ steps.pip-cache-ts.outputs.datew }}-${{ hashFiles('**/requirements.txt', '**/setup.py') }}
restore-keys: |
${{ runner.os }}-pip-3.10-${{ steps.pip-cache-ts.outputs.datew }}-

# Cache Conda packages (for environments your bash script might create)
# setup-miniconda action sets MINICONDA_PATH_0 environment variable
- name: Cache Conda packages
uses: actions/cache@v4
id: cache
id: cache-conda
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ steps.pip-cache.outputs.datew }}
- name: Install dependencies
path: ${{ env.MINICONDA_PATH_0 }}/pkgs
key: ${{ runner.os }}-conda-pkgs-${{ steps.pip-cache-ts.outputs.datew }}-${{ hashFiles('**/environment*.yml', '**/requirements*.txt') }} # Adjust hashFiles as needed
restore-keys: |
${{ runner.os }}-conda-pkgs-${{ steps.pip-cache-ts.outputs.datew }}-

- name: Install global Python dependencies (using Python 3.10)
shell: bash
run: |
python -m pip install --upgrade pip wheel
python -m pip install --upgrade setuptools
- name: check

- name: Run check script
shell: bash -el {0}
run: |
# clean up temporary files
$(pwd)/runtests.sh --clean
df -h
bash $(pwd)/ci/run_premerge_cpu.sh changed
shell: bash
bash $(pwd)/ci/run_premerge_cpu.sh
12 changes: 10 additions & 2 deletions ci/bundle_custom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
"maisi_ct_generative",
"cxr_image_synthesis_latent_diffusion_model",
"brain_image_synthesis_latent_diffusion_model",
"retinalOCT_RPD_segmentation",
]

# This list is used for our CI tests to determine whether a bundle contains the preferred files.
# If a bundle does not have any of the preferred files, please add the bundle name into the list.
exclude_verify_preferred_files_list = ["pediatric_abdominal_ct_segmentation", "maisi_ct_generative"]
exclude_verify_preferred_files_list = [
"pediatric_abdominal_ct_segmentation",
"maisi_ct_generative",
"retinalOCT_RPD_segmentation",
]

# This list is used for our CI tests to determine whether a bundle needs to be tested with
# the `verify_export_torchscript` function in `verify_bundle.py`.
Expand All @@ -47,6 +52,7 @@
"mednist_ddpm",
"cxr_image_synthesis_latent_diffusion_model",
"brain_image_synthesis_latent_diffusion_model",
"retinalOCT_RPD_segmentation",
]

# This list is used for our CI tests to determine whether a bundle needs to be tested after downloading
Expand All @@ -58,7 +64,9 @@
# This dict is used for our CI tests to install required dependencies that cannot be installed by `pip install` directly.
# If a bundle has this kind of dependencies, please add the bundle name (key), and the path of the install script (value)
# into the dict.
install_dependency_dict = {}
install_dependency_dict = {
"retinalOCT_RPD_segmentation": "ci/install_scripts/install_retinalOCT_RPD_segmentation_dependency.sh"
}

# This list is used for our CI tests to determine whether a bundle supports TensorRT export. Related
# test will be employed for bundles in the dict.
Expand Down
4 changes: 4 additions & 0 deletions ci/get_bundle_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

ALLOW_MONAI_RC = os.environ.get("ALLOW_MONAI_RC", "false").lower() in ("true", "1", "t", "y", "yes")

special_dependencies_list = ["detectron2"]


def increment_version(version):
"""
Expand Down Expand Up @@ -79,6 +81,8 @@ def get_requirements(bundle, models_path, requirements_file):
if package_key in metadata.keys():
optional_dict = metadata[package_key]
for name, version in optional_dict.items():
if name in special_dependencies_list:
continue
libs.append(f"{name}=={version}")

if len(libs) > 0:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ensure that using evironment with python==3.9
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git@65184fc057d4fab080a98564f6b60fae0b94edc4'
84 changes: 74 additions & 10 deletions ci/run_premerge_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ elif [[ $# -gt 1 ]]; then
exit 1
fi

# Bunles that requires special python version
declare -A bundle_python_versions=(
["retinalOCT_RPD_segmentation"]="3.9"
)
DEFAULT_PYTHON_VERSION_FOR_VENV="3.10"

# Usually, CPU test is required, but for some bundles that are too large to run in Github Actions, we can exclude them.
exclude_test_list=("maisi_ct_generative")
is_excluded() {
Expand All @@ -41,22 +47,23 @@ is_excluded() {
return 1 # Return false (1) if not excluded
}

install_common_deps_in_activated_env() {
python -m pip install --upgrade pip wheel
python -m pip install --upgrade setuptools
python -m pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
}

init_venv() {
if [ ! -d "model_zoo_venv" ]; then # Check if the venv directory does not exist
echo "initializing pip environment"
python -m venv model_zoo_venv
source model_zoo_venv/bin/activate
pip install --upgrade pip wheel
pip install --upgrade setuptools
pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
install_common_deps_in_activated_env
else
echo "Virtual environment model_zoo_venv already exists. Activating..."
source model_zoo_venv/bin/activate
pip install --upgrade pip wheel
pip install --upgrade setuptools
pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
install_common_deps_in_activated_env
fi
}

Expand All @@ -70,6 +77,42 @@ remove_venv() {
fi
}

init_conda_env() {
local python_version_to_create="$1"
local bundle_identifier="$2"
local conda_env_name="conda_env_${bundle_identifier}"

# Always source conda.sh to ensure conda activate is available
if [ -n "$CONDA_EXE" ] && [ -f "$(dirname "$CONDA_EXE")/../etc/profile.d/conda.sh" ]; then
source "$(dirname "$CONDA_EXE")/../etc/profile.d/conda.sh"
elif [ -n "$MINICONDA_PATH_0" ] && [ -f "$MINICONDA_PATH_0/etc/profile.d/conda.sh" ]; then
source "$MINICONDA_PATH_0/etc/profile.d/conda.sh"
else
echo "Warning: Could not reliably source conda.sh for Conda activation."
fi

if conda env list | grep -q "^${conda_env_name}[[:space:]]"; then
echo "Conda env '$conda_env_name' already exists. Removing for a clean start..."
conda env remove -n "$conda_env_name" -y
fi

conda create -n "$conda_env_name" python="$python_version_to_create" -y
conda activate "$conda_env_name"
install_common_deps_in_activated_env
conda deactivate 2>/dev/null || true
}

remove_conda_env() {
local conda_env_name_to_remove="$1"
if [ -z "$conda_env_name_to_remove" ]; then
echo "Warning: No Conda env name provided to remove_conda_env."
return
fi
echo "Deactivating and removing Conda environment: $conda_env_name_to_remove"
conda deactivate 2>/dev/null || true
conda env remove -n "$conda_env_name_to_remove" -y
}

verify_bundle() {
for dir in /opt/hostedtoolcache/*; do
if [[ $dir != "/opt/hostedtoolcache/Python" ]]; then
Expand Down Expand Up @@ -106,15 +149,36 @@ verify_bundle() {
else
include_pre_release=""
fi
init_venv
# determine if conda env should be used for the bundle
active_conda_env_for_bundle=""
required_python_version="${bundle_python_versions[$bundle]}"
use_conda_for_bundle=false
if [[ -n "$required_python_version" && "$required_python_version" != "$DEFAULT_PYTHON_VERSION_FOR_VENV" ]]
then
use_conda_for_bundle=true
fi
if $use_conda_for_bundle
then
init_conda_env "$required_python_version" "$bundle"
active_conda_env_for_bundle="conda_env_${bundle}"
conda activate "$active_conda_env_for_bundle"
else
init_venv
fi
# Check if the requirements file exists and is not empty
if [ -s "$requirements_file" ]; then
echo "install required libraries for bundle: $bundle"
pip install $include_pre_release -r "$requirements_file"
fi
# verify bundle
python $(pwd)/ci/verify_bundle.py -b "$bundle" -m "min" # min tests on cpu
remove_venv
# cleanup
if $use_conda_for_bundle
then
remove_conda_env "$active_conda_env_for_bundle"
else
remove_venv
fi
fi
done
else
Expand Down
83 changes: 73 additions & 10 deletions ci/run_premerge_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,28 @@ if [[ $# -gt 1 ]]; then
exit 1
fi

declare -A bundle_python_versions=(
["retinalOCT_RPD_segmentation"]="3.9"
)
DEFAULT_PYTHON_VERSION_FOR_VENV="3.10"

install_common_deps_in_activated_env() {
python -m pip install --upgrade pip wheel
python -m pip install --upgrade setuptools
python -m pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
}

init_venv() {
if [ ! -d "model_zoo_venv" ]; then # Check if the venv directory does not exist
echo "initializing pip environment"
python -m venv model_zoo_venv
source model_zoo_venv/bin/activate
pip install --upgrade pip wheel
pip install --upgrade setuptools
pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
install_common_deps_in_activated_env
else
echo "Virtual environment model_zoo_venv already exists. Activating..."
source model_zoo_venv/bin/activate
pip install --upgrade pip wheel
pip install --upgrade setuptools
pip install jsonschema gdown pyyaml parameterized fire
export PYTHONPATH=$PWD
install_common_deps_in_activated_env
fi
}

Expand All @@ -58,6 +64,42 @@ remove_venv() {
fi
}

init_conda_env() {
local python_version_to_create="$1"
local bundle_identifier="$2"
local conda_env_name="conda_env_${bundle_identifier}"

# Always source conda.sh to ensure conda activate is available
if [ -n "$CONDA_EXE" ] && [ -f "$(dirname "$CONDA_EXE")/../etc/profile.d/conda.sh" ]; then
source "$(dirname "$CONDA_EXE")/../etc/profile.d/conda.sh"
elif [ -n "$MINICONDA_PATH_0" ] && [ -f "$MINICONDA_PATH_0/etc/profile.d/conda.sh" ]; then
source "$MINICONDA_PATH_0/etc/profile.d/conda.sh"
else
echo "Warning: Could not reliably source conda.sh for Conda activation."
fi

if conda env list | grep -q "^${conda_env_name}[[:space:]]"; then
echo "Conda env '$conda_env_name' already exists. Removing for a clean start..."
conda env remove -n "$conda_env_name" -y
fi

conda create -n "$conda_env_name" python="$python_version_to_create" -y
conda activate "$conda_env_name"
install_common_deps_in_activated_env
conda deactivate 2>/dev/null || true
}

remove_conda_env() {
local conda_env_name_to_remove="$1"
if [ -z "$conda_env_name_to_remove" ]; then
echo "Warning: No Conda env name provided to remove_conda_env."
return
fi
echo "Deactivating and removing Conda environment: $conda_env_name_to_remove"
conda deactivate 2>/dev/null || true
conda env remove -n "$conda_env_name_to_remove" -y
}

verify_bundle() {
echo 'Run verify bundle...'
head_ref=$(git rev-parse HEAD)
Expand All @@ -82,7 +124,22 @@ verify_bundle() {
else
include_pre_release=""
fi
init_venv
# determine if conda env should be used for the bundle
active_conda_env_for_bundle=""
required_python_version="${bundle_python_versions[$bundle]}"
use_conda_for_bundle=false
if [[ -n "$required_python_version" && "$required_python_version" != "$DEFAULT_PYTHON_VERSION_FOR_VENV" ]]
then
use_conda_for_bundle=true
fi
if $use_conda_for_bundle
then
init_conda_env "$required_python_version" "$bundle"
active_conda_env_for_bundle="conda_env_${bundle}"
conda activate "$active_conda_env_for_bundle"
else
init_venv
fi
# Check if the requirements file exists and is not empty
if [ -s "$requirements_file" ]; then
echo "install required libraries for bundle: $bundle"
Expand All @@ -101,7 +158,13 @@ verify_bundle() {
test_cmd="torchrun $(pwd)/ci/unit_tests/runner.py --b \"$bundle\" --dist True"
fi
eval $test_cmd
remove_venv
# cleanup
if $use_conda_for_bundle
then
remove_conda_env "$active_conda_env_for_bundle"
else
remove_venv
fi
done
else
echo "this pull request does not change any bundles, skip verify."
Expand Down
3 changes: 1 addition & 2 deletions ci/run_regular_tests_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ elif [[ $# -gt 1 ]]; then
exit 1
fi

# Usually, CPU test is required, but for some bundles that are too large to run in Github Actions, we can exclude them.
exclude_test_list=("maisi_ct_generative")
exclude_test_list=("maisi_ct_generative" "retinalOCT_RPD_segmentation")
is_excluded() {
for item in "${exclude_test_list[@]}"; do # Use exclude_test_list here
if [ "$1" == "$item" ]; then
Expand Down
Loading