Workflow:Junyanz Pytorch CycleGAN and pix2pix Pretrained Inference
| Knowledge Sources | |
|---|---|
| Domains | Computer_Vision, GANs, Image_Translation |
| Last Updated | 2026-02-09 16:00 GMT |
Overview
End-to-end process for applying pre-trained CycleGAN or pix2pix models to translate images without any training.
Description
This workflow covers how to download and use pre-trained image translation models for immediate inference. It supports both CycleGAN models (for unpaired translation tasks like horse-to-zebra, style transfer, satellite-to-map) and pix2pix models (for paired translation tasks like labels-to-photos, edges-to-objects). The inference pipeline loads a saved generator network, processes input images through it, and produces an HTML gallery of results. A special "test" model mode is available that loads only a single generator for efficient one-directional CycleGAN inference.
Usage
Execute this workflow when you want to translate images using an already-trained model without performing any training. This is appropriate when a suitable pre-trained model exists for your domain pair, when you want to quickly evaluate the quality of translations, or when you want to apply a previously trained custom model to new input images.
Execution Steps
Step 1: Environment Setup
Install the required dependencies. The inference pipeline requires the same base dependencies as training: PyTorch (2.4+), torchvision, and Pillow. Visdom and wandb are optional for inference. The setup is lighter than training since no gradient computation or optimizer state is needed.
Key considerations:
- CPU inference is supported (no GPU required, though slower)
- Memory requirements are lower than training since only the generator is loaded
Step 2: Download Pretrained Model
Download a pre-trained generator checkpoint using the provided download scripts. For CycleGAN, available models include horse2zebra, monet2photo, style_monet, style_cezanne, style_ukiyoe, style_vangogh, sat2map, map2sat, cityscapes and facades variants, and iphone2dslr_flower. For pix2pix, available models include facades_label2photo and others. The script downloads the checkpoint file and places it in the checkpoints directory with the expected naming convention.
Key considerations:
- CycleGAN models are downloaded to checkpoints/{name}_pretrained/latest_net_G.pth
- Pix2pix models follow the same convention
- Models are hosted on the Berkeley EECS server
- Custom trained models can also be used by placing checkpoints in the expected directory
Step 3: Prepare Input Data
Organize the input images for translation. For CycleGAN one-directional inference (--model test), place images in a single directory. For CycleGAN bidirectional inference (--model cycle_gan), organize images into testA and testB subdirectories. For pix2pix inference, provide the aligned image pairs in the expected format. Standard built-in test datasets can be downloaded using the dataset download scripts.
Key considerations:
- The --model test option uses single dataset mode (one directory of images)
- The --model cycle_gan option requires both testA and testB directories
- For pix2pix, images must be aligned pairs in the same format used during training
- Input images are automatically resized and cropped according to the preprocessing settings
Step 4: Run Inference
Execute the test script with appropriate options specifying the data root, experiment name, and model type. The script loads the trained generator, disables gradient computation, iterates through the input images, runs each through the generator network, and collects the visual outputs. Key options include --model (test for single-direction CycleGAN, cycle_gan for both directions, pix2pix for paired), --no_dropout (required for CycleGAN), and --epoch (to select which checkpoint to load).
Key considerations:
- The --num_test option limits how many images to process (default: 50)
- The --eval flag puts the model in evaluation mode (affects batchnorm and dropout layers)
- For pix2pix models, --netG, --norm, and --no_dropout must match the training configuration
- CycleGAN models default to --no_dropout and instance normalization
Step 5: Review Results
Browse the generated HTML gallery containing the translation results. The output directory contains an index.html file that displays input images alongside their translated outputs. For CycleGAN test mode, the gallery shows original and translated images. For full CycleGAN mode, it shows translations in both directions plus reconstructions. For pix2pix, it shows input, generated output, and ground truth.
Key considerations:
- Results are saved to results/{name}/{phase}_{epoch}/index.html
- Individual generated images are also saved as separate files
- The gallery can be opened in any web browser for visual inspection
- Results directory can be customized with --results_dir