Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions generation/maisi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,65 @@ torchrun \
```
Please also check [maisi_train_controlnet_tutorial.ipynb](./maisi_train_controlnet_tutorial.ipynb) for more details about data preparation and training parameters.

### 4. License
### 4. FID Score Computation

We provide the `compute_fid_2-5d_ct.py` script that calculates the Frechet Inception Distance (FID) between two 3D medical datasets (e.g., **real** vs. **synthetic** images). It uses a **2.5D** feature-extraction approach across three orthogonal planes (XY, YZ, ZX) and leverages **distributed GPU processing** (via PyTorch’s `torch.distributed` and NCCL) for efficient, large-scale computations.

#### Key Features

- **Distributed Processing**
Scales to multiple GPUs and larger datasets by splitting the workload across devices.

- **2.5D Feature Extraction**
Uses a slice-based technique, applying a 2D model across all slices in each dimension.

- **Flexible Preprocessing**
Supports optional center-cropping, padding, and resampling to target shapes or voxel spacings.

#### Usage Example

Suppose your **real** dataset root is `path/to/real_images`, and you have a `real_filelist.txt` that lists filenames line by line, such as:
```
case001.nii.gz
case002.nii.gz
case003.nii.gz
```
You also have a **synthetic** dataset in `path/to/synth_images` with a corresponding `synth_filelist.txt`. You can run the script as follows:

```bash
torchrun --nproc_per_node=2 compute_fid_2-5d_ct.py \
--model_name "radimagenet_resnet50" \
--real_dataset_root "path/to/real_images" \
--real_filelist "path/to/real_filelist.txt" \
--real_features_dir "datasetA" \
--synth_dataset_root "path/to/synth_images" \
--synth_filelist "path/to/synth_filelist.txt" \
--synth_features_dir "datasetB" \
--enable_center_slices_ratio 0.4 \
--enable_padding True \
--enable_center_cropping True \
--enable_resampling_spacing "1.0x1.0x1.0" \
--ignore_existing True \
--num_images 100 \
--output_root "./features/features-512x512x512" \
--target_shape "512x512x512"
```

This command will:
1. Launch a distributed run with 2 GPUs.
2. Load each `.nii.gz` file from your specified `real_filelist` and `synth_filelist`.
3. Apply 2.5D feature extraction across the XY, YZ, and ZX planes.
4. Compute FID to compare **real** vs. **synthetic** feature distributions.

For more details, see the in-code docstring in [`compute_fid_2-5d_ct.py`](./scripts/compute_fid_2-5d_ct.py) or consult our documentation for a deeper dive into function arguments and the underlying implementation.

### 5. License

The code is released under Apache 2.0 License.

The model weight is released under [NSCLv1 License](./LICENSE.weights).

### 5. Questions and Bugs
### 6. 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
Loading
Loading