A CycleGAN-based model for 3D image-to-image translation.
This project implements a 3D CycleGAN architecture for unpaired image-to-image translation in 3D space. It extends the traditional CycleGAN concept to work with 3D volumetric data, making it suitable for applications in medical imaging, 3D modeling, and volumetric data transformation.
- Python 3.9+
- CUDA-capable GPU (recommended)
- PyTorch version depending on the CUDA version
- Additional dependencies listed in
requirements.txt
- Clone the repository:
git clone https://github.com/somethingDKFZhere/3DcycleGAN.git
cd 3DcycleGAN- Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
.\venv\Scripts\activate
# On Linux/Mac
source venv/bin/activate- Install the required dependencies:
pip install -r requirements.txt- Organize your dataset in the following structure:
data/
├── train/
│ ├── images/
│ │ └── (source domain 3D images)
│ └── labels/
│ └── (corresponding label files)
├── validation/
│ ├── images/
│ │ └── (validation source domain images)
│ └── labels/
│ └── (validation label files)
└── test/
├── images/
│ └── (test source domain images)
└── labels/
└── (test label files)
-
Supported input formats:
- NIfTI (.nii, .nii.gz)
-
Data organization guidelines:
- Image and label files should have matching filenames, e.g. (001_site_CT_1.nii.gz and 001_site_CBCT_1.nii.gz)
- Recommended split ratios: 70% train, 15% validation, 15% test
- All images should have consistent dimensions and orientation
To train the model:
First set-up files in the options folder: base_options.py, train_options.py and test_options.py. You need to set test_options in the beginning because they are used in the validation steps along the way.
Then run:
python train.pyTo test the trained model:
python test.pyThe 3D CycleGAN consists of:
- Two 3D generators (G_A2B and G_B2A)
- Two 3D discriminators (D_A and D_B)
- Cycle consistency loss
- Identity loss
- Adversarial loss
Results will be saved in the checkpoints/ directory with the following structure:
checkpoints/
└── experiment_name/
├── images/
├── epoch_net_...
├── latest_net_G_A.pth
├── latest_net_G_B.pth
├── Losses.jpg
├── Individual losses
├── loss_log.txt
├── opt.txt
└── val_metrics_log.csv
This project is licensed under the MIT License - see the LICENSE file for details.
This implementation is inspired by:
For questions and feedback, please open an issue in the repository or contact [goran.stanic@dkfz-heidelberg.de].