Downloads · 30 days
0
christopherOosthuizen/cyclegan-keys-to-raisins
cyclegan-keys-to-raisins is a machine learning model from christopherOosthuizen. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
A CycleGAN model that converts images of keys into images of raisins (and vice versa) using unpaired image-to-image translation.
Downloads · 30 days
0
Access
Public
Updated Apr 24, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py31.7 KB · 88%
From the Hugging Face model README
A CycleGAN model that converts images of keys into images of raisins (and vice versa) using unpaired image-to-image translation.
This project implements the classic CycleGAN architecture from Zhu et al., "Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks" (ICCV 2017).
The model learns to translate between two unpaired image domains:
| Parameter | Value |
|---|---|
| Image size | 256×256 |
| Generator filters | 64 |
| Discriminator filters | 64 |
| Residual blocks | 9 |
| Batch size | 1 |
| Learning rate | 0.0002 |
| β₁, β₂ | 0.5, 0.999 |
| Epochs | 200 (100 constant + 100 decay) |
| Optimizer | Adam |
The training data was generated synthetically:
# Generate data and train
python train_cyclegan.py --epochs 200 --dataroot ./datasets/keys2raisins --output_dir ./outputs
# Key -> Raisin
python inference.py --input key_photo.jpg --checkpoint G_AB_final.pth --output raisin.jpg
# Raisin -> Key
python inference.py --input raisin_photo.jpg --checkpoint G_BA_final.pth --output key.jpg
import torch
from inference import Generator, load_generator
device = 'cuda' if torch.cuda.is_available() else 'cpu'
# Load key -> raisin generator
G = load_generator('G_AB_final.pth', ngf=64, n_residual_blocks=9, device=device)
# Your image should be 256x256 RGB, normalized to [-1, 1]
# The generator returns a translated tensor
| File | Description |
|---|---|
train_cyclegan.py | Full training script with data generation |
inference.py | Translate images using trained generators |
config.json | Model configuration |
@inproceedings{zhu2017unpaired,
title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks},
author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},
booktitle={ICCV},
year={2017}
}