-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor MAISI bundle to monai 1.4 (#634)
Fixes # . ### Description refactor to monai1.4, add quality check, correct typo add download script ### 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. - [ ] 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 <[email protected]> Signed-off-by: Yiheng Wang <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yiheng Wang <[email protected]> Co-authored-by: Yiheng Wang <[email protected]>
- Loading branch information
1 parent
19f45ee
commit 2c5d564
Showing
17 changed files
with
1,242 additions
and
3,606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
models/maisi_ct_generative/configs/image_median_statistics.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"liver": { | ||
"min_median": -14.0, | ||
"max_median": 1000.0, | ||
"percentile_0_5": 9.530000000000001, | ||
"percentile_99_5": 162.0, | ||
"sigma_6_low": -21.596463547885904, | ||
"sigma_6_high": 156.27881534763367, | ||
"sigma_12_low": -110.53410299564568, | ||
"sigma_12_high": 245.21645479539342 | ||
}, | ||
"spleen": { | ||
"min_median": -69.0, | ||
"max_median": 1000.0, | ||
"percentile_0_5": 16.925000000000004, | ||
"percentile_99_5": 184.07500000000073, | ||
"sigma_6_low": -43.133891656525165, | ||
"sigma_6_high": 177.40494997185993, | ||
"sigma_12_low": -153.4033124707177, | ||
"sigma_12_high": 287.6743707860525 | ||
}, | ||
"pancreas": { | ||
"min_median": -124.0, | ||
"max_median": 1000.0, | ||
"percentile_0_5": -29.0, | ||
"percentile_99_5": 145.92000000000007, | ||
"sigma_6_low": -56.59382515620725, | ||
"sigma_6_high": 149.50627399318438, | ||
"sigma_12_low": -159.64387473090306, | ||
"sigma_12_high": 252.5563235678802 | ||
}, | ||
"kidney": { | ||
"min_median": -165.5, | ||
"max_median": 819.0, | ||
"percentile_0_5": -40.0, | ||
"percentile_99_5": 254.61999999999898, | ||
"sigma_6_low": -130.56375604853028, | ||
"sigma_6_high": 267.28163511081016, | ||
"sigma_12_low": -329.4864516282005, | ||
"sigma_12_high": 466.20433069048045 | ||
}, | ||
"lung": { | ||
"min_median": -1000.0, | ||
"max_median": 65.0, | ||
"percentile_0_5": -937.0, | ||
"percentile_99_5": -366.9500000000007, | ||
"sigma_6_low": -1088.5583843889117, | ||
"sigma_6_high": -551.8503346949108, | ||
"sigma_12_low": -1356.912409235912, | ||
"sigma_12_high": -283.4963098479103 | ||
}, | ||
"bone": { | ||
"min_median": 77.5, | ||
"max_median": 1000.0, | ||
"percentile_0_5": 136.45499999999998, | ||
"percentile_99_5": 551.6350000000002, | ||
"sigma_6_low": 71.39901958080469, | ||
"sigma_6_high": 471.9957615639765, | ||
"sigma_12_low": -128.8993514107812, | ||
"sigma_12_high": 672.2941325555623 | ||
}, | ||
"brain": { | ||
"min_median": -1000.0, | ||
"max_median": 238.0, | ||
"percentile_0_5": -951.0, | ||
"percentile_99_5": 126.25, | ||
"sigma_6_low": -304.8208236135867, | ||
"sigma_6_high": 369.5118535139189, | ||
"sigma_12_low": -641.9871621773394, | ||
"sigma_12_high": 706.6781920776717 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
"all_anatomy_size_condtions_json": "$@bundle_root + '/configs/all_anatomy_size_condtions.json'", | ||
"label_dict_json": "$@bundle_root + '/configs/label_dict.json'", | ||
"label_dict_remap_json": "$@bundle_root + '/configs/label_dict_124_to_132.json'", | ||
"quality_check_args": null, | ||
"real_img_median_statistics_file": "$@bundle_root + '/configs/image_median_statistics.json'", | ||
"num_output_samples": 1, | ||
"body_region": [ | ||
"abdomen" | ||
|
@@ -62,8 +62,14 @@ | |
64, | ||
64 | ||
], | ||
"autoencoder_sliding_window_infer_size": [ | ||
96, | ||
96, | ||
96 | ||
], | ||
"autoencoder_sliding_window_infer_overlap": 0.6667, | ||
"autoencoder_def": { | ||
"_target_": "scripts.custom_network_tp.AutoencoderKlckModifiedTp", | ||
"_target_": "monai.apps.generation.maisi.networks.autoencoderkl_maisi.AutoencoderKlMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@image_channels", | ||
"out_channels": "@image_channels", | ||
|
@@ -88,10 +94,13 @@ | |
"with_encoder_nonlocal_attn": false, | ||
"with_decoder_nonlocal_attn": false, | ||
"use_checkpointing": false, | ||
"use_convtranspose": false | ||
"use_convtranspose": false, | ||
"norm_float16": true, | ||
"num_splits": 8, | ||
"dim_split": 1 | ||
}, | ||
"difusion_unet_def": { | ||
"_target_": "scripts.custom_network_diffusion.CustomDiffusionModelUNet", | ||
"diffusion_unet_def": { | ||
"_target_": "monai.apps.generation.maisi.networks.diffusion_model_unet_maisi.DiffusionModelUNetMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@latent_channels", | ||
"out_channels": "@latent_channels", | ||
|
@@ -115,12 +124,12 @@ | |
], | ||
"num_res_blocks": 2, | ||
"use_flash_attention": true, | ||
"input_top_region_index": true, | ||
"input_bottom_region_index": true, | ||
"input_spacing": true | ||
"include_top_region_index_input": true, | ||
"include_bottom_region_index_input": true, | ||
"include_spacing_input": true | ||
}, | ||
"controlnet_def": { | ||
"_target_": "scripts.custom_network_controlnet.CustomControlNet", | ||
"_target_": "monai.apps.generation.maisi.networks.controlnet_maisi.ControlNetMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@latent_channels", | ||
"num_channels": [ | ||
|
@@ -151,11 +160,11 @@ | |
] | ||
}, | ||
"mask_generation_autoencoder_def": { | ||
"_target_": "generative.networks.nets.AutoencoderKL", | ||
"spatial_dims": 3, | ||
"_target_": "monai.apps.generation.maisi.networks.autoencoderkl_maisi.AutoencoderKlMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": 8, | ||
"out_channels": 125, | ||
"latent_channels": 4, | ||
"latent_channels": "@latent_channels", | ||
"num_channels": [ | ||
32, | ||
64, | ||
|
@@ -177,14 +186,17 @@ | |
"with_decoder_nonlocal_attn": false, | ||
"use_flash_attention": false, | ||
"use_checkpointing": true, | ||
"use_convtranspose": true | ||
"use_convtranspose": true, | ||
"norm_float16": true, | ||
"num_splits": 8, | ||
"dim_split": 1 | ||
}, | ||
"mask_generation_diffusion_def": { | ||
"_target_": "generative.networks.nets.DiffusionModelUNet", | ||
"spatial_dims": 3, | ||
"in_channels": 4, | ||
"out_channels": 4, | ||
"num_channels": [ | ||
"_target_": "monai.networks.nets.diffusion_model_unet.DiffusionModelUNet", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@latent_channels", | ||
"out_channels": "@latent_channels", | ||
"channels": [ | ||
64, | ||
128, | ||
256, | ||
|
@@ -209,33 +221,33 @@ | |
"cross_attention_dim": 10 | ||
}, | ||
"autoencoder": "$@autoencoder_def.to(@device)", | ||
"checkpoint_autoencoder": "$scripts.utils.load_autoencoder_ckpt(@trained_autoencoder_path)", | ||
"checkpoint_autoencoder": "$torch.load(@trained_autoencoder_path)", | ||
"load_autoencoder": "[email protected]_state_dict(@checkpoint_autoencoder)", | ||
"difusion_unet": "$@difusion_unet_def.to(@device)", | ||
"checkpoint_difusion_unet": "$torch.load(@trained_diffusion_path)", | ||
"load_diffusion": "$@difusion_unet.load_state_dict(@checkpoint_difusion_unet['unet_state_dict'])", | ||
"diffusion_unet": "$@diffusion_unet_def.to(@device)", | ||
"checkpoint_diffusion_unet": "$torch.load(@trained_diffusion_path)", | ||
"load_diffusion": "$@diffusion_unet.load_state_dict(@checkpoint_diffusion_unet['unet_state_dict'])", | ||
"controlnet": "$@controlnet_def.to(@device)", | ||
"copy_controlnet_state": "$monai.networks.utils.copy_model_state(@controlnet, @difusion_unet.state_dict())", | ||
"copy_controlnet_state": "$monai.networks.utils.copy_model_state(@controlnet, @diffusion_unet.state_dict())", | ||
"checkpoint_controlnet": "$torch.load(@trained_controlnet_path)", | ||
"load_controlnet": "[email protected]_state_dict(@checkpoint_controlnet['controlnet_state_dict'], strict=True)", | ||
"scale_factor": "$@checkpoint_difusion_unet['scale_factor'].to(@device)", | ||
"scale_factor": "$@checkpoint_diffusion_unet['scale_factor'].to(@device)", | ||
"mask_generation_autoencoder": "$@mask_generation_autoencoder_def.to(@device)", | ||
"checkpoint_mask_generation_autoencoder": "$torch.load(@trained_mask_generation_autoencoder_path)", | ||
"load_mask_generation_autoencoder": "$@mask_generation_autoencoder.load_state_dict(@checkpoint_mask_generation_autoencoder, strict=True)", | ||
"mask_generation_difusion_unet": "$@mask_generation_diffusion_def.to(@device)", | ||
"checkpoint_mask_generation_difusion_unet": "$torch.load(@trained_mask_generation_diffusion_path)", | ||
"load_mask_generation_diffusion": "$@mask_generation_difusion_unet.load_state_dict(@checkpoint_mask_generation_difusion_unet, strict=True)", | ||
"mask_generation_scale_factor": 1.0055984258651733, | ||
"mask_generation_diffusion_unet": "$@mask_generation_diffusion_def.to(@device)", | ||
"checkpoint_mask_generation_diffusion_unet": "$torch.load(@trained_mask_generation_diffusion_path)", | ||
"load_mask_generation_diffusion": "$@mask_generation_diffusion_unet.load_state_dict(@checkpoint_mask_generation_diffusion_unet['unet_state_dict'], strict=True)", | ||
"mask_generation_scale_factor": "$@checkpoint_mask_generation_diffusion_unet['scale_factor']", | ||
"noise_scheduler": { | ||
"_target_": "generative.networks.schedulers.DDPMScheduler", | ||
"_target_": "monai.networks.schedulers.ddpm.DDPMScheduler", | ||
"num_train_timesteps": 1000, | ||
"beta_start": 0.0015, | ||
"beta_end": 0.0195, | ||
"schedule": "scaled_linear_beta", | ||
"clip_sample": false | ||
}, | ||
"mask_generation_noise_scheduler": { | ||
"_target_": "generative.networks.schedulers.DDPMScheduler", | ||
"_target_": "monai.networks.schedulers.ddpm.DDPMScheduler", | ||
"num_train_timesteps": 1000, | ||
"beta_start": 0.0015, | ||
"beta_end": 0.0195, | ||
|
@@ -263,27 +275,29 @@ | |
"label_dict_json": "@label_dict_json", | ||
"label_dict_remap_json": "@label_dict_remap_json", | ||
"autoencoder": "@autoencoder", | ||
"difusion_unet": "@difusion_unet", | ||
"diffusion_unet": "@diffusion_unet", | ||
"controlnet": "@controlnet", | ||
"scale_factor": "@scale_factor", | ||
"noise_scheduler": "@noise_scheduler", | ||
"mask_generation_autoencoder": "@mask_generation_autoencoder", | ||
"mask_generation_difusion_unet": "@mask_generation_difusion_unet", | ||
"mask_generation_diffusion_unet": "@mask_generation_diffusion_unet", | ||
"mask_generation_scale_factor": "@mask_generation_scale_factor", | ||
"mask_generation_noise_scheduler": "@mask_generation_noise_scheduler", | ||
"controllable_anatomy_size": "@controllable_anatomy_size", | ||
"image_output_ext": "@image_output_ext", | ||
"label_output_ext": "@label_output_ext", | ||
"real_img_median_statistics": "@real_img_median_statistics_file", | ||
"device": "@device", | ||
"latent_shape": "@latent_shape", | ||
"mask_generation_latent_shape": "@mask_generation_latent_shape", | ||
"output_size": "@output_size", | ||
"quality_check_args": "@quality_check_args", | ||
"spacing": "@spacing", | ||
"output_dir": "@output_dir", | ||
"num_inference_steps": "@num_inference_steps", | ||
"mask_generation_num_inference_steps": "@mask_generation_num_inference_steps", | ||
"random_seed": "@random_seed" | ||
"random_seed": "@random_seed", | ||
"autoencoder_sliding_window_infer_size": "@autoencoder_sliding_window_infer_size", | ||
"autoencoder_sliding_window_infer_overlap": "@autoencoder_sliding_window_infer_overlap" | ||
}, | ||
"run": [ | ||
"$@ldm_sampler.sample_multiple_images(@num_output_samples)" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ | |
"spatial_dims": 3, | ||
"image_channels": 1, | ||
"latent_channels": 4, | ||
"difusion_unet_def": { | ||
"_target_": "scripts.custom_network_diffusion.CustomDiffusionModelUNet", | ||
"diffusion_unet_def": { | ||
"_target_": "monai.apps.generation.maisi.networks.diffusion_model_unet_maisi.DiffusionModelUNetMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@latent_channels", | ||
"out_channels": "@latent_channels", | ||
|
@@ -53,12 +53,12 @@ | |
], | ||
"num_res_blocks": 2, | ||
"use_flash_attention": true, | ||
"input_top_region_index": true, | ||
"input_bottom_region_index": true, | ||
"input_spacing": true | ||
"include_top_region_index_input": true, | ||
"include_bottom_region_index_input": true, | ||
"include_spacing_input": true | ||
}, | ||
"controlnet_def": { | ||
"_target_": "scripts.custom_network_controlnet.CustomControlNet", | ||
"_target_": "monai.apps.generation.maisi.networks.controlnet_maisi.ControlNetMaisi", | ||
"spatial_dims": "@spatial_dims", | ||
"in_channels": "@latent_channels", | ||
"num_channels": [ | ||
|
@@ -89,19 +89,19 @@ | |
] | ||
}, | ||
"noise_scheduler": { | ||
"_target_": "generative.networks.schedulers.DDPMScheduler", | ||
"_target_": "monai.networks.schedulers.ddpm.DDPMScheduler", | ||
"num_train_timesteps": 1000, | ||
"beta_start": 0.0015, | ||
"beta_end": 0.0195, | ||
"schedule": "scaled_linear_beta", | ||
"clip_sample": false | ||
}, | ||
"unzip_dataset": "scripts.utils.unzip_dataset(@dataset_dir)", | ||
"difusion_unet": "$@difusion_unet_def.to(@device)", | ||
"checkpoint_difusion_unet": "$torch.load(@trained_diffusion_path)", | ||
"load_diffusion": "$@difusion_unet.load_state_dict(@checkpoint_difusion_unet['unet_state_dict'])", | ||
"unzip_dataset": "$scripts.utils.unzip_dataset(@dataset_dir)", | ||
"diffusion_unet": "$@diffusion_unet_def.to(@device)", | ||
"checkpoint_diffusion_unet": "$torch.load(@trained_diffusion_path)", | ||
"load_diffusion": "$@diffusion_unet.load_state_dict(@checkpoint_diffusion_unet['unet_state_dict'])", | ||
"controlnet": "$@controlnet_def.to(@device)", | ||
"copy_controlnet_state": "$monai.networks.utils.copy_model_state(@controlnet, @difusion_unet.state_dict())", | ||
"copy_controlnet_state": "$monai.networks.utils.copy_model_state(@controlnet, @diffusion_unet.state_dict())", | ||
"checkpoint_controlnet": "$torch.load(@trained_controlnet_path)", | ||
"load_controlnet": "[email protected]_state_dict(@checkpoint_controlnet['controlnet_state_dict'], strict=True)", | ||
"scale_factor": "$@checkpoint_controlnet['scale_factor'].to(@device)", | ||
|
@@ -244,7 +244,7 @@ | |
"max_epochs": "@epochs", | ||
"device": "@device", | ||
"train_data_loader": "@train#dataloader", | ||
"difusion_unet": "@difusion_unet", | ||
"diffusion_unet": "@diffusion_unet", | ||
"controlnet": "@controlnet", | ||
"noise_scheduler": "@noise_scheduler", | ||
"loss_function": "@loss", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.