Skip to content

Commit 9c7bbf4

Browse files
Add FID Score Computation (#1952)
Add 2.5D FID Score computation for volumetric CT image generation. ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [ ] Avoid including large-size files in the PR. - [ ] Clean up long text outputs from code cells in the notebook. - [ ] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [ ] 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 - [ ] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` --------- Signed-off-by: dongyang0122 <don.yang.mech@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4a40380 commit 9c7bbf4

File tree

2 files changed

+801
-2
lines changed

2 files changed

+801
-2
lines changed

generation/maisi/README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,65 @@ torchrun \
247247
```
248248
Please also check [maisi_train_controlnet_tutorial.ipynb](./maisi_train_controlnet_tutorial.ipynb) for more details about data preparation and training parameters.
249249

250-
### 4. License
250+
### 4. FID Score Computation
251+
252+
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.
253+
254+
#### Key Features
255+
256+
- **Distributed Processing**
257+
Scales to multiple GPUs and larger datasets by splitting the workload across devices.
258+
259+
- **2.5D Feature Extraction**
260+
Uses a slice-based technique, applying a 2D model across all slices in each dimension.
261+
262+
- **Flexible Preprocessing**
263+
Supports optional center-cropping, padding, and resampling to target shapes or voxel spacings.
264+
265+
#### Usage Example
266+
267+
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:
268+
```
269+
case001.nii.gz
270+
case002.nii.gz
271+
case003.nii.gz
272+
```
273+
You also have a **synthetic** dataset in `path/to/synth_images` with a corresponding `synth_filelist.txt`. You can run the script as follows:
274+
275+
```bash
276+
torchrun --nproc_per_node=2 compute_fid_2-5d_ct.py \
277+
--model_name "radimagenet_resnet50" \
278+
--real_dataset_root "path/to/real_images" \
279+
--real_filelist "path/to/real_filelist.txt" \
280+
--real_features_dir "datasetA" \
281+
--synth_dataset_root "path/to/synth_images" \
282+
--synth_filelist "path/to/synth_filelist.txt" \
283+
--synth_features_dir "datasetB" \
284+
--enable_center_slices_ratio 0.4 \
285+
--enable_padding True \
286+
--enable_center_cropping True \
287+
--enable_resampling_spacing "1.0x1.0x1.0" \
288+
--ignore_existing True \
289+
--num_images 100 \
290+
--output_root "./features/features-512x512x512" \
291+
--target_shape "512x512x512"
292+
```
293+
294+
This command will:
295+
1. Launch a distributed run with 2 GPUs.
296+
2. Load each `.nii.gz` file from your specified `real_filelist` and `synth_filelist`.
297+
3. Apply 2.5D feature extraction across the XY, YZ, and ZX planes.
298+
4. Compute FID to compare **real** vs. **synthetic** feature distributions.
299+
300+
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.
301+
302+
### 5. License
251303

252304
The code is released under Apache 2.0 License.
253305

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

256-
### 5. Questions and Bugs
308+
### 6. Questions and Bugs
257309

258310
- 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.
259311
- For bugs relating to MONAI functionality, please create an issue on the [main repository](https://github.com/Project-MONAI/MONAI/issues).

0 commit comments

Comments
 (0)