Skip to content

Commit 5da7c66

Browse files
authored
Merge branch 'Project-MONAI:dev' into fix-6840
2 parents 8b7463d + 2e391c8 commit 5da7c66

37 files changed

+671
-148
lines changed

.github/workflows/cron.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@ jobs:
1313
strategy:
1414
matrix:
1515
environment:
16-
- "PT113+CUDA118"
17-
- "PT210+CUDA121"
16+
- "PT230+CUDA121"
1817
- "PT240+CUDA126"
1918
- "PTLATEST+CUDA126"
2019
include:
2120
# https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes
22-
- environment: PT113+CUDA118
23-
pytorch: "torch==1.13.1 torchvision==0.14.1 --extra-index-url https://download.pytorch.org/whl/cu121"
24-
base: "nvcr.io/nvidia/pytorch:22.10-py3" # CUDA 11.8
25-
- environment: PT210+CUDA121
26-
pytorch: "pytorch==2.1.0 torchvision==0.16.0 --extra-index-url https://download.pytorch.org/whl/cu121"
21+
- environment: PT230+CUDA121
22+
pytorch: "pytorch==2.3.0 torchvision==0.18.0 --extra-index-url https://download.pytorch.org/whl/cu121"
2723
base: "nvcr.io/nvidia/pytorch:23.08-py3" # CUDA 12.1
2824
- environment: PT240+CUDA126
2925
pytorch: "pytorch==2.4.0 torchvision==0.19.0 --extra-index-url https://download.pytorch.org/whl/cu121"

.github/workflows/pythonapp-gpu.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ jobs:
2222
strategy:
2323
matrix:
2424
environment:
25-
- "PT113+CUDA116"
26-
- "PT210+CUDA121DOCKER"
25+
- "PT230+CUDA124DOCKER"
26+
- "PT240+CUDA125DOCKER"
27+
- "PT250+CUDA126DOCKER"
2728
include:
2829
# https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes
29-
- environment: PT113+CUDA116
30-
pytorch: "torch==1.13.1 torchvision==0.14.1"
31-
base: "nvcr.io/nvidia/cuda:11.6.1-devel-ubuntu18.04"
32-
- environment: PT210+CUDA121DOCKER
33-
# 23.08: 2.1.0a0+29c30b1
30+
- environment: PT230+CUDA124DOCKER
31+
# 24.04: 2.3.0a0+6ddf5cf85e
3432
pytorch: "-h" # we explicitly set pytorch to -h to avoid pip install error
35-
base: "nvcr.io/nvidia/pytorch:23.08-py3"
36-
- environment: PT210+CUDA121DOCKER
37-
# 24.08: 2.3.0a0+40ec155e58.nv24.3
33+
base: "nvcr.io/nvidia/pytorch:24.04-py3"
34+
- environment: PT240+CUDA125DOCKER
35+
# 24.06: 2.4.0a0+f70bd71a48
36+
pytorch: "-h" # we explicitly set pytorch to -h to avoid pip install error
37+
base: "nvcr.io/nvidia/pytorch:24.06-py3"
38+
- environment: PT250+CUDA126DOCKER
39+
# 24.08: 2.5.0a0+872d972e41
3840
pytorch: "-h" # we explicitly set pytorch to -h to avoid pip install error
3941
base: "nvcr.io/nvidia/pytorch:24.08-py3"
4042
container:
@@ -49,7 +51,7 @@ jobs:
4951
apt-get update
5052
apt-get install -y wget
5153
52-
if [ ${{ matrix.environment }} = "PT113+CUDA116" ]
54+
if [ ${{ matrix.environment }} = "PT230+CUDA124" ]
5355
then
5456
PYVER=3.9 PYSFX=3 DISTUTILS=python3-distutils && \
5557
apt-get update && apt-get install -y --no-install-recommends \
@@ -114,7 +116,7 @@ jobs:
114116
# build for the current self-hosted CI Tesla V100
115117
BUILD_MONAI=1 TORCH_CUDA_ARCH_LIST="7.0" ./runtests.sh --build --disttests
116118
./runtests.sh --quick --unittests
117-
if [ ${{ matrix.environment }} = "PT113+CUDA116" ]; then
119+
if [ ${{ matrix.environment }} = "PT230+CUDA124" ]; then
118120
# test the clang-format tool downloading once
119121
coverage run -m tests.clang_format_utils
120122
fi

.github/workflows/pythonapp-min.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
strategy:
125125
fail-fast: false
126126
matrix:
127-
pytorch-version: ['1.13.1', '2.0.1', '2.2.2', '2.3.1', '2.4.1', 'latest']
127+
pytorch-version: ['2.3.1', '2.4.1', '2.5.1', 'latest']
128128
timeout-minutes: 40
129129
steps:
130130
- uses: actions/checkout@v4

.github/workflows/pythonapp.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
- if: runner.os == 'windows'
9595
name: Install torch cpu from pytorch.org (Windows only)
9696
run: |
97-
python -m pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
97+
python -m pip install torch==2.4.1 torchvision==0.19.1+cpu --index-url https://download.pytorch.org/whl/cpu
9898
- if: runner.os == 'Linux'
9999
name: Install itk pre-release (Linux only)
100100
run: |
@@ -103,7 +103,7 @@ jobs:
103103
- name: Install the dependencies
104104
run: |
105105
python -m pip install --user --upgrade pip wheel
106-
python -m pip install torch==1.13.1 torchvision==0.14.1
106+
python -m pip install torch==2.4.1 torchvision==0.19.1
107107
cat "requirements-dev.txt"
108108
python -m pip install -r requirements-dev.txt
109109
python -m pip list
@@ -155,7 +155,7 @@ jobs:
155155
# install the latest pytorch for testing
156156
# however, "pip install monai*.tar.gz" will build cpp/cuda with an isolated
157157
# fresh torch installation according to pyproject.toml
158-
python -m pip install torch>=1.13.1 torchvision
158+
python -m pip install torch>=2.3.0 torchvision
159159
- name: Check packages
160160
run: |
161161
pip uninstall monai

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
MONAI is a [PyTorch](https://pytorch.org/)-based, [open-source](https://github.com/Project-MONAI/MONAI/blob/dev/LICENSE) framework for deep learning in healthcare imaging, part of the [PyTorch Ecosystem](https://pytorch.org/ecosystem/).
2020
Its ambitions are as follows:
21+
2122
- Developing a community of academic, industrial and clinical researchers collaborating on a common foundation;
2223
- Creating state-of-the-art, end-to-end training workflows for healthcare imaging;
2324
- Providing researchers with the optimized and standardized way to create and evaluate deep learning models.
2425

25-
2626
## Features
27+
2728
> _Please see [the technical highlights](https://docs.monai.io/en/latest/highlights.html) and [What's New](https://docs.monai.io/en/latest/whatsnew.html) of the milestone releases._
2829
2930
- flexible pre-processing for multi-dimensional medical imaging data;
@@ -32,7 +33,6 @@ Its ambitions are as follows:
3233
- customizable design for varying user expertise;
3334
- multi-GPU multi-node data parallelism support.
3435

35-
3636
## Installation
3737

3838
To install [the current release](https://pypi.org/project/monai/), you can simply run:
@@ -53,30 +53,34 @@ Technical documentation is available at [docs.monai.io](https://docs.monai.io).
5353

5454
## Citation
5555

56-
If you have used MONAI in your research, please cite us! The citation can be exported from: https://arxiv.org/abs/2211.02701.
56+
If you have used MONAI in your research, please cite us! The citation can be exported from: <https://arxiv.org/abs/2211.02701>.
5757

5858
## Model Zoo
59+
5960
[The MONAI Model Zoo](https://github.com/Project-MONAI/model-zoo) is a place for researchers and data scientists to share the latest and great models from the community.
6061
Utilizing [the MONAI Bundle format](https://docs.monai.io/en/latest/bundle_intro.html) makes it easy to [get started](https://github.com/Project-MONAI/tutorials/tree/main/model_zoo) building workflows with MONAI.
6162

6263
## Contributing
64+
6365
For guidance on making a contribution to MONAI, see the [contributing guidelines](https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md).
6466

6567
## Community
68+
6669
Join the conversation on Twitter/X [@ProjectMONAI](https://twitter.com/ProjectMONAI) or join our [Slack channel](https://forms.gle/QTxJq3hFictp31UM9).
6770

6871
Ask and answer questions over on [MONAI's GitHub Discussions tab](https://github.com/Project-MONAI/MONAI/discussions).
6972

7073
## Links
71-
- Website: https://monai.io/
72-
- API documentation (milestone): https://docs.monai.io/
73-
- API documentation (latest dev): https://docs.monai.io/en/latest/
74-
- Code: https://github.com/Project-MONAI/MONAI
75-
- Project tracker: https://github.com/Project-MONAI/MONAI/projects
76-
- Issue tracker: https://github.com/Project-MONAI/MONAI/issues
77-
- Wiki: https://github.com/Project-MONAI/MONAI/wiki
78-
- Test status: https://github.com/Project-MONAI/MONAI/actions
79-
- PyPI package: https://pypi.org/project/monai/
80-
- conda-forge: https://anaconda.org/conda-forge/monai
81-
- Weekly previews: https://pypi.org/project/monai-weekly/
82-
- Docker Hub: https://hub.docker.com/r/projectmonai/monai
74+
75+
- Website: <https://monai.io/>
76+
- API documentation (milestone): <https://docs.monai.io/>
77+
- API documentation (latest dev): <https://docs.monai.io/en/latest/>
78+
- Code: <https://github.com/Project-MONAI/MONAI>
79+
- Project tracker: <https://github.com/Project-MONAI/MONAI/projects>
80+
- Issue tracker: <https://github.com/Project-MONAI/MONAI/issues>
81+
- Wiki: <https://github.com/Project-MONAI/MONAI/wiki>
82+
- Test status: <https://github.com/Project-MONAI/MONAI/actions>
83+
- PyPI package: <https://pypi.org/project/monai/>
84+
- conda-forge: <https://anaconda.org/conda-forge/monai>
85+
- Weekly previews: <https://pypi.org/project/monai-weekly/>
86+
- Docker Hub: <https://hub.docker.com/r/projectmonai/monai>

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-f https://download.pytorch.org/whl/cpu/torch-1.13.1%2Bcpu-cp39-cp39-linux_x86_64.whl
2-
torch>=1.13.1
1+
-f https://download.pytorch.org/whl/cpu/torch-2.3.0%2Bcpu-cp39-cp39-linux_x86_64.whl
2+
torch>=2.3.0
33
pytorch-ignite==0.4.11
44
numpy>=1.20
55
itk>=5.2

docs/source/handlers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ ROC AUC metrics handler
5353
:members:
5454

5555

56+
Average Precision metric handler
57+
--------------------------------
58+
.. autoclass:: AveragePrecision
59+
:members:
60+
61+
5662
Confusion matrix metrics handler
5763
--------------------------------
5864
.. autoclass:: ConfusionMatrix

docs/source/metrics.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ Metrics
8080
.. autoclass:: ROCAUCMetric
8181
:members:
8282

83+
`Average Precision`
84+
-------------------
85+
.. autofunction:: compute_average_precision
86+
87+
.. autoclass:: AveragePrecisionMetric
88+
:members:
89+
8390
`Confusion matrix`
8491
------------------
8592
.. autofunction:: get_confusion_matrix

environment-dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ channels:
55
- nvidia
66
- conda-forge
77
dependencies:
8-
- numpy>=1.24,<2.0
9-
- pytorch>=1.13.1
8+
- numpy>=1.24,<3.0
9+
- pytorch>=2.3.0
1010
- torchio
1111
- torchvision
1212
- pytorch-cuda>=11.6

monai/bundle/scripts.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
import os
1717
import re
18+
import urllib
1819
import warnings
1920
import zipfile
2021
from collections.abc import Mapping, Sequence
@@ -58,7 +59,7 @@
5859
validate, _ = optional_import("jsonschema", name="validate")
5960
ValidationError, _ = optional_import("jsonschema.exceptions", name="ValidationError")
6061
Checkpoint, has_ignite = optional_import("ignite.handlers", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Checkpoint")
61-
requests_get, has_requests = optional_import("requests", name="get")
62+
requests, has_requests = optional_import("requests")
6263
onnx, _ = optional_import("onnx")
6364
huggingface_hub, _ = optional_import("huggingface_hub")
6465

@@ -206,6 +207,16 @@ def _download_from_monaihosting(download_path: Path, filename: str, version: str
206207
extractall(filepath=filepath, output_dir=download_path, has_base=True)
207208

208209

210+
def _download_from_bundle_info(download_path: Path, filename: str, version: str, progress: bool) -> None:
211+
bundle_info = get_bundle_info(bundle_name=filename, version=version)
212+
if not bundle_info:
213+
raise ValueError(f"Bundle info not found for {filename} v{version}.")
214+
url = bundle_info["browser_download_url"]
215+
filepath = download_path / f"{filename}_v{version}.zip"
216+
download_url(url=url, filepath=filepath, hash_val=None, progress=progress)
217+
extractall(filepath=filepath, output_dir=download_path, has_base=True)
218+
219+
209220
def _add_ngc_prefix(name: str, prefix: str = "monai_") -> str:
210221
if name.startswith(prefix):
211222
return name
@@ -222,7 +233,7 @@ def _get_all_download_files(request_url: str, headers: dict | None = None) -> li
222233
if not has_requests:
223234
raise ValueError("requests package is required, please install it.")
224235
headers = {} if headers is None else headers
225-
response = requests_get(request_url, headers=headers)
236+
response = requests.get(request_url, headers=headers)
226237
response.raise_for_status()
227238
model_info = json.loads(response.text)
228239

@@ -266,7 +277,7 @@ def _download_from_ngc_private(
266277
request_url = _get_ngc_private_bundle_url(model_name=filename, version=version, repo=repo)
267278
if has_requests:
268279
headers = {} if headers is None else headers
269-
response = requests_get(request_url, headers=headers)
280+
response = requests.get(request_url, headers=headers)
270281
response.raise_for_status()
271282
else:
272283
raise ValueError("NGC API requires requests package. Please install it.")
@@ -289,7 +300,7 @@ def _get_ngc_token(api_key, retry=0):
289300
url = "https://authn.nvidia.com/token?service=ngc"
290301
headers = {"Accept": "application/json", "Authorization": "ApiKey " + api_key}
291302
if has_requests:
292-
response = requests_get(url, headers=headers)
303+
response = requests.get(url, headers=headers)
293304
if not response.ok:
294305
# retry 3 times, if failed, raise an error.
295306
if retry < 3:
@@ -303,14 +314,17 @@ def _get_ngc_token(api_key, retry=0):
303314

304315
def _get_latest_bundle_version_monaihosting(name):
305316
full_url = f"{MONAI_HOSTING_BASE_URL}/{name.lower()}"
306-
requests_get, has_requests = optional_import("requests", name="get")
307317
if has_requests:
308-
resp = requests_get(full_url)
309-
resp.raise_for_status()
310-
else:
311-
raise ValueError("NGC API requires requests package. Please install it.")
312-
model_info = json.loads(resp.text)
313-
return model_info["model"]["latestVersionIdStr"]
318+
resp = requests.get(full_url)
319+
try:
320+
resp.raise_for_status()
321+
model_info = json.loads(resp.text)
322+
return model_info["model"]["latestVersionIdStr"]
323+
except requests.exceptions.HTTPError:
324+
# for monaihosting bundles, if cannot find the version, get from model zoo model_info.json
325+
return get_bundle_versions(name)["latest_version"]
326+
327+
raise ValueError("NGC API requires requests package. Please install it.")
314328

315329

316330
def _examine_monai_version(monai_version: str) -> tuple[bool, str]:
@@ -388,14 +402,14 @@ def _get_latest_bundle_version_ngc(name: str, repo: str | None = None, headers:
388402
version_header = {"Accept-Encoding": "gzip, deflate"} # Excluding 'zstd' to fit NGC requirements
389403
if headers:
390404
version_header.update(headers)
391-
resp = requests_get(version_endpoint, headers=version_header)
405+
resp = requests.get(version_endpoint, headers=version_header)
392406
resp.raise_for_status()
393407
model_info = json.loads(resp.text)
394408
latest_versions = _list_latest_versions(model_info)
395409

396410
for version in latest_versions:
397411
file_endpoint = base_url + f"/{name.lower()}/versions/{version}/files/configs/metadata.json"
398-
resp = requests_get(file_endpoint, headers=headers)
412+
resp = requests.get(file_endpoint, headers=headers)
399413
metadata = json.loads(resp.text)
400414
resp.raise_for_status()
401415
# if the package version is not available or the model is compatible with the package version
@@ -585,7 +599,16 @@ def download(
585599
name_ver = "_v".join([name_, version_]) if version_ is not None else name_
586600
_download_from_github(repo=repo_, download_path=bundle_dir_, filename=name_ver, progress=progress_)
587601
elif source_ == "monaihosting":
588-
_download_from_monaihosting(download_path=bundle_dir_, filename=name_, version=version_, progress=progress_)
602+
try:
603+
_download_from_monaihosting(
604+
download_path=bundle_dir_, filename=name_, version=version_, progress=progress_
605+
)
606+
except urllib.error.HTTPError:
607+
# for monaihosting bundles, if cannot download from default host, download according to bundle_info
608+
_download_from_bundle_info(
609+
download_path=bundle_dir_, filename=name_, version=version_, progress=progress_
610+
)
611+
589612
elif source_ == "ngc":
590613
_download_from_ngc(
591614
download_path=bundle_dir_,
@@ -792,9 +815,9 @@ def _get_all_bundles_info(
792815

793816
if auth_token is not None:
794817
headers = {"Authorization": f"Bearer {auth_token}"}
795-
resp = requests_get(request_url, headers=headers)
818+
resp = requests.get(request_url, headers=headers)
796819
else:
797-
resp = requests_get(request_url)
820+
resp = requests.get(request_url)
798821
resp.raise_for_status()
799822
else:
800823
raise ValueError("requests package is required, please install it.")

0 commit comments

Comments
 (0)