Skip to content

Commit 437e325

Browse files
authored
Merge branch 'main' into maisi
2 parents f145874 + 9c7bbf4 commit 437e325

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
@@ -287,13 +287,65 @@ torchrun \
287287
```
288288
Please also check [maisi_train_controlnet_tutorial.ipynb](./maisi_train_controlnet_tutorial.ipynb) for more details about data preparation and training parameters.
289289

290-
### 4. License
290+
### 4. FID Score Computation
291+
292+
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.
293+
294+
#### Key Features
295+
296+
- **Distributed Processing**
297+
Scales to multiple GPUs and larger datasets by splitting the workload across devices.
298+
299+
- **2.5D Feature Extraction**
300+
Uses a slice-based technique, applying a 2D model across all slices in each dimension.
301+
302+
- **Flexible Preprocessing**
303+
Supports optional center-cropping, padding, and resampling to target shapes or voxel spacings.
304+
305+
#### Usage Example
306+
307+
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:
308+
```
309+
case001.nii.gz
310+
case002.nii.gz
311+
case003.nii.gz
312+
```
313+
You also have a **synthetic** dataset in `path/to/synth_images` with a corresponding `synth_filelist.txt`. You can run the script as follows:
314+
315+
```bash
316+
torchrun --nproc_per_node=2 compute_fid_2-5d_ct.py \
317+
--model_name "radimagenet_resnet50" \
318+
--real_dataset_root "path/to/real_images" \
319+
--real_filelist "path/to/real_filelist.txt" \
320+
--real_features_dir "datasetA" \
321+
--synth_dataset_root "path/to/synth_images" \
322+
--synth_filelist "path/to/synth_filelist.txt" \
323+
--synth_features_dir "datasetB" \
324+
--enable_center_slices_ratio 0.4 \
325+
--enable_padding True \
326+
--enable_center_cropping True \
327+
--enable_resampling_spacing "1.0x1.0x1.0" \
328+
--ignore_existing True \
329+
--num_images 100 \
330+
--output_root "./features/features-512x512x512" \
331+
--target_shape "512x512x512"
332+
```
333+
334+
This command will:
335+
1. Launch a distributed run with 2 GPUs.
336+
2. Load each `.nii.gz` file from your specified `real_filelist` and `synth_filelist`.
337+
3. Apply 2.5D feature extraction across the XY, YZ, and ZX planes.
338+
4. Compute FID to compare **real** vs. **synthetic** feature distributions.
339+
340+
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.
341+
342+
### 5. License
291343

292344
The code is released under Apache 2.0 License.
293345

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

296-
### 5. Questions and Bugs
348+
### 6. Questions and Bugs
297349

298350
- 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.
299351
- 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)