Skip to content

Commit

Permalink
Merge branch 'main' into vista_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
finalelement authored Aug 23, 2024
2 parents d01158e + 2ec36f2 commit 04dbd0e
Show file tree
Hide file tree
Showing 12 changed files with 1,224 additions and 223 deletions.
11 changes: 7 additions & 4 deletions generation/maisi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,30 @@ MAISI is based on the following papers:
Network definition is stored in [./configs/config_maisi.json](./configs/config_maisi.json). Training and inference should use the same [./configs/config_maisi.json](./configs/config_maisi.json).

### 2. Model Inference
#### Inference parameters:
The information for the inference input, like body region and anatomy to generate, is stored in [./configs/config_infer.json](./configs/config_infer.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.5x1.5x2.0 mm.
- `"output_size"`: volume size of generated images. E.g., if set to `[512, 512, 256]`, it will generate images with size of 512x512x256. They need to be divisible by 16. If you have a small GPU memory size, you should adjust it to small numbers.
- `"output_size"`: volume size of generated images. E.g., if set to `[512, 512, 256]`, it will generate images with size of 512x512x256. 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 768x768x512 mm. We recommend the FOV in x and y axis to be at least 256mm for head, and at least 384mm for other body regions like abdomen. There is no such restriction for z-axis.
- `"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. The output will contain paired image and segmentation mask for the controllable anatomy.
- `"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.


Please refer to [maisi_inference_tutorial.ipynb](maisi_inference_tutorial.ipynb) for the tutorial for MAISI model inference.

#### Execute Inference:
To run the inference script, please run:
```bash
export MONAI_DATA_DIRECTORY=<dir_you_will_download_data>
python -m scripts.inference -c ./configs/config_maisi.json -i ./configs/config_infer.json -e ./configs/environment.json --random-seed 0
```

Please refer to [maisi_inference_tutorial.ipynb](maisi_inference_tutorial.ipynb) for the tutorial for MAISI model inference.

#### Quality Check:
We have implemented a quality check function for the generated CT images. The main idea behind this function is to ensure that the Hounsfield units (HU) intensity for each organ in the CT images remains within a defined range. For each training image used in the Diffusion network, we computed the median value for a few major organs. Then we summarize the statistics of these median values and save it to [./configs/image_median_statistics.json](./configs/image_median_statistics.json). During inference, for each generated image, we compute the median HU values for the major organs and check whether they fall within the normal range.

### 3. Model Training
Training data preparation can be found in [./data/README.md](./data/README.md)

Expand Down
2 changes: 1 addition & 1 deletion generation/maisi/configs/config_maisi.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"use_checkpointing": false,
"use_convtranspose": false,
"norm_float16": true,
"num_splits": 16,
"num_splits": 8,
"dim_split": 1
},
"diffusion_unet_def": {
Expand Down
72 changes: 72 additions & 0 deletions generation/maisi/configs/image_median_statistics.json
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
}
}
Loading

0 comments on commit 04dbd0e

Please sign in to comment.