Skip to content

Commit 69ccafd

Browse files
Update maisi readme and add input check to controlnet infer script (#1825)
Fixes # . ### Description 1. We provide several recommended spacing parameters for different output sizes in README 2. Add an additional input check in the ControlNet inference script to prevent generating images with small FOV. ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Avoid including large-size files in the PR. - [x] Clean up long text outputs from code cells in the notebook. - [x] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [x] Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the `./figure` folder - [x] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` --------- Signed-off-by: Pengfei Guo <pengfeig@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 08ccc1e commit 69ccafd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

generation/maisi/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ The information for the inference input, like body region and anatomy to generat
6868

6969
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.
7070

71+
#### Recommended spacing for different output sizes:
72+
73+
|`output_size`| Recommended `"spacing"`|
74+
|:-----:|:-----:|
75+
[256, 256, 256] | [1.5, 1.5, 1.5] |
76+
[512, 512, 128] | [0.8, 0.8, 2.5] |
77+
[512, 512, 512] | [1.0, 1.0, 1.0] |
78+
7179
#### Execute Inference:
7280
To run the inference script, please run:
7381
```bash

generation/maisi/scripts/infer_controlnet.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from monai.transforms import SaveImage
2424
from monai.utils import RankFilter
2525

26-
from .sample import ldm_conditional_sample_one_image
26+
from .sample import check_input, ldm_conditional_sample_one_image
2727
from .utils import define_instance, prepare_maisi_controlnet_json_dataloader, setup_ddp
2828

2929

@@ -150,10 +150,13 @@ def main():
150150
top_region_index_tensor = batch["top_region_index"].to(device)
151151
bottom_region_index_tensor = batch["bottom_region_index"].to(device)
152152
spacing_tensor = batch["spacing"].to(device)
153+
out_spacing = tuple((batch["spacing"].squeeze().numpy() / 100).tolist())
153154
# get target dimension
154155
dim = batch["dim"]
155156
output_size = (dim[0].item(), dim[1].item(), dim[2].item())
156157
latent_shape = (args.latent_channels, output_size[0] // 4, output_size[1] // 4, output_size[2] // 4)
158+
# check if output_size and out_spacing are valid.
159+
check_input(None, None, None, output_size, out_spacing, None)
157160
# generate a single synthetic image using a latent diffusion model with controlnet.
158161
synthetic_images, _ = ldm_conditional_sample_one_image(
159162
autoencoder,

0 commit comments

Comments
 (0)