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

6676 port generative engines #7406

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
a8c2a1a
5394 enable py311 tests (#7182)
wyli Nov 1, 2023
40aaea3
[Auto3DSeg] Add mlflow support in autorunner. (#7176)
dongyang0122 Nov 2, 2023
2971fcd
6627 reading dcm folder filtering filenames (#7181)
wyli Nov 2, 2023
3fc1993
Precision issue in `get_confusion_matrix ` (#7187)
KumoLiu Nov 2, 2023
3572fd5
autorunner params from config (#7175)
myron Nov 3, 2023
d8b6676
Implemented VoxelMorph (#7178)
kvttt Nov 3, 2023
016b386
auto updates (#7203)
monai-bot Nov 6, 2023
a2c671a
fix useless error msg in nnunetv2runner (#7217)
elitap Nov 15, 2023
4bad4bc
Fixup mypy 1.7.0 errors (#7231)
Shadow-Devil Nov 16, 2023
b9b57c8
add Yun Liu to user list to trigger blossom-ci [skip ci] (#7239)
YanxuanLiu Nov 17, 2023
a22b5dd
Replace single quotation marks with double quotation marks to install…
ytl0623 Nov 17, 2023
8f781eb
Update bug_report.md (#7213)
dzenanz Nov 17, 2023
bf166b5
Add cache option in `GridPatchDataset` (#7180)
KumoLiu Nov 17, 2023
2ecb612
:memo: [array] Add examples for EnsureType and CastToType (#7245)
ishandutta0098 Nov 19, 2023
e9673e8
:hammer: [dataset] Handle corrupted cached file in PersistentDataset …
ishandutta0098 Nov 20, 2023
fcb4ff4
auto updates (#7247)
monai-bot Nov 20, 2023
a99ea95
add class label option to write metric report to improve readability …
elitap Nov 22, 2023
ee68d50
Fix B026 unrecommanded star-arg unpacking after a keyword argument (#…
KumoLiu Nov 27, 2023
62ad35c
Quote $PY_EXE variable to deal with Python path that contain spaces i…
ytl0623 Nov 30, 2023
9ced3e5
add SoftclDiceLoss and SoftDiceclDiceLoss loss function in documentat…
ytl0623 Nov 30, 2023
8642877
Skip Old Pytorch Versions for `SwinUNETR` (#7266)
KumoLiu Nov 30, 2023
708167a
Bump conda-incubator/setup-miniconda from 2 to 3 (#7274)
dependabot[bot] Dec 1, 2023
039ee21
6676 port generative networks autoencoderkl (#7260)
marksgraham Dec 5, 2023
20a57e7
6676 port generative networks vqvae (#7285)
marksgraham Dec 7, 2023
5e2466d
6676 port generative networks transformer (#7300)
marksgraham Dec 11, 2023
249c39a
6676 port generative networks ddpm (#7304)
marksgraham Dec 12, 2023
c9f028e
6676 port generative networks controlnet (#7312)
marksgraham Dec 14, 2023
58b4575
Adds patchgan discriminator (#7319)
marksgraham Dec 14, 2023
aef4daf
6676 port generative networks spade (#7320)
marksgraham Dec 19, 2023
2fe972f
Adds adversarial trainer
marksgraham Dec 21, 2023
33dce3a
Updates docs
marksgraham Dec 21, 2023
023b6bb
Adds preparebatch
marksgraham Dec 21, 2023
a017b8b
Outline test, need schedulers and inferer implemented to finish
marksgraham Dec 21, 2023
64735eb
6676 port diffusion schedulers (#7332)
marksgraham Jan 3, 2024
2a8104d
6676 port diffusion schedulers (#7364)
marksgraham Jan 5, 2024
cc17f72
Adds ordering util (#7369)
marksgraham Jan 8, 2024
f377f2e
6676 port generative inferers (#7379)
marksgraham Jan 18, 2024
bc69d8b
Adds prepare batch engine
marksgraham Jan 18, 2024
2a8954b
Test prepare batch
marksgraham Jan 19, 2024
e15a50f
Skip nibabel test if not installed
marksgraham Jan 29, 2024
f60c4e2
Adds prepare batch to min tests
marksgraham Jan 29, 2024
11c1285
update the Python version requirements for transformers (#7275)
KumoLiu Dec 5, 2023
e15b570
7263 add diffusion loss (#7272)
kvttt Dec 5, 2023
fdbc611
[Attention block] relative positional embedding (#7346)
vgrau98 Jan 18, 2024
f87339e
Fix swinunetrv2 2D bug (#7302)
heyufan1995 Dec 8, 2023
9c07cb8
Fix `RuntimeError` in `DataAnalyzer` (#7310)
KumoLiu Dec 12, 2023
7eb1a7d
Support specified filenames in `Saveimage` (#7318)
KumoLiu Dec 14, 2023
426cec9
Fix typo (#7321)
KumoLiu Dec 15, 2023
4e2160c
fix optimizer pararmeter issue (#7322)
binliunls Dec 15, 2023
0e89c92
Fix `lazy` ignored in `SpatialPadd` (#7316)
KumoLiu Dec 18, 2023
0a03228
Update openslide-python version (#7344)
KumoLiu Dec 28, 2023
775ecac
Upgrade the version of `transformers` (#7343)
KumoLiu Dec 29, 2023
bc3c062
Bump github/codeql-action from 2 to 3 (#7354)
dependabot[bot] Jan 2, 2024
9d78d99
Bump actions/upload-artifact from 3 to 4 (#7350)
dependabot[bot] Jan 2, 2024
535830e
Bump actions/setup-python from 4 to 5 (#7351)
dependabot[bot] Jan 2, 2024
488c335
Bump actions/download-artifact from 3 to 4 (#7352)
dependabot[bot] Jan 2, 2024
41abb20
Bump peter-evans/slash-command-dispatch from 3.0.1 to 3.0.2 (#7353)
dependabot[bot] Jan 3, 2024
5ce1b60
Give more useful exception when batch is considered during matrix mul…
KumoLiu Jan 8, 2024
64577f9
Fix incorrectly size compute in auto3dseg analyzer (#7374)
KumoLiu Jan 9, 2024
ea0e89b
7380 mention demo in bending energy and diffusion docstrings (#7381)
kvttt Jan 10, 2024
fff5cdd
Pin gdown version to v4.6.3 (#7384)
KumoLiu Jan 12, 2024
6556f88
Track applied operations in image filter (#7395)
vlaminckaxel Jan 18, 2024
ef912c8
Add `compile` support in `SupervisedTrainer` and `SupervisedEvaluator…
KumoLiu Jan 19, 2024
21f9ae1
Fix CUDA_VISIBLE_DEVICES setting ignored (#7408)
KumoLiu Jan 22, 2024
56212b9
Fix Incorrect updated affine in `NrrdReader` and update docstring in …
KumoLiu Jan 25, 2024
4a9d10b
Ignore E704 after update black (#7422)
KumoLiu Jan 30, 2024
6faf4b2
new formatting
marksgraham Jan 30, 2024
b01b372
Merge branch 'gen-ai-dev' into 6676_port_generative_engines
marksgraham Jan 30, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/chatops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: dispatch
uses: peter-evans/slash-command-dispatch@v3.0.1
uses: peter-evans/slash-command-dispatch@v3.0.2
with:
token: ${{ secrets.PR_MAINTAIN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -72,4 +72,4 @@ jobs:
BUILD_MONAI=1 ./runtests.sh --build

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 1 addition & 1 deletion .github/workflows/cron-ngc-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: cache weekly timestamp
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
ref: dev
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'
- shell: bash
Expand All @@ -36,7 +36,7 @@ jobs:
python setup.py build
cat build/lib/monai/_version.py
- name: Upload version
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: _version.py
path: build/lib/monai/_version.py
Expand All @@ -56,7 +56,7 @@ jobs:
with:
ref: dev
- name: Download version
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: _version.py
- name: docker_build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pythonapp-min.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Prepare pip wheel
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Prepare pip wheel
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Prepare pip wheel
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: cache weekly timestamp
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
disk-root: "D:"
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Prepare pip wheel
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: cache weekly timestamp
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: cache weekly timestamp
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install setuptools
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:

- if: matrix.python-version == '3.9' && startsWith(github.ref, 'refs/tags/')
name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'
- shell: bash
Expand All @@ -108,7 +108,7 @@ jobs:
python setup.py build
cat build/lib/monai/_version.py
- name: Upload version
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: _version.py
path: build/lib/monai/_version.py
Expand All @@ -125,7 +125,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Download version
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: _version.py
- name: Set tag
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/setupapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: cache weekly timestamp
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: cache weekly timestamp
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/weekly-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
ref: dev
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install setuptools
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sphinxcontrib-serializinghtml
sphinx-autodoc-typehints==1.11.1
pandas
einops
transformers<4.22 # https://github.com/Project-MONAI/MONAI/issues/5157
transformers<4.22; python_version <= '3.10' # https://github.com/Project-MONAI/MONAI/issues/5157
mlflow>=1.28.0
clearml>=1.10.0rc0
tensorboardX
Expand Down
5 changes: 5 additions & 0 deletions docs/source/engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Workflows
.. autoclass:: GanTrainer
:members:

`AdversarialTrainer`
~~~~~~~~~~~~~~~~~~~~
.. autoclass:: AdversarialTrainer
:members:

`Evaluator`
~~~~~~~~~~~
.. autoclass:: Evaluator
Expand Down
5 changes: 5 additions & 0 deletions docs/source/losses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ Registration Losses
.. autoclass:: BendingEnergyLoss
:members:

`DiffusionLoss`
~~~~~~~~~~~~~~~
.. autoclass:: DiffusionLoss
:members:

`LocalNormalizedCrossCorrelationLoss`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: LocalNormalizedCrossCorrelationLoss
Expand Down
26 changes: 16 additions & 10 deletions monai/apps/auto3dseg/data_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from monai.data import DataLoader, Dataset, partition_dataset
from monai.data.utils import no_collation
from monai.transforms import Compose, EnsureTyped, LoadImaged, Orientationd
from monai.utils import StrEnum, min_version, optional_import
from monai.utils import ImageMetaKey, StrEnum, min_version, optional_import
from monai.utils.enums import DataStatsKeys, ImageStatsKeys


Expand Down Expand Up @@ -343,19 +343,25 @@ def _get_all_case_stats(
d = summarizer(batch_data)
except BaseException as err:
if "image_meta_dict" in batch_data.keys():
filename = batch_data["image_meta_dict"]["filename_or_obj"]
filename = batch_data["image_meta_dict"][ImageMetaKey.FILENAME_OR_OBJ]
else:
filename = batch_data[self.image_key].meta["filename_or_obj"]
filename = batch_data[self.image_key].meta[ImageMetaKey.FILENAME_OR_OBJ]
logger.info(f"Unable to process data {filename} on {device}. {err}")
if self.device.type == "cuda":
logger.info("DataAnalyzer `device` set to GPU execution hit an exception. Falling back to `cpu`.")
batch_data[self.image_key] = batch_data[self.image_key].to("cpu")
if self.label_key is not None:
label = batch_data[self.label_key]
if not _label_argmax:
label = torch.argmax(label, dim=0) if label.shape[0] > 1 else label[0]
batch_data[self.label_key] = label.to("cpu")
d = summarizer(batch_data)
try:
batch_data[self.image_key] = batch_data[self.image_key].to("cpu")
if self.label_key is not None:
label = batch_data[self.label_key]
if not _label_argmax:
label = torch.argmax(label, dim=0) if label.shape[0] > 1 else label[0]
batch_data[self.label_key] = label.to("cpu")
d = summarizer(batch_data)
except BaseException as err:
logger.info(f"Unable to process data {filename} on {device}. {err}")
continue
else:
continue

stats_by_cases = {
DataStatsKeys.BY_CASE_IMAGE_PATH: d[DataStatsKeys.BY_CASE_IMAGE_PATH],
Expand Down
8 changes: 6 additions & 2 deletions monai/apps/detection/utils/anchor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ class AnchorGeneratorWithAnchorShape(AnchorGenerator):
def __init__(
self,
feature_map_scales: Sequence[int] | Sequence[float] = (1, 2, 4, 8),
base_anchor_shapes: Sequence[Sequence[int]]
| Sequence[Sequence[float]] = ((32, 32, 32), (48, 20, 20), (20, 48, 20), (20, 20, 48)),
base_anchor_shapes: Sequence[Sequence[int]] | Sequence[Sequence[float]] = (
(32, 32, 32),
(48, 20, 20),
(20, 48, 20),
(20, 20, 48),
),
indexing: str = "ij",
) -> None:
nn.Module.__init__(self)
Expand Down
2 changes: 1 addition & 1 deletion monai/apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from monai.config.type_definitions import PathLike
from monai.utils import look_up_option, min_version, optional_import

gdown, has_gdown = optional_import("gdown", "4.4")
gdown, has_gdown = optional_import("gdown", "4.6.3")

if TYPE_CHECKING:
from tqdm import tqdm
Expand Down
4 changes: 2 additions & 2 deletions monai/auto3dseg/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __call__(self, data):
)

report[ImageStatsKeys.SIZEMM] = [
int(a * b) for a, b in zip(report[ImageStatsKeys.SHAPE][0], report[ImageStatsKeys.SPACING])
a * b for a, b in zip(report[ImageStatsKeys.SHAPE][0], report[ImageStatsKeys.SPACING])
]

report[ImageStatsKeys.INTENSITY] = [
Expand Down Expand Up @@ -460,7 +460,7 @@ def __call__(self, data: Mapping[Hashable, MetaTensor]) -> dict[Hashable, MetaTe
torch.set_grad_enabled(False)

ndas: list[MetaTensor] = [d[self.image_key][i] for i in range(d[self.image_key].shape[0])] # type: ignore
ndas_label: MetaTensor = d[self.label_key] # (H,W,D)
ndas_label: MetaTensor = d[self.label_key].astype(torch.int8) # (H,W,D)

if ndas_label.shape != ndas[0].shape:
raise ValueError(f"Label shape {ndas_label.shape} is different from image shape {ndas[0].shape}")
Expand Down
6 changes: 2 additions & 4 deletions monai/data/decathlon_datalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@


@overload
def _compute_path(base_dir: PathLike, element: PathLike, check_path: bool = False) -> str:
...
def _compute_path(base_dir: PathLike, element: PathLike, check_path: bool = False) -> str: ...


@overload
def _compute_path(base_dir: PathLike, element: list[PathLike], check_path: bool = False) -> list[str]:
...
def _compute_path(base_dir: PathLike, element: list[PathLike], check_path: bool = False) -> list[str]: ...


def _compute_path(base_dir, element, check_path=False):
Expand Down
12 changes: 6 additions & 6 deletions monai/data/image_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class ITKReader(ImageReader):
series_name: the name of the DICOM series if there are multiple ones.
used when loading DICOM series.
reverse_indexing: whether to use a reversed spatial indexing convention for the returned data array.
If ``False``, the spatial indexing follows the numpy convention;
otherwise, the spatial indexing convention is reversed to be compatible with ITK. Default is ``False``.
If ``False``, the spatial indexing convention is reversed to be compatible with ITK;
otherwise, the spatial indexing follows the numpy convention. Default is ``False``.
This option does not affect the metadata.
series_meta: whether to load the metadata of the DICOM series (using the metadata from the first slice).
This flag is checked only when loading DICOM series. Default is ``False``.
Expand Down Expand Up @@ -1323,7 +1323,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:
header = dict(i.header)
if self.index_order == "C":
header = self._convert_f_to_c_order(header)
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(i)
header[MetaKeys.ORIGINAL_AFFINE] = self._get_affine(header)

if self.affine_lps_to_ras:
header = self._switch_lps_ras(header)
Expand All @@ -1344,7 +1344,7 @@ def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:

return _stack_images(img_array, compatible_meta), compatible_meta

def _get_affine(self, img: NrrdImage) -> np.ndarray:
def _get_affine(self, header: dict) -> np.ndarray:
"""
Get the affine matrix of the image, it can be used to correct
spacing, orientation or execute spatial transforms.
Expand All @@ -1353,8 +1353,8 @@ def _get_affine(self, img: NrrdImage) -> np.ndarray:
img: A `NrrdImage` loaded from image file

"""
direction = img.header["space directions"]
origin = img.header["space origin"]
direction = header["space directions"]
origin = header["space origin"]

x, y = direction.shape
affine_diam = min(x, y) + 1
Expand Down
4 changes: 3 additions & 1 deletion monai/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
from __future__ import annotations

from .evaluator import EnsembleEvaluator, Evaluator, SupervisedEvaluator
from .trainer import GanTrainer, SupervisedTrainer, Trainer
from .trainer import AdversarialTrainer, GanTrainer, SupervisedTrainer, Trainer
from .utils import (
DiffusionPrepareBatch,
IterationEvents,
PrepareBatch,
PrepareBatchDefault,
PrepareBatchExtraInput,
VPredictionPrepareBatch,
default_make_latent,
default_metric_cmp_fn,
default_prepare_batch,
Expand Down
Loading
Loading