Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:heyufan1995/model-zoo into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
heyufan1995 committed Oct 9, 2024
2 parents 4988add + 291f45e commit 5e66231
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 42 deletions.
1 change: 0 additions & 1 deletion ci/unit_tests/test_vista3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def test_eval_config(self, override):
os.path.join(bundle_root, "configs/train.json"),
os.path.join(bundle_root, "configs/train_continual.json"),
os.path.join(bundle_root, "configs/evaluate.json"),
os.path.join(bundle_root, "configs/data.yaml"),
]
trainer = ConfigWorkflow(
workflow_type="train",
Expand Down
1 change: 0 additions & 1 deletion ci/unit_tests/test_vista3d_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def test_eval_mgpu_config(self, override):
os.path.join(bundle_root, "configs/train_continual.json"),
os.path.join(bundle_root, "configs/evaluate.json"),
os.path.join(bundle_root, "configs/mgpu_evaluate.json"),
os.path.join(bundle_root, "configs/data.yaml"),
]
output_path = os.path.join(bundle_root, "configs/evaluate_override.json")
n_gpu = torch.cuda.device_count()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "1.1.1",
"version": "1.1.2",
"changelog": {
"1.1.2": "update issue for IgniteInfo",
"1.1.1": "enable tensorrt",
"1.1.0": "update to use monai 1.4, model ckpt not changed, rm GenerativeAI repo",
"1.0.9": "update to use monai 1.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence

import torch
from monai.config import IgniteInfo
from monai.engines.utils import IterationEvents, default_metric_cmp_fn, default_prepare_batch
from monai.inferers import Inferer, SimpleInferer
from monai.transforms import Transform
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys, GanKeys
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader
Expand Down
3 changes: 2 additions & 1 deletion models/brats_mri_generative_diffusion/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "1.1.1",
"version": "1.1.2",
"changelog": {
"1.1.2": "update issue for IgniteInfo",
"1.1.1": "enable tensorrt",
"1.1.0": "update to use monai 1.4, model ckpt not changed, rm GenerativeAI repo",
"1.0.9": "update to use monai 1.3.1",
Expand Down
3 changes: 1 addition & 2 deletions models/brats_mri_generative_diffusion/scripts/ldm_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence

import torch
from monai.config import IgniteInfo
from monai.engines.utils import IterationEvents, default_metric_cmp_fn, default_prepare_batch
from monai.inferers import Inferer, SimpleInferer
from monai.transforms import Transform
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys, GanKeys
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader
Expand Down
3 changes: 2 additions & 1 deletion models/lung_nodule_ct_detection/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.6.7",
"version": "0.6.8",
"changelog": {
"0.6.8": "update issue for IgniteInfo",
"0.6.7": "use monai 1.4 and update large files",
"0.6.6": "update to use monai 1.3.1",
"0.6.5": "remove notes for trt_export in readme",
Expand Down
3 changes: 1 addition & 2 deletions models/lung_nodule_ct_detection/scripts/detection_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import warnings
from typing import TYPE_CHECKING, Callable, Optional

from monai.config import IgniteInfo
from monai.handlers.classification_saver import ClassificationSaver
from monai.utils import evenly_divisible_all_gather, min_version, optional_import, string_list_all_gather
from monai.utils import IgniteInfo, evenly_divisible_all_gather, min_version, optional_import, string_list_all_gather

from .utils import detach_to_numpy

Expand Down
3 changes: 1 addition & 2 deletions models/lung_nodule_ct_detection/scripts/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

import torch
from monai.apps.detection.networks.retinanet_detector import RetinaNetDetector
from monai.config import IgniteInfo
from monai.engines.evaluator import SupervisedEvaluator
from monai.engines.utils import IterationEvents, default_metric_cmp_fn
from monai.transforms import Transform
from monai.utils import ForwardMode, min_version, optional_import
from monai.utils import ForwardMode, IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys as Keys
from torch.utils.data import DataLoader

Expand Down
3 changes: 1 addition & 2 deletions models/lung_nodule_ct_detection/scripts/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union

import torch
from monai.config import IgniteInfo
from monai.engines.trainer import Trainer
from monai.engines.utils import IterationEvents, default_metric_cmp_fn
from monai.inferers import Inferer
from monai.transforms import Transform
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import
from monai.utils.enums import CommonKeys as Keys
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader
Expand Down
4 changes: 3 additions & 1 deletion models/maisi_ct_generative/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_generator_ldm_20240318.json",
"version": "0.4.3",
"version": "0.4.5",
"changelog": {
"0.4.5": "update README",
"0.4.4": "update issue for IgniteInfo",
"0.4.3": "remove download large files, add weights_only when loading weights and add label_dict to large files",
"0.4.2": "update train.json to fix finetune ckpt bug",
"0.4.1": "update large files",
Expand Down
24 changes: 24 additions & 0 deletions models/maisi_ct_generative/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ The inference requires:
- GPU: at least 58GB GPU memory for 512 x 512 x 512
- Disk Memory: at least 21GB disk memory

#### Inference parameters:
The information for the inference input, like body region and anatomy to generate, is stored in [./configs/inference.json](../configs/inference.json). Please feel free to play with it. Here are the details of the parameters.

- `"num_output_samples"`: int, the number of output image/mask pairs it will generate.
- `"spacing"`: voxel size of generated images. E.g., if set to `[1.5, 1.5, 2.0]`, it will generate images with a resolution of 1.5×1.5×2.0 mm. The spacing for x and y axes has to be between 0.5 and 3.0 mm and the spacing for the z axis has to be between 0.5 and 5.0 mm.
- `"output_size"`: volume size of generated images. E.g., if set to `[512, 512, 256]`, it will generate images with size of 512×512×256. They need to be divisible by 16. If you have a small GPU memory size, you should adjust it to small numbers. Note that `"spacing"` and `"output_size"` together decide the output field of view (FOV). For eample, if set them to `[1.5, 1.5, 2.0]`mm and `[512, 512, 256]`, the FOV is 768×768×512 mm. We recommend output_size is the FOV in x and y axis are same and to be at least 256mm for head, and at least 384mm for other body regions like abdomen. The output size for the x and y axes can be selected from [256, 384, 512], while for the z axis, it can be chosen from [128, 256, 384, 512, 640, 768].
- `"controllable_anatomy_size"`: a list of controllable anatomy and its size scale (0--1). E.g., if set to `[["liver", 0.5],["hepatic tumor", 0.3]]`, the generated image will contain liver that have a median size, with size around 50% percentile, and hepatic tumor that is relatively small, with around 30% percentile. In addition, if the size scale is set to -1, it indicates that the organ does not exist or should be removed. The output will contain paired image and segmentation mask for the controllable anatomy.
The following organs support generation with a controllable size: ``["liver", "gallbladder", "stomach", "pancreas", "colon", "lung tumor", "bone lesion", "hepatic tumor", "colon cancer primaries", "pancreatic tumor"]``.
The raw output of the current mask generation model has a fixed size of $256^3$ voxels with a spacing of $1.5^3$ mm. If the "output_size" differs from this default, the generated masks will be resampled to the desired `"output_size"` and `"spacing"`. Note that resampling may degrade the quality of the generated masks and could trigger multiple inference attempts if the images fail to pass the [image quality check](../scripts/quality_check.py).
- `"body_region"`: If "controllable_anatomy_size" is not specified, "body_region" will be used to constrain the region of generated images. It needs to be chosen from "head", "chest", "thorax", "abdomen", "pelvis", "lower".
- `"anatomy_list"`: If "controllable_anatomy_size" is not specified, the output will contain paired image and segmentation mask for the anatomy in "./configs/label_dict.json".
- `"autoencoder_sliding_window_infer_size"`: in order to save GPU memory, we use sliding window inference when decoding latents to image when `"output_size"` is large. This is the patch size of the sliding window. Small value will reduce GPU memory but increase time cost. They need to be divisible by 16.
- `"autoencoder_sliding_window_infer_overlap"`: float between 0 and 1. Large value will reduce the stitching artifacts when stitching patches during sliding window inference, but increase time cost. If you do not observe seam lines in the generated image result, you can use a smaller value to save inference time.

To generate images with substantial dimensions, such as 512 × 512 × 512 or larger, using GPUs with 80GB of memory, it is advisable to configure the `"num_splits"` parameter in [the auto-encoder configuration](./configs/config_maisi.json#L11-L37) to 16. This adjustment is crucial to avoid out-of-memory issues during inference.

#### Recommended spacing for different output sizes:

|`"output_size"`| Recommended `"spacing"`|
|:-----:|:-----:|
[256, 256, 256] | [1.5, 1.5, 1.5] |
[512, 512, 128] | [0.8, 0.8, 2.5] |
[512, 512, 512] | [1.0, 1.0, 1.0] |

### Execute inference
The following code generates a synthetic image from a random sampled noise.
```
Expand Down
3 changes: 1 addition & 2 deletions models/maisi_ct_generative/scripts/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@

import torch
import torch.nn.functional as F
from monai.config import IgniteInfo
from monai.engines.trainer import Trainer
from monai.engines.utils import IterationEvents, PrepareBatchExtraInput, default_metric_cmp_fn
from monai.inferers import Inferer
from monai.networks.schedulers import Scheduler
from monai.transforms import Transform
from monai.utils import RankFilter, min_version, optional_import
from monai.utils import IgniteInfo, RankFilter, min_version, optional_import
from monai.utils.enums import CommonKeys as Keys
from torch.optim.optimizer import Optimizer
from torch.utils.data import DataLoader
Expand Down
40 changes: 40 additions & 0 deletions models/model_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1726,5 +1726,45 @@
"vista3d_v0.5.1": {
"checksum": "3a1d16b60a52889b0b04616156b104efcc261883",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/vista3d/versions/0.5.1/files/vista3d_v0.5.1.zip"
},
"vista3d_v0.5.2": {
"checksum": "f0388a3f75152f709dda1fd6b08a4c4d8d565358",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/vista3d/versions/0.5.2/files/vista3d_v0.5.2.zip"
},
"pathology_nuclei_classification_v0.2.0": {
"checksum": "f8dd21b3711fa5705a0796704a0a477257b98da1",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/pathology_nuclei_classification/versions/0.2.0/files/pathology_nuclei_classification_v0.2.0.zip"
},
"brats_mri_axial_slices_generative_diffusion_v1.1.2": {
"checksum": "d6a2ac63890fd43280ff01310771ef265df784fb",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/brats_mri_axial_slices_generative_diffusion/versions/1.1.2/files/brats_mri_axial_slices_generative_diffusion_v1.1.2.zip"
},
"pathology_nuclick_annotation_v0.2.1": {
"checksum": "7287d19869b834235e51c1f3e3cfc387a324c76b",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/pathology_nuclick_annotation/versions/0.2.1/files/pathology_nuclick_annotation_v0.2.1.zip"
},
"brats_mri_generative_diffusion_v1.1.2": {
"checksum": "47bc08d062f5cb12d2a5efeba102ccb24e4cef2c",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/brats_mri_generative_diffusion/versions/1.1.2/files/brats_mri_generative_diffusion_v1.1.2.zip"
},
"lung_nodule_ct_detection_v0.6.8": {
"checksum": "1abae7a9379861c477f7b189e0171cfcd71370b0",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/lung_nodule_ct_detection/versions/0.6.8/files/lung_nodule_ct_detection_v0.6.8.zip"
},
"maisi_ct_generative_v0.4.4": {
"checksum": "30aa9a9f53a15ea06b0cfdadbb6876afb072d809",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/maisi_ct_generative/versions/0.4.4/files/maisi_ct_generative_v0.4.4.zip"
},
"vista2d_v0.2.9": {
"checksum": "36d220ff31b3b96ab4ea79b7c56b04aa105b45c9",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/vista2d/versions/0.2.9/files/vista2d_v0.2.9.zip"
},
"maisi_ct_generative_v0.4.5": {
"checksum": "e8271089c14e7aec261cac30ffeec7e07bfa10ef",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/maisi_ct_generative/versions/0.4.5/files/maisi_ct_generative_v0.4.5.zip"
},
"pathology_tumor_detection_v0.6.1": {
"checksum": "e41d063673ee1bc925eccea772b2535676e5e6f0",
"source": "https://api.ngc.nvidia.com/v2/models/nvidia/monaihosting/pathology_tumor_detection/versions/0.6.1/files/pathology_tumor_detection_v0.6.1.zip"
}
}
3 changes: 2 additions & 1 deletion models/pathology_nuclei_classification/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.1.9",
"version": "0.2.0",
"changelog": {
"0.2.0": "update issue for IgniteInfo",
"0.1.9": "update tensorrt benchmark results",
"0.1.8": "enable tensorrt",
"0.1.7": "update to use monai 1.3.1",
Expand Down
3 changes: 1 addition & 2 deletions models/pathology_nuclei_classification/scripts/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import numpy as np
import torch
import torch.distributed
from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import
from sklearn.metrics import classification_report

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
Expand Down
3 changes: 2 additions & 1 deletion models/pathology_nuclick_annotation/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.2.0",
"version": "0.2.1",
"changelog": {
"0.2.1": "update issue for IgniteInfo",
"0.2.0": "use monai 1.4 and update large files",
"0.1.9": "update to use monai 1.3.1",
"0.1.8": "add load_pretrain flag for infer",
Expand Down
3 changes: 1 addition & 2 deletions models/pathology_nuclick_annotation/scripts/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import numpy as np
import torch
import torch.distributed
from monai.config import IgniteInfo
from monai.utils import min_version, optional_import
from monai.utils import IgniteInfo, min_version, optional_import

Events, _ = optional_import("ignite.engine", IgniteInfo.OPT_IMPORT_VERSION, min_version, "Events")
make_grid, _ = optional_import("torchvision.utils", name="make_grid")
Expand Down
3 changes: 2 additions & 1 deletion models/pathology_tumor_detection/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.6.0",
"version": "0.6.1",
"changelog": {
"0.6.1": "fix multi-gpu issue",
"0.6.0": "use monai 1.4 and update large files",
"0.5.9": "update to use monai 1.3.1",
"0.5.8": "update readme to add memory warning",
Expand Down
10 changes: 5 additions & 5 deletions models/pathology_tumor_detection/configs/train.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
]
},
"handlers": [
{
"_target_": "LrScheduleHandler",
"lr_scheduler": "@lr_scheduler",
"print_lr": true
},
{
"_target_": "ValidationHandler",
"validator": "@validate#evaluator",
Expand All @@ -207,11 +212,6 @@
"tag_name": "train_loss",
"output_transform": "$monai.handlers.from_engine(['loss'], first=True)"
},
{
"_target_": "LrScheduleHandler",
"lr_scheduler": "@lr_scheduler",
"print_lr": true
},
{
"_target_": "TensorBoardStatsHandler",
"log_dir": "@output_dir",
Expand Down
3 changes: 2 additions & 1 deletion models/vista2d/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "0.2.8",
"version": "0.2.9",
"changelog": {
"0.2.9": "fix unsupported data dtype in findContours",
"0.2.8": "remove relative path in readme",
"0.2.7": "enhance readme",
"0.2.6": "update tensorrt benchmark results",
Expand Down
1 change: 1 addition & 0 deletions models/vista2d/scripts/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def __call__(self, data):
cv2.imwrite(output_filepath, image)
logger.info(f"Overlay Masks: Saving {output_filepath}")
else:
label = cv2.convertScaleAbs(label, alpha=255.0 / label.max())
contours, _ = cv2.findContours(label, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
polygons.extend(self.to_polygons(contours))

Expand Down
7 changes: 5 additions & 2 deletions models/vista3d/configs/evaluate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
]
},
"label_set": "$list(x[1] for x in @label_mappings#default)",
"validate#evaluator#hyper_kwargs#val_head": "auto",
"validate#evaluator#hyper_kwargs#val_head": "auto",
"validate#preprocessing": {
"_target_": "Compose",
"transforms": [
Expand Down Expand Up @@ -128,7 +128,10 @@
},
{
"_target_": "monai.apps.vista3d.transforms.Relabeld",
"keys": ["pred", "label"],
"keys": [
"pred",
"label"
],
"label_mappings": "${'default': [[c, i+1] for i, c in enumerate(@label_set)]}",
"dtype": "$torch.uint8"
}
Expand Down
3 changes: 2 additions & 1 deletion models/vista3d/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "0.5.1",
"version": "0.5.2",
"changelog": {
"0.5.2": "fix eval issue",
"0.5.1": "add description for zero-shot and upate eval",
"0.5.0": "update json file link and add test",
"0.4.9": "fix oom issue and update readme",
Expand Down
Loading

0 comments on commit 5e66231

Please sign in to comment.