Skip to content

DKFZ-OpenMedPhys/3DcycleGAN

Repository files navigation

3DcycleGAN

A CycleGAN-based model for 3D image-to-image translation.

Overview

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.

Requirements

  • Python 3.9+
  • CUDA-capable GPU (recommended)
  • PyTorch version depending on the CUDA version
  • Additional dependencies listed in requirements.txt

Installation

  1. Clone the repository:
git clone https://github.com/somethingDKFZhere/3DcycleGAN.git
cd 3DcycleGAN
  1. Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
.\venv\Scripts\activate
# On Linux/Mac
source venv/bin/activate
  1. Install the required dependencies:
pip install -r requirements.txt

Dataset Preparation

  1. 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)
  1. Supported input formats:

    • NIfTI (.nii, .nii.gz)
  2. 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

Training

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.py

Testing

To test the trained model:

python test.py

Model Architecture

The 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

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This implementation is inspired by:

Contact

For questions and feedback, please open an issue in the repository or contact [goran.stanic@dkfz-heidelberg.de].

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages