-
Notifications
You must be signed in to change notification settings - Fork 740
Maisi readme #1743
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
Merged
Merged
Maisi readme #1743
Changes from 7 commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
c97509f
add readme
Can-Zhao 544ee06
add readme
Can-Zhao 033e614
add readme
Can-Zhao fce7a02
Merge branch 'main' into maisi_readme
Can-Zhao d315e0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1af6f91
correct typo
Can-Zhao 0f2a0e1
Merge branch 'maisi_readme' of https://github.com/Can-Zhao/tutorials …
Can-Zhao 8959b8b
add mri training data number
Can-Zhao cdc6ae7
add more details for inference
Can-Zhao aeb301e
Merge branch 'main' into maisi_readme
guopengf 31ffdf5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 58f637f
test commit
guopengf 9648aef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 03f905a
Merge branch 'main' into maisi_readme
Can-Zhao 87305e6
Merge branch 'main' into maisi_readme
Can-Zhao 3fea7e3
Merge branch 'main' into maisi_readme
guopengf 9e0c8df
update controlnet readme
guopengf 3f18e85
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bd030b7
Merge branch 'main' into maisi_readme
mingxin-zheng 6aee4ff
Merge branch 'main' into maisi_readme
Can-Zhao 3d94f1a
Merge branch 'Project-MONAI:main' into maisi_readme
Can-Zhao 7ebfba7
Merge branch 'Project-MONAI:main' into maisi_readme
Can-Zhao 7ea4767
Update readme for highlight, infer, and vae
Can-Zhao 746cfa8
Update readme for highlight, infer, and vae
Can-Zhao 914022c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b767492
Update readme for highlight, infer, and vae
Can-Zhao 73f2edc
Merge branch 'maisi_readme' of https://github.com/Can-Zhao/tutorials …
Can-Zhao 54bf9d8
update controlnet readme
guopengf 9aadd0f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cba35c0
update controlnet readme
guopengf 279f8ea
update vae readme, update vae botebook
Can-Zhao fc6e869
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 1b02466
Merge branch 'main' into maisi_readme
mingxin-zheng d1bdd4c
resolve conflict
Can-Zhao 383e0dd
Merge branch 'maisi_readme' of https://github.com/Can-Zhao/tutorials …
Can-Zhao 3c41b60
add description about ARM64
Can-Zhao 8d56497
add description about ARM64
Can-Zhao 880945d
add description about VAE data
Can-Zhao 1cd46e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] aa7b524
Merge branch 'main' into maisi_readme
guopengf 23090c2
update readme
guopengf ae3875b
Merge branch 'main' into maisi_readme
guopengf 8d3e4f6
add detail info on vae data
Can-Zhao 4deda70
add detail info on vae data
Can-Zhao 5de4aa9
typo
Can-Zhao a1aaba5
typo
Can-Zhao 994008b
update controlnet part
guopengf 028fe7f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 37a48a5
Update generative/maisi/data/README.md
guopengf 09c741e
Merge branch 'main' into maisi_readme
KumoLiu 43c8542
update
dongyang0122 861ab9f
update
dongyang0122 452210e
update
dongyang0122 4cdc0e1
update
dongyang0122 4a36743
update
dongyang0122 4f89f54
update
dongyang0122 c0a4355
update
dongyang0122 ce271d5
update
dongyang0122 6a36781
update
dongyang0122 a655980
update
guopengf bb3d46a
update
guopengf 97738a7
update license
guopengf 7274da7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,122 @@ | ||
# Medical AI for Synthetic Imaging (MAISI) | ||
This example shows the use cases of training and validating Nvidia MAISI (Medical AI for Synthetic Imaging), a 3D Latent Diffusion Model that can generate large CT images with paired segmentation masks, variable volume size and voxel size, as well as controllable organ/tumor size. | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The training and inference workflow of MAISI is depicted in the figure below. It begins by training an autoencoder in pixel space to encode images into latent features. Following that, it trains a diffusion model in the latent space to denoise the noisy latent features. During inference, it first generates latent features from random noise by applying multiple denoising steps using the trained diffusion model. Finally, it decodes the denoised latent features into images using the trained autoencoder. | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<p align="center"> | ||
<img src="./figures/maisi_train.jpg" alt="MAISI training scheme"> | ||
<br> | ||
<em>Figure 1: MAISI training scheme</em> | ||
</p> | ||
|
||
<p align="center"> | ||
<img src="./figures/maisi_infer.jpg" alt="MAISI inference scheme") | ||
<br> | ||
<em>Figure 2: MAISI inference scheme</em> | ||
</p> | ||
MAISI is based on the following papers: | ||
|
||
[**Latent Diffusion:** Rombach, Robin, et al. "High-resolution image synthesis with latent diffusion models." CVPR 2022.](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach_High-Resolution_Image_Synthesis_With_Latent_Diffusion_Models_CVPR_2022_paper.pdf) | ||
|
||
### 1. Installation | ||
Please refer to the [Installation of MONAI Generative Model](../README.md) | ||
|
||
### 2. Model inference and example outputs | ||
|
||
To generate one image during inference, please run the following command: | ||
```bash | ||
python inference.py -c ./configs/config_maisi.json -e ./configs/environment.json --num 1 | ||
``` | ||
`--num` defines how many images it would generate. | ||
|
||
An example output is shown below. | ||
<p align="center"> | ||
<img src="./figs/syn_axial.png" width="30%" > | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ||
<img src="./figs/syn_sag.png" width="30%" > | ||
| ||
<img src="./figs/syn_cor.png" width="30%" > | ||
KumoLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</p> | ||
|
||
### 3. Training example | ||
Training data preparation can be found in [./data/README.md](./data/README.md) | ||
|
||
#### [3.1 3D Autoencoder Training](./train_autoencoder.py) | ||
|
||
The network configuration files are located in [./config/config_train_32g.json](./config/config_train_32g.json) for 32G GPU | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and [./config/config_train_16g.json](./config/config_train_16g.json) for 16G GPU. | ||
You can modify the hyperparameters in these files to suit your requirements. | ||
|
||
The training script resamples the brain images based on the voxel spacing specified in the `"spacing"` field of the configuration files. For instance, `"spacing": [1.1, 1.1, 1.1]` resamples the images to a resolution of 1.1x1.1x1.1 mm. If you have a GPU with larger memory, you may consider changing the `"spacing"` field to `"spacing": [1.0, 1.0, 1.0]`. | ||
|
||
The training script uses the batch size and patch size defined in the configuration files. If you have a different GPU memory size, you should adjust the `"batch_size"` and `"patch_size"` parameters in the `"autoencoder_train"` to match your GPU. Note that the `"patch_size"` needs to be divisible by 4. | ||
|
||
Before you start training, please set the path in [./config/environment.json](./config/environment.json). | ||
|
||
- `"model_dir"`: where it saves the trained models | ||
- `"tfevent_path"`: where it saves the tensorboard events | ||
- `"output_dir"`: where you store the generated images during inference. | ||
- `"resume_ckpt"`: whether to resume training from existing checkpoints. | ||
- `"data_base_dir"`: where you store the Brats dataset. | ||
|
||
Below is the the training command for single GPU. | ||
|
||
```bash | ||
python train_autoencoder.py -c ./config/config_train_32g.json -e ./config/environment.json -g 1 | ||
``` | ||
|
||
The training script also enables multi-GPU training. For instance, if you are using eight 32G GPUs, you can run the training script with the following command: | ||
```bash | ||
export NUM_GPUS_PER_NODE=8 | ||
torchrun \ | ||
--nproc_per_node=${NUM_GPUS_PER_NODE} \ | ||
--nnodes=1 \ | ||
--master_addr=localhost --master_port=1234 \ | ||
train_autoencoder.py -c ./config/config_train_32g.json -e ./config/environment.json -g ${NUM_GPUS_PER_NODE} | ||
``` | ||
|
||
<p align="center"> | ||
<img src="./figs/train_recon.png" alt="autoencoder train curve" width="45%" > | ||
| ||
<img src="./figs/val_recon.png" alt="autoencoder validation curve" width="45%" > | ||
</p> | ||
|
||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
With eight DGX1V 32G GPUs, it took around 55 hours to train 1000 epochs. | ||
|
||
#### [3.2 3D Latent Diffusion Training](./train_diffusion.py) | ||
KumoLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The training script uses the batch size and patch size defined in the configuration files. If you have a different GPU memory size, you should adjust the `"batch_size"` and `"patch_size"` parameters in the `"diffusion_train"` to match your GPU. Note that the `"patch_size"` needs to be divisible by 16. | ||
|
||
To train with single 32G GPU, please run: | ||
```bash | ||
python train_diffusion.py -c ./config/config_train_32g.json -e ./config/environment.json -g 1 | ||
``` | ||
|
||
The training script also enables multi-GPU training. For instance, if you are using eight 32G GPUs, you can run the training script with the following command: | ||
```bash | ||
export NUM_GPUS_PER_NODE=8 | ||
torchrun \ | ||
--nproc_per_node=${NUM_GPUS_PER_NODE} \ | ||
--nnodes=1 \ | ||
--master_addr=localhost --master_port=1234 \ | ||
train_diffusion.py -c ./config/config_train_32g.json -e ./config/environment.json -g ${NUM_GPUS_PER_NODE} | ||
``` | ||
KumoLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<p align="center"> | ||
<img src="./figs/train_diffusion.png" alt="latent diffusion train curve" width="45%" > | ||
| ||
<img src="./figs/val_diffusion.png" alt="latent diffusion validation curve" width="45%" > | ||
</p> | ||
|
||
#### [3.3 3D ControNet Training](./train_controlnet.py) | ||
|
||
|
||
### 4. Questions and bugs | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- For questions relating to the use of MONAI, please use our [Discussions tab](https://github.com/Project-MONAI/MONAI/discussions) on the main repository of MONAI. | ||
- For bugs relating to MONAI functionality, please create an issue on the [main repository](https://github.com/Project-MONAI/MONAI/issues). | ||
- For bugs relating to the running of a tutorial, please create an issue in [this repository](https://github.com/Project-MONAI/Tutorials/issues). | ||
|
||
### Reference | ||
[1] [Rombach, Robin, et al. "High-resolution image synthesis with latent diffusion models." CVPR 2022.](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach_High-Resolution_Image_Synthesis_With_Latent_Diffusion_Models_CVPR_2022_paper.pdf) | ||
|
||
[2] [Menze, Bjoern H., et al. "The multimodal brain tumor image segmentation benchmark (BRATS)." IEEE transactions on medical imaging 34.10 (2014): 1993-2024.](https://ieeexplore.ieee.org/document/6975210) | ||
|
||
[3] [Pinaya et al. "Brain imaging generation with latent diffusion models"](https://arxiv.org/abs/2209.07162) |
This file contains hidden or 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,18 @@ | ||
# Medical AI for Synthetic Imaging (MAISI) Data Preparation | ||
|
||
Disclaimer: We are not the host of the data. Please make sure to read the requirements and usage policies of the data and give credit to the authors of the dataset! | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### 1 VAE training Data | ||
Can-Zhao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The VAE training dataset used in MAISI contains 37243 CT traiing data, 17887 CT validation data | ||
|
||
### 2 Diffusion model training Data | ||
KumoLiu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
### 3 ControlNet model training Data | ||
|
||
### 4. Questions and bugs | ||
|
||
- For questions relating to the use of MONAI, please use our [Discussions tab](https://github.com/Project-MONAI/MONAI/discussions) on the main repository of MONAI. | ||
- For bugs relating to MONAI functionality, please create an issue on the [main repository](https://github.com/Project-MONAI/MONAI/issues). | ||
- For bugs relating to the running of a tutorial, please create an issue in [this repository](https://github.com/Project-MONAI/Tutorials/issues). | ||
|
||
### Reference | ||
[1] [Rombach, Robin, et al. "High-resolution image synthesis with latent diffusion models." CVPR 2022.](https://openaccess.thecvf.com/content/CVPR2022/papers/Rombach_High-Resolution_Image_Synthesis_With_Latent_Diffusion_Models_CVPR_2022_paper.pdf) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.