How rafaelbou/cyclegan_old2new_car_models works
Project type and purpose
• This is an open-source research tool implementing CycleGAN in TensorFlow. Its purpose is unpaired image-to-image translation (e.g., horses↔zebras) by training two generators and two discriminators with cycle-consistency loss.
File structure
• Top-level scripts:
• download_dataset.sh – fetches sample datasets (e.g. horse2zebra)
• main.py – entry point for both training and testing
• Core model code:
• model.py – builds and trains the CycleGAN (defines generators, discriminators, losses, optimizers)
• module.py – reusable neural-network building blocks (Conv, Deconv, ResNet blocks)
• ops.py – low-level TensorFlow operations (instance norm, leaky ReLU, etc.)
• Utilities and I/O:
• utils.py – data loading, image preprocessing/augmentation, result saving
• requirements.txt – Python dependencies
• Artifacts:
• imgs/ – example input/output images
• logs_old/ – previous TensorBoard event files
README for additional insights
• Describes how to train (python main.py --dataset_dir=…) and test (--phase=test).
• Checkpoints saved in ./checkpoint/, logs in ./logs/.
• Relies on TensorFlow r1.x, NumPy, SciPy, Pillow.
a. Main components
1. Data Layer
– Dataset storage (local folder, e.g. horse2zebra/)
– download_dataset.sh script
2. Preprocessing Layer
– utils.load_image(), utils.preprocess()
3. Model Layer
– module.py blocks
– ops.py TF layers
– model.py:
• Generator A→B, Generator B→A
• Discriminator A, Discriminator B
• Loss calculators (adversarial, cycle, identity)
• Optimizers
4. Orchestrator
– main.py: parses arguments, calls model.train() or model.test()
5. Persistence & Monitoring
– Checkpoint Manager (tf.train.Saver) → ./checkpoint/
– TensorBoard summaries → ./logs/
6. Output Layer
– utils.save_images() → imgs/ or test output folder
b. Relationships and data flows
• Data Layer → Preprocessing → Model Layer (input pipelines)
• Model Layer ↔ Loss functions ↔ Optimizer (training loop)
• Training loop → Checkpoint Manager (periodic saves)
• Training loop → TensorBoard summaries (metrics, images)
• Test phase: Preprocessing → Model.inference() → Output Layer
c. Architectural patterns and principles
– Modular separation:
• Reusable blocks in module.py, ops.py
• High-level orchestration in model.py and main.py
– Pipeline pattern for data ingest → transform → model
– Clear distinction between training vs. inference logic
d. Key technologies
– TensorFlow r1.x (core DL framework)
– NumPy/SciPy (data manipulation)
– Pillow (image I/O)
– TensorBoard (visualization)