monai-weekly 1.5.dev2449__py3-none-any.whl → 1.5.dev2451__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
monai/__init__.py CHANGED
@@ -136,4 +136,4 @@ except BaseException:
136
136
 
137
137
  if MONAIEnvVars.debug():
138
138
  raise
139
- __commit_id__ = "e604d1841fe60c0ffb6978ae4116535ca8d8f34f"
139
+ __commit_id__ = "efff647a332f9520e7b7d7565893bd16ab26e041"
monai/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2024-12-08T02:32:52+0000",
11
+ "date": "2024-12-22T02:28:23+0000",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "8cad248c8b374702245989507da1dd8430ef863f",
15
- "version": "1.5.dev2449"
14
+ "full-revisionid": "7c1c58cd10db72c01b5cdda1600cd68e262437cf",
15
+ "version": "1.5.dev2451"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
monai/apps/utils.py CHANGED
@@ -15,6 +15,7 @@ import hashlib
15
15
  import json
16
16
  import logging
17
17
  import os
18
+ import re
18
19
  import shutil
19
20
  import sys
20
21
  import tarfile
@@ -30,7 +31,9 @@ from urllib.request import urlopen, urlretrieve
30
31
  from monai.config.type_definitions import PathLike
31
32
  from monai.utils import look_up_option, min_version, optional_import
32
33
 
34
+ requests, has_requests = optional_import("requests")
33
35
  gdown, has_gdown = optional_import("gdown", "4.7.3")
36
+ BeautifulSoup, has_bs4 = optional_import("bs4", name="BeautifulSoup")
34
37
 
35
38
  if TYPE_CHECKING:
36
39
  from tqdm import tqdm
@@ -298,6 +301,29 @@ def extractall(
298
301
  )
299
302
 
300
303
 
304
+ def get_filename_from_url(data_url: str) -> str:
305
+ """
306
+ Get the filename from the URL link.
307
+ """
308
+ try:
309
+ response = requests.head(data_url, allow_redirects=True)
310
+ content_disposition = response.headers.get("Content-Disposition")
311
+ if content_disposition:
312
+ filename = re.findall('filename="?([^";]+)"?', content_disposition)
313
+ if filename:
314
+ return str(filename[0])
315
+ if "drive.google.com" in data_url:
316
+ response = requests.get(data_url)
317
+ if "text/html" in response.headers.get("Content-Type", ""):
318
+ soup = BeautifulSoup(response.text, "html.parser")
319
+ filename_div = soup.find("span", {"class": "uc-name-size"})
320
+ if filename_div:
321
+ return str(filename_div.find("a").text)
322
+ return _basename(data_url)
323
+ except Exception as e:
324
+ raise Exception(f"Error processing URL: {e}") from e
325
+
326
+
301
327
  def download_and_extract(
302
328
  url: str,
303
329
  filepath: PathLike = "",
@@ -327,7 +353,18 @@ def download_and_extract(
327
353
  be False.
328
354
  progress: whether to display progress bar.
329
355
  """
356
+ url_filename_ext = "".join(Path(get_filename_from_url(url)).suffixes)
357
+ filepath_ext = "".join(Path(_basename(filepath)).suffixes)
358
+ if filepath not in ["", "."]:
359
+ if filepath_ext == "":
360
+ new_filepath = Path(filepath).with_suffix(url_filename_ext)
361
+ logger.warning(
362
+ f"filepath={filepath}, which missing file extension. Auto-appending extension to: {new_filepath}"
363
+ )
364
+ filepath = new_filepath
365
+ if filepath_ext and filepath_ext != url_filename_ext:
366
+ raise ValueError(f"File extension mismatch: expected extension {url_filename_ext}, but get {filepath_ext}")
330
367
  with tempfile.TemporaryDirectory() as tmp_dir:
331
- filename = filepath or Path(tmp_dir, _basename(url)).resolve()
368
+ filename = filepath or Path(tmp_dir, get_filename_from_url(url)).resolve()
332
369
  download_url(url=url, filepath=filename, hash_val=hash_val, hash_type=hash_type, progress=progress)
333
370
  extractall(filepath=filename, output_dir=output_dir, file_type=file_type, has_base=has_base)
monai/engines/workflow.py CHANGED
@@ -12,7 +12,7 @@
12
12
  from __future__ import annotations
13
13
 
14
14
  import warnings
15
- from collections.abc import Callable, Iterable, Sequence
15
+ from collections.abc import Callable, Iterable, Sequence, Sized
16
16
  from typing import TYPE_CHECKING, Any
17
17
 
18
18
  import torch
@@ -121,24 +121,24 @@ class Workflow(Engine):
121
121
  to_kwargs: dict | None = None,
122
122
  amp_kwargs: dict | None = None,
123
123
  ) -> None:
124
- if iteration_update is not None:
125
- super().__init__(iteration_update)
126
- else:
127
- super().__init__(self._iteration)
124
+ super().__init__(self._iteration if iteration_update is None else iteration_update)
128
125
 
129
126
  if isinstance(data_loader, DataLoader):
130
- sampler = data_loader.__dict__["sampler"]
127
+ sampler = getattr(data_loader, "sampler", None)
128
+
129
+ # set the epoch value for DistributedSampler objects when an epoch starts
131
130
  if isinstance(sampler, DistributedSampler):
132
131
 
133
132
  @self.on(Events.EPOCH_STARTED)
134
133
  def set_sampler_epoch(engine: Engine) -> None:
135
134
  sampler.set_epoch(engine.state.epoch)
136
135
 
137
- if epoch_length is None:
136
+ # if the epoch_length isn't given, attempt to get it from the length of the data loader
137
+ if epoch_length is None and isinstance(data_loader, Sized):
138
+ try:
138
139
  epoch_length = len(data_loader)
139
- else:
140
- if epoch_length is None:
141
- raise ValueError("If data_loader is not PyTorch DataLoader, must specify the epoch_length.")
140
+ except TypeError: # raised when data_loader has an iterable dataset with no length, or is some other type
141
+ pass # deliberately leave epoch_length as None
142
142
 
143
143
  # set all sharable data for the workflow based on Ignite engine.state
144
144
  self.state: Any = State(
@@ -147,7 +147,7 @@ class Workflow(Engine):
147
147
  iteration=0,
148
148
  epoch=0,
149
149
  max_epochs=max_epochs,
150
- epoch_length=epoch_length,
150
+ epoch_length=epoch_length, # None when the dataset is iterable and so has no length
151
151
  output=None,
152
152
  batch=None,
153
153
  metrics={},
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: monai-weekly
3
- Version: 1.5.dev2449
3
+ Version: 1.5.dev2451
4
4
  Summary: AI Toolkit for Healthcare Imaging
5
5
  Home-page: https://monai.io/
6
6
  Author: MONAI Consortium
@@ -46,10 +46,10 @@ Requires-Dist: itk>=5.2; extra == "all"
46
46
  Requires-Dist: tqdm>=4.47.0; extra == "all"
47
47
  Requires-Dist: lmdb; extra == "all"
48
48
  Requires-Dist: psutil; extra == "all"
49
- Requires-Dist: cucim-cu12; (python_version >= "3.9" and python_version <= "3.10") and extra == "all"
49
+ Requires-Dist: cucim-cu12; (platform_system == "Linux" and python_version >= "3.9" and python_version <= "3.10") and extra == "all"
50
50
  Requires-Dist: openslide-python; extra == "all"
51
- Requires-Dist: tifffile; extra == "all"
52
- Requires-Dist: imagecodecs; extra == "all"
51
+ Requires-Dist: tifffile; (platform_system == "Linux" or platform_system == "Darwin") and extra == "all"
52
+ Requires-Dist: imagecodecs; (platform_system == "Linux" or platform_system == "Darwin") and extra == "all"
53
53
  Requires-Dist: pandas; extra == "all"
54
54
  Requires-Dist: einops; extra == "all"
55
55
  Requires-Dist: transformers<4.41.0,>=4.36.0; python_version <= "3.10" and extra == "all"
@@ -63,7 +63,7 @@ Requires-Dist: jsonschema; extra == "all"
63
63
  Requires-Dist: pynrrd; extra == "all"
64
64
  Requires-Dist: pydicom; extra == "all"
65
65
  Requires-Dist: h5py; extra == "all"
66
- Requires-Dist: nni; extra == "all"
66
+ Requires-Dist: nni; (platform_system == "Linux" and "arm" not in platform_machine and "aarch" not in platform_machine) and extra == "all"
67
67
  Requires-Dist: optuna; extra == "all"
68
68
  Requires-Dist: onnx>=1.13.0; extra == "all"
69
69
  Requires-Dist: onnxruntime; python_version <= "3.10" and extra == "all"
@@ -101,13 +101,13 @@ Requires-Dist: lmdb; extra == "lmdb"
101
101
  Provides-Extra: psutil
102
102
  Requires-Dist: psutil; extra == "psutil"
103
103
  Provides-Extra: cucim
104
- Requires-Dist: cucim-cu12; extra == "cucim"
104
+ Requires-Dist: cucim-cu12; (platform_system == "Linux" and python_version >= "3.9" and python_version <= "3.10") and extra == "cucim"
105
105
  Provides-Extra: openslide
106
106
  Requires-Dist: openslide-python; extra == "openslide"
107
107
  Provides-Extra: tifffile
108
- Requires-Dist: tifffile; extra == "tifffile"
108
+ Requires-Dist: tifffile; (platform_system == "Linux" or platform_system == "Darwin") and extra == "tifffile"
109
109
  Provides-Extra: imagecodecs
110
- Requires-Dist: imagecodecs; extra == "imagecodecs"
110
+ Requires-Dist: imagecodecs; (platform_system == "Linux" or platform_system == "Darwin") and extra == "imagecodecs"
111
111
  Provides-Extra: pandas
112
112
  Requires-Dist: pandas; extra == "pandas"
113
113
  Provides-Extra: einops
@@ -137,7 +137,7 @@ Requires-Dist: pydicom; extra == "pydicom"
137
137
  Provides-Extra: h5py
138
138
  Requires-Dist: h5py; extra == "h5py"
139
139
  Provides-Extra: nni
140
- Requires-Dist: nni; extra == "nni"
140
+ Requires-Dist: nni; (platform_system == "Linux" and "arm" not in platform_machine and "aarch" not in platform_machine) and extra == "nni"
141
141
  Provides-Extra: optuna
142
142
  Requires-Dist: optuna; extra == "optuna"
143
143
  Provides-Extra: onnx
@@ -1,5 +1,5 @@
1
- monai/__init__.py,sha256=8nDtqXXT8g-2RkTMzJScb7J2ivFmb37BrqgM3S_NJ1k,4095
2
- monai/_version.py,sha256=uJdYCwRIEg12C-k2c1DKHw0XzzOkPRe-G7r0glT9iYU,503
1
+ monai/__init__.py,sha256=9uBqEYRgHOLxHMXL6KaeW64h3EEBWzVc8Q5_qNdvbHw,4095
2
+ monai/_version.py,sha256=xt33zPGBBDISzFAylvD8rM8SeH-5WwgMQzCJR1hckIE,503
3
3
  monai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  monai/_extensions/__init__.py,sha256=NEBPreRhQ8H9gVvgrLr_y52_TmqB96u_u4VQmeNT93I,642
5
5
  monai/_extensions/loader.py,sha256=7SiKw36q-nOzH8CRbBurFrz7GM40GCu7rc93Tm8XpnI,3643
@@ -10,7 +10,7 @@ monai/_extensions/gmm/gmm_cuda.cu,sha256=egWZBIpNYfOfxn0TKX82y-S2M6jg9NCzWwRcTLN
10
10
  monai/_extensions/gmm/gmm_cuda_linalg.cuh,sha256=Glqg2oAcUFUXg-DVfpROkiv-DdXvvVdM1nyiFm8qlHY,3520
11
11
  monai/apps/__init__.py,sha256=VDIc3HB_uFbqKL1TS-OeRvryEMDfzm22KJRzwpkXsGo,908
12
12
  monai/apps/datasets.py,sha256=msT58BoHlQFQpD4Tx-CThwAkkaUowoNZOgcH0THg0u0,35085
13
- monai/apps/utils.py,sha256=Gellkseuv3XKs-A6XcgbtqktQayv9NVIhX9tTQGM10I,14362
13
+ monai/apps/utils.py,sha256=kJ200fyf_folGggBd2VK_CXjiDVMIAxaB6wxTj4NvBI,16099
14
14
  monai/apps/auto3dseg/__init__.py,sha256=DhUB2Ol0-iNAk1ZNmD1RkTODUOhdiibv8h9MgcLuF6s,1016
15
15
  monai/apps/auto3dseg/__main__.py,sha256=fCDhD8uhmJQKkKBxLO6hMJhEvZJRIsjTc1Ad3bYmNIY,1411
16
16
  monai/apps/auto3dseg/auto_runner.py,sha256=a4Ry93TkK0aTb68bwle8HoG4SzUbUf0IbDrY33jTReg,40106
@@ -151,7 +151,7 @@ monai/engines/__init__.py,sha256=oV0zH5n8qPdCCNZCqLqN4Z7iqADouDtZmtswWQoZWOk,109
151
151
  monai/engines/evaluator.py,sha256=d0V4Ko1mcVsr9PtOhhtJYy4SVtrXuKdZ9yWM9mCYpAA,26961
152
152
  monai/engines/trainer.py,sha256=CmCw0C20A1EUgmpBt_eGHp9ObIJO5shqF7bQGJVskc0,38448
153
153
  monai/engines/utils.py,sha256=YGaa1Gk2b3bBtodbToGaSOD-s9X7wMgfgESOozZCLrM,15632
154
- monai/engines/workflow.py,sha256=S4DCLBSndcaM6LDb6xS-gTL8xCs8fiVejb-8O-pLKeQ,15226
154
+ monai/engines/workflow.py,sha256=FXZt8wN8m2U7wmXwoI0t1ILeieqsHtPwt5P8cMX71_A,15495
155
155
  monai/fl/__init__.py,sha256=s9djSd6kvViPnFvMR11Dgd30Lv4oY6FaPJr4ZZJZLq0,573
156
156
  monai/fl/client/__init__.py,sha256=Wnkcf-Guhi-d29eAH0p51jz1Tn9WSVM4UUGbbb9SAqQ,725
157
157
  monai/fl/client/client_algo.py,sha256=vetQbSNmuvJRBEcu0AKM96gKYbkSXlu4HSriqK7wiiU,5098
@@ -420,8 +420,8 @@ monai/visualize/img2tensorboard.py,sha256=NnMcyfIFqX-jD7TBO3Rn02zt5uug79d_7pIIaV
420
420
  monai/visualize/occlusion_sensitivity.py,sha256=OQHEJLyIhB8zWqQsfKaX-1kvCjWFVYtLfS4dFC0nKFI,18160
421
421
  monai/visualize/utils.py,sha256=B-MhTVs7sQbIqYS3yPnpBwPw2K82rE2PBtGIfpwZtWM,9894
422
422
  monai/visualize/visualizer.py,sha256=qckyaMZCbezYUwE20k5yc-Pb7UozVavMDbrmyQwfYHY,1377
423
- monai_weekly-1.5.dev2449.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
424
- monai_weekly-1.5.dev2449.dist-info/METADATA,sha256=pkXaiu1fplwCSKbFQn3lkiY_rbmynZAw6dJmE2RhjNk,11293
425
- monai_weekly-1.5.dev2449.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
426
- monai_weekly-1.5.dev2449.dist-info/top_level.txt,sha256=UaNwRzLGORdus41Ip446s3bBfViLkdkDsXDo34J2P44,6
427
- monai_weekly-1.5.dev2449.dist-info/RECORD,,
423
+ monai_weekly-1.5.dev2451.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
424
+ monai_weekly-1.5.dev2451.dist-info/METADATA,sha256=0Tg9NUHnzUVF_3-QgVzTfxt0yaQQ1X39LiDjn1THmws,11876
425
+ monai_weekly-1.5.dev2451.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
426
+ monai_weekly-1.5.dev2451.dist-info/top_level.txt,sha256=UaNwRzLGORdus41Ip446s3bBfViLkdkDsXDo34J2P44,6
427
+ monai_weekly-1.5.dev2451.dist-info/RECORD,,