Skip to content

Commit

Permalink
Merge branch 'Project-MONAI:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
virginiafdez authored Sep 16, 2024
2 parents e5fba2b + ae3f383 commit c01dacb
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 34 deletions.
5 changes: 2 additions & 3 deletions 3d_segmentation/unetr_btcv_segmentation_3d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"\n",
"\n",
"This tutorial demonstrates how to construct a training workflow of UNETR [1] on multi-organ segmentation task using the BTCV challenge dataset.\n",
"![image](https://lh3.googleusercontent.com/pw/AM-JKLU2eTW17rYtCmiZP3WWC-U1HCPOHwLe6pxOfJXwv2W-00aHfsNy7jeGV1dwUq0PXFOtkqasQ2Vyhcu6xkKsPzy3wx7O6yGOTJ7ZzA01S6LSh8szbjNLfpbuGgMe6ClpiS61KGvqu71xXFnNcyvJNFjN=w1448-h496-no?authuser=0)\n",
"\n",
"And it contains the following features:\n",
"1. Transforms for dictionary format data.\n",
Expand Down Expand Up @@ -51,7 +50,7 @@
"3. [Efficient multi-atlas abdominal segmentation on clinically acquired CT with SIMPLE context learning (MIA)](https://www.sciencedirect.com/science/article/abs/pii/S1361841515000766?via%3Dihub)\n",
"\n",
"\n",
"![image](https://lh3.googleusercontent.com/pw/AM-JKLX0svvlMdcrchGAgiWWNkg40lgXYjSHsAAuRc5Frakmz2pWzSzf87JQCRgYpqFR0qAjJWPzMQLc_mmvzNjfF9QWl_1OHZ8j4c9qrbR6zQaDJWaCLArRFh0uPvk97qAa11HtYbD6HpJ-wwTCUsaPcYvM=w1724-h522-no?authuser=0)\n",
"![image](../figures/BTCV_organs.png)\n",
"\n",
"\n",
"\n",
Expand Down Expand Up @@ -586,7 +585,7 @@
" hidden_size=768,\n",
" mlp_dim=3072,\n",
" num_heads=12,\n",
" pos_embed=\"perceptron\",\n",
" proj_type=\"perceptron\",\n",
" norm_name=\"instance\",\n",
" res_block=True,\n",
" dropout_rate=0.0,\n",
Expand Down
2 changes: 1 addition & 1 deletion 3d_segmentation/unetr_btcv_segmentation_3d_lightning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
" hidden_size=768,\n",
" mlp_dim=3072,\n",
" num_heads=12,\n",
" pos_embed=\"perceptron\",\n",
" proj_type=\"perceptron\",\n",
" norm_name=\"instance\",\n",
" res_block=True,\n",
" conv_block=True,\n",
Expand Down
2 changes: 1 addition & 1 deletion deepedit/ignite/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_network(network, labels, spatial_size):
hidden_size=1536,
mlp_dim=3072,
num_heads=48,
pos_embed="conv",
proj_type="conv",
norm_name="instance",
res_block=True,
)
Expand Down
2 changes: 1 addition & 1 deletion deployment/Triton/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from monai.apps.utils import download_and_extract

model_name = "monai_covid"
gdrive_path = "https://drive.google.com/uc?id=1GYvHGU2jES0m_msin-FFQnmTOaHkl0LN"
gdrive_path = "https://developer.download.nvidia.com/assets/Clara/monai/tutorials/covid19_compressed.tar.gz"
covid19_filename = "covid19_compress.tar.gz"
md5_check = "cadd79d5ca9ccdee2b49cd0c8a3e6217"

Expand Down
2 changes: 1 addition & 1 deletion deployment/Triton/client/client_mednist.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


model_name = "mednist_class"
gdrive_path = "https://drive.google.com/uc?id=1HQk4i4vXKUX_aAYR4wcZQKd-qk5Lcm_W"
gdrive_path = "https://developer.download.nvidia.com/assets/Clara/monai/tutorials/MedNIST_demo.tar.gz"
mednist_filename = "MedNIST_demo.tar.gz"
md5_check = "3f24a5833bb0455a7815c4e0ecc8a810"

Expand Down
2 changes: 1 addition & 1 deletion deployment/Triton/models/mednist_class/1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


logger = logging.getLogger(__name__)
gdrive_url = "https://drive.google.com/uc?id=1c6noLV9oR0_mQwrsiQ9TqaaeWFKyw46l"
gdrive_url = "https://developer.download.nvidia.com/assets/Clara/monai/tutorials/MedNist_model.tar.gz"
model_filename = "MedNIST_model.tar.gz"
md5_check = "a4fb9d6147599e104b5d8dc1809ed034"

Expand Down
2 changes: 1 addition & 1 deletion deployment/Triton/models/monai_covid/1/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@


logger = logging.getLogger(__name__)
gdrive_url = "https://drive.google.com/uc?id=1U9Oaw47SWMJeDkg1FSTY1W__tQOY1nAZ"
gdrive_url = "https://developer.download.nvidia.com/assets/Clara/monai/tutorials/covid19_model.tar.gz"
model_filename = "covid19_model.tar.gz"
md5_check = "571046a25659515bf7abee4266f14435"

Expand Down
2 changes: 1 addition & 1 deletion detection/generate_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def generate_detection_train_transform(
spatial_axes=(0, 1),
),
# apply the same affine matrix which already applied on the images to the points
ApplyTransformToPointsd(keys=[point_key], refer_key=image_key, affine_lps_to_ras=affine_lps_to_ras),
ApplyTransformToPointsd(keys=[point_key], refer_keys=image_key, affine_lps_to_ras=affine_lps_to_ras),
# convert points back to boxes
ConvertPointsToBoxesd(keys=[point_key]),
ClipBoxToImaged(
Expand Down
13 changes: 5 additions & 8 deletions generation/2d_ldm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ python download_brats_data.py -e ./config/environment.json

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!

### 2. Installation
Please refer to the [Installation of MONAI Generative Model](../README.md)
### 2. Run the example

### 3. Run the example

#### [3.1 2D Autoencoder Training](./train_autoencoder.py)
#### [2.1 2D 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 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.

Expand Down Expand Up @@ -74,7 +71,7 @@ An example reconstruction result is shown below:
<img src="./figs/recon.png" alt="Autoencoder reconstruction result")
</p>

#### [3.2 2D Latent Diffusion Training](./train_diffusion.py)
#### [2.2 2D Latent Diffusion Training](./train_diffusion.py)
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 and no larger than 256.

To train with single 32G GPU, please run:
Expand All @@ -97,7 +94,7 @@ torchrun \
<img src="./figs/val_diffusion.png" alt="latent diffusion validation curve" width="45%" >
</p>

#### [3.3 Inference](./inference.py)
#### [2.3 Inference](./inference.py)
To generate one image during inference, please run the following command:
```bash
python inference.py -c ./config/config_train_32g.json -e ./config/environment.json --num 1
Expand All @@ -115,7 +112,7 @@ An example output is shown below.
<img src="./figs/syn_3.jpeg" width="20%" >
</p>

### 4. Questions and bugs
### 3. 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).
Expand Down
13 changes: 5 additions & 8 deletions generation/3d_ldm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ python download_brats_data.py -e ./config/environment.json

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!

### 2. Installation
Please refer to the [Installation of MONAI Generative Model](../README.md)
### 2. Run the example

### 3. Run the example

#### [3.1 3D Autoencoder Training](./train_autoencoder.py)
#### [2.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
and [./config/config_train_16g.json](./config/config_train_16g.json) for 16G GPU.
Expand Down Expand Up @@ -73,7 +70,7 @@ torchrun \

With eight DGX1V 32G GPUs, it took around 55 hours to train 1000 epochs.

#### [3.2 3D Latent Diffusion Training](./train_diffusion.py)
#### [2.2 3D Latent Diffusion Training](./train_diffusion.py)
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:
Expand All @@ -96,7 +93,7 @@ torchrun \
<img src="./figs/val_diffusion.png" alt="latent diffusion validation curve" width="45%" >
</p>

#### [3.3 Inference](./inference.py)
#### [2.3 Inference](./inference.py)
To generate one image during inference, please run the following command:
```bash
python inference.py -c ./config/config_train_32g.json -e ./config/environment.json --num 1
Expand All @@ -112,7 +109,7 @@ An example output is shown below.
<img src="./figs/syn_cor.png" width="30%" >
</p>

### 4. Questions and bugs
### 3. 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).
Expand Down
8 changes: 8 additions & 0 deletions generation/maisi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ The information for the inference input, like body region and anatomy to generat

To generate images with substantial dimensions, such as 512 &times; 512 &times; 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:
To run the inference script, please run:
```bash
Expand Down
5 changes: 4 additions & 1 deletion generation/maisi/scripts/infer_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from monai.transforms import SaveImage
from monai.utils import RankFilter

from .sample import ldm_conditional_sample_one_image
from .sample import check_input, ldm_conditional_sample_one_image
from .utils import define_instance, prepare_maisi_controlnet_json_dataloader, setup_ddp


Expand Down Expand Up @@ -150,10 +150,13 @@ def main():
top_region_index_tensor = batch["top_region_index"].to(device)
bottom_region_index_tensor = batch["bottom_region_index"].to(device)
spacing_tensor = batch["spacing"].to(device)
out_spacing = tuple((batch["spacing"].squeeze().numpy() / 100).tolist())
# get target dimension
dim = batch["dim"]
output_size = (dim[0].item(), dim[1].item(), dim[2].item())
latent_shape = (args.latent_channels, output_size[0] // 4, output_size[1] // 4, output_size[2] // 4)
# check if output_size and out_spacing are valid.
check_input(None, None, None, output_size, out_spacing, None)
# generate a single synthetic image using a latent diffusion model with controlnet.
synthetic_images, _ = ldm_conditional_sample_one_image(
autoencoder,
Expand Down
2 changes: 1 addition & 1 deletion modules/developer_guide.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@
"id": "kvn_6mf9gZoA"
},
"source": [
"The following commands will start a `SupervisedTrainer` instance. As an extension of Pytorch ignite's facilities, it combines all the elements mentioned before. Calling `trainer.run()` will train the network for two epochs and compute `MeadDice` metric based on the training data at the end of every epoch.\n",
"The following commands will start a `SupervisedTrainer` instance. As an extension of Pytorch ignite's facilities, it combines all the elements mentioned before. Calling `trainer.run()` will train the network for two epochs and compute `MeanDice` metric based on the training data at the end of every epoch.\n",
"\n",
"The `key_train_metric` is used to track the progress of model quality improvement. Additional handlers could be set to do early stopping and learning rate scheduling.\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion modules/interpretability/class_lung_lesion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"\n",
"For the demo data:\n",
"- Please see the `bbox_gen.py` script for generating the patch classification data from MSD task06_lung (available via `monai.apps.DecathlonDataset`);\n",
"- Alternatively, the patch dataset (~130MB) is available for direct downloading at: https://drive.google.com/drive/folders/1pQdzdkkC9c2GOblLgpGlG3vxsSK9NtDx\n",
"- Alternatively, the patch dataset (~130MB) is available for direct downloading at: https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/lung_lesion_patches.tar.gz\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Project-MONAI/tutorials/blob/main/modules/interpretability/class_lung_lesion.ipynb)"
]
Expand Down
4 changes: 2 additions & 2 deletions modules/tcia_csv_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@
"metadata": {},
"source": [
"## Download and Load the CSV file with `TCIADataset`\n",
"Here we use the demo data in Google drive:\n",
"https://drive.google.com/file/d/1HQ7BZvBr1edmi8HIwdG5KBweXWms5Uzk/view?usp=sharing \n",
"Here we use the demo data located here:\n",
"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ISPY1_Combined.csv \n",
"\n",
"Expect the first row of CSV file to be titles of columns. we only use the first 8 rows to execute demo processing."
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def main(args):
in_channels=1,
img_size=(96, 96, 96),
patch_size=(16, 16, 16),
pos_embed="conv",
proj_type="conv",
hidden_size=768,
mlp_dim=3072,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
" hidden_size=768,\n",
" mlp_dim=3072,\n",
" num_heads=12,\n",
" pos_embed=\"conv\",\n",
" proj_type=\"conv\",\n",
" norm_name=\"instance\",\n",
" res_block=True,\n",
" dropout_rate=0.0,\n",
Expand Down
2 changes: 1 addition & 1 deletion self_supervised_pretraining/vit_unetr_ssl/ssl_train.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
" in_channels=1,\n",
" img_size=(96, 96, 96),\n",
" patch_size=(16, 16, 16),\n",
" pos_embed=\"conv\",\n",
" proj_type=\"conv\",\n",
" hidden_size=768,\n",
" mlp_dim=3072,\n",
")\n",
Expand Down

0 comments on commit c01dacb

Please sign in to comment.