Skip to content

Commit

Permalink
Update brats_mri_axial_slices_generative_diffusion to monai1.4 (#621)
Browse files Browse the repository at this point in the history
Fixes # .

### Description
A few sentences describing the changes proposed in this pull request.

### Status
**Ready/Work in progress/Hold**

### Please ensure all the checkboxes:
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Codeformat tests passed locally by running `./runtests.sh
--codeformat`.
- [ ] In-line docstrings updated.
- [x] Update `version` and `changelog` in `metadata.json` if changing an
existing bundle.
- [ ] Please ensure the naming rules in config files meet our
requirements (please refer to: `CONTRIBUTING.md`).
- [ ] Ensure versions of packages such as `monai`, `pytorch` and `numpy`
are correct in `metadata.json`.
- [ ] Descriptions should be consistent with the content, such as
`eval_metrics` of the provided weights and TorchScript modules.
- [ ] Files larger than 25MB are excluded and replaced by providing
download links in `large_file.yml`.
- [ ] Avoid using path that contains personal information within config
files (such as use `/home/your_name/` for `"bundle_root"`).

---------

Signed-off-by: Can-Zhao <volcanofly@gmail.com>
Signed-off-by: Yiheng Wang <vennw@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Yiheng Wang <vennw@nvidia.com>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent ae1b883 commit 35b5db1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
64
],
"autoencoder_def": {
"_target_": "generative.networks.nets.AutoencoderKL",
"_target_": "monai.networks.nets.autoencoderkl.AutoencoderKL",
"spatial_dims": "@spatial_dims",
"in_channels": "@image_channels",
"out_channels": "@image_channels",
"latent_channels": "@latent_channels",
"num_channels": [
"channels": [
64,
128,
256
Expand All @@ -43,14 +43,15 @@
false
],
"with_encoder_nonlocal_attn": true,
"with_decoder_nonlocal_attn": true
"with_decoder_nonlocal_attn": true,
"include_fc": false
},
"network_def": {
"_target_": "generative.networks.nets.DiffusionModelUNet",
"_target_": "monai.networks.nets.diffusion_model_unet.DiffusionModelUNet",
"spatial_dims": "@spatial_dims",
"in_channels": "@latent_channels",
"out_channels": "@latent_channels",
"num_channels": [
"channels": [
32,
64,
128,
Expand All @@ -68,16 +69,18 @@
32,
32
],
"num_res_blocks": 2
"num_res_blocks": 2,
"include_fc": false,
"use_combined_linear": false
},
"load_autoencoder_path": "$@bundle_root + '/models/model_autoencoder.pt'",
"load_autoencoder": "$@autoencoder_def.load_state_dict(torch.load(@load_autoencoder_path))",
"load_autoencoder": "$@autoencoder_def.load_old_state_dict(torch.load(@load_autoencoder_path))",
"autoencoder": "$@autoencoder_def.to(@device)",
"load_diffusion_path": "$@model_dir + '/model.pt'",
"load_diffusion": "$@network_def.load_state_dict(torch.load(@load_diffusion_path))",
"load_diffusion": "$@network_def.load_old_state_dict(torch.load(@load_diffusion_path))",
"diffusion": "$@network_def.to(@device)",
"noise_scheduler": {
"_target_": "generative.networks.schedulers.DDIMScheduler",
"_target_": "monai.networks.schedulers.ddim.DDIMScheduler",
"_requires_": [
"@load_diffusion",
"@load_autoencoder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"infer_batch_size_img": 1,
"infer_batch_size_slice": 1,
"autoencoder_def": {
"_target_": "generative.networks.nets.AutoencoderKL",
"_target_": "monai.networks.nets.autoencoderkl.AutoencoderKL",
"spatial_dims": "@spatial_dims",
"in_channels": "@image_channels",
"out_channels": "@image_channels",
"latent_channels": "@latent_channels",
"num_channels": [
"channels": [
64,
128,
256
Expand All @@ -43,10 +43,11 @@
false
],
"with_encoder_nonlocal_attn": true,
"with_decoder_nonlocal_attn": true
"with_decoder_nonlocal_attn": true,
"include_fc": false
},
"load_autoencoder_path": "$@bundle_root + '/models/model_autoencoder.pt'",
"load_autoencoder": "$@autoencoder_def.load_state_dict(torch.load(@load_autoencoder_path))",
"load_autoencoder": "$@autoencoder_def.load_old_state_dict(torch.load(@load_autoencoder_path))",
"autoencoder": "$@autoencoder_def.to(@device)",
"preprocessing_transforms": [
{
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_generator_ldm_20230507.json",
"version": "1.0.9",
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json",
"version": "1.0.10",
"changelog": {
"1.0.10": "update to use monai 1.4, model ckpt not changed, rm GenerativeAI repo",
"1.0.9": "update to use monai 1.3.1",
"1.0.8": "define arg for output file and put infer logic into a function",
"1.0.7": "update AddChanneld with EnsureChannelFirstd",
Expand All @@ -13,14 +14,14 @@
"1.0.1": "fix inference folder error",
"1.0.0": "Initial release"
},
"monai_version": "1.3.1",
"monai_version": "1.4.0",
"pytorch_version": "2.2.2",
"numpy_version": "1.24.4",
"optional_packages_version": {
"required_packages_version": {
"nibabel": "5.2.1",
"lpips": "0.1.4",
"monai-generative": "0.2.2"
"lpips": "0.1.4"
},
"supported_apps": {},
"name": "BraTS MRI axial slices latent diffusion generation",
"task": "BraTS MRI axial slices synthesis",
"description": "A generative model for creating 2D brain MRI axial slices from Gaussian noise based on BraTS dataset",
Expand Down Expand Up @@ -71,7 +72,7 @@
}
}
},
"generator_data_format": {
"network_data_format": {
"inputs": {
"latent": {
"type": "noise",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
"image_channels": 1,
"latent_channels": 1,
"discriminator_def": {
"_target_": "generative.networks.nets.PatchDiscriminator",
"_target_": "monai.networks.nets.patchgan_discriminator.PatchDiscriminator",
"spatial_dims": "@spatial_dims",
"num_layers_d": 3,
"num_channels": 32,
"channels": 32,
"in_channels": 1,
"out_channels": 1,
"norm": "INSTANCE"
},
"autoencoder_def": {
"_target_": "generative.networks.nets.AutoencoderKL",
"_target_": "monai.networks.nets.autoencoderkl.AutoencoderKL",
"spatial_dims": "@spatial_dims",
"in_channels": "@image_channels",
"out_channels": "@image_channels",
"latent_channels": "@latent_channels",
"num_channels": [
"channels": [
64,
128,
256
Expand All @@ -51,10 +51,11 @@
false
],
"with_encoder_nonlocal_attn": true,
"with_decoder_nonlocal_attn": true
"with_decoder_nonlocal_attn": true,
"include_fc": false
},
"perceptual_loss_def": {
"_target_": "generative.losses.PerceptualLoss",
"_target_": "monai.losses.perceptual.PerceptualLoss",
"spatial_dims": "@spatial_dims",
"network_type": "resnet50",
"pretrained": "@pretrained",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
64
],
"load_autoencoder_path": "$@bundle_root + '/models/model_autoencoder.pt'",
"load_autoencoder": "$@autoencoder_def.load_state_dict(torch.load(@load_autoencoder_path))",
"load_autoencoder": "$@autoencoder_def.load_old_state_dict(torch.load(@load_autoencoder_path))",
"autoencoder": "$@autoencoder_def.to(@device)",
"network_def": {
"_target_": "generative.networks.nets.DiffusionModelUNet",
"_target_": "monai.networks.nets.diffusion_model_unet.DiffusionModelUNet",
"spatial_dims": "@spatial_dims",
"in_channels": "@latent_channels",
"out_channels": "@latent_channels",
"num_channels": [
"channels": [
32,
64,
128,
Expand All @@ -38,7 +38,9 @@
32,
32
],
"num_res_blocks": 2
"num_res_blocks": 2,
"include_fc": false,
"use_combined_linear": false
},
"diffusion": "$@network_def.to(@device)",
"optimizer": {
Expand All @@ -56,7 +58,7 @@
},
"scale_factor": "$scripts.utils.compute_scale_factor(@autoencoder,@train#dataloader,@device)",
"noise_scheduler": {
"_target_": "generative.networks.schedulers.DDPMScheduler",
"_target_": "monai.networks.schedulers.ddpm.DDPMScheduler",
"_requires_": [
"@load_autoencoder"
],
Expand All @@ -70,7 +72,7 @@
},
"train": {
"inferer": {
"_target_": "generative.inferers.LatentDiffusionInferer",
"_target_": "monai.inferers.LatentDiffusionInferer",
"scheduler": "@noise_scheduler",
"scale_factor": "@scale_factor"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See the License for the specific language governing permissions and

import torch
from generative.losses import PatchAdversarialLoss
from monai.losses.adversarial_loss import PatchAdversarialLoss

intensity_loss = torch.nn.L1Loss()
adv_loss = PatchAdversarialLoss(criterion="least_squares")
Expand Down

0 comments on commit 35b5db1

Please sign in to comment.