Environment:Junyanz Pytorch CycleGAN and pix2pix Python PyTorch Runtime
| Knowledge Sources | |
|---|---|
| Domains | Computer_Vision, Deep_Learning, Infrastructure |
| Last Updated | 2026-02-09 16:00 GMT |
Overview
Linux or macOS environment with Python 3.11, PyTorch 2.4+, CUDA 12.1, and visualization dependencies (dominate, wandb, Pillow).
Description
This environment provides the full runtime context for training and testing CycleGAN and pix2pix image-to-image translation models. It is built around a Conda environment specification (pytorch-img2img) that pins Python 3.11, PyTorch 2.4.0, torchvision 0.19.0, and CUDA 12.1. The code supports both GPU-accelerated and CPU-only execution (set --gpu_ids -1 for CPU mode). For GPU execution, any NVIDIA GPU with CUDA support is sufficient; no minimum VRAM is strictly enforced, though CycleGAN requires significantly more memory than pix2pix due to loading four networks simultaneously.
Usage
Use this environment for all CycleGAN and pix2pix workflows: training, testing, inference, and dataset preparation. It is the mandatory prerequisite for every Implementation in this repository. GPU acceleration is strongly recommended for training but optional for inference.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux or macOS | Windows not officially supported; Docker available as alternative |
| Hardware | CPU or NVIDIA GPU + CUDA CuDNN | GPU strongly recommended for training |
| Python | 3.11 | Pinned in environment.yml |
| CUDA | 12.1 (via pytorch-cuda) | Only required for GPU execution |
| Disk | ~5GB for environment + dataset storage | Datasets vary in size (e.g., horse2zebra ~111MB) |
Dependencies
System Packages
- conda (Miniconda or Anaconda)
- CUDA toolkit 12.1 (for GPU execution)
- CuDNN (bundled with PyTorch conda package)
Python Packages
- `torch` = 2.4.0
- `torchvision` = 0.19.0
- `numpy` = 1.24.3
- `scikit-image`
- `Pillow` >= 10.0.0
- `dominate` >= 2.8.0
- `wandb` >= 0.16.0 (optional, for logging)
Credentials
The following environment variables are optional:
- `WANDB_API_KEY`: Weights & Biases API key, required only when using --use_wandb flag for training visualization.
Quick Install
# Option 1: Conda (recommended)
conda env create -f environment.yml
conda activate pytorch-img2img
# Option 2: Pip (minimal)
pip install torch==2.4.0 torchvision==0.19.0 numpy==1.24.3 Pillow>=10.0.0 dominate>=2.8.0 wandb>=0.16.0 scikit-image
Code Evidence
Device initialization from `util/util.py:52-69`:
def init_ddp():
is_ddp = "WORLD_SIZE" in os.environ and int(os.environ["WORLD_SIZE"]) > 1
if is_ddp:
if not dist.is_initialized():
dist.init_process_group(backend="nccl")
local_rank = int(os.environ["LOCAL_RANK"])
device = torch.device(f"cuda:{local_rank}")
torch.cuda.set_device(local_rank)
elif torch.cuda.is_available():
device = torch.device("cuda:0")
torch.cuda.set_device(0)
else:
device = torch.device("cpu")
return device
Test-time device selection from `test.py:47`:
opt.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
Optional wandb import with graceful fallback from `test.py:39-42`:
try:
import wandb
except ImportError:
print('Warning: wandb package cannot be found. The option "--use_wandb" will result in error.')
PyTorch version requirement stated in `README.md:19`:
**Note**: The current software works well with PyTorch 2.4+.
Conda environment specification from `environment.yml`:
name: pytorch-img2img
channels:
- pytorch
- conda-forge
- nvidia
dependencies:
- python=3.11
- pytorch=2.4.0
- torchvision=0.19.0
- pytorch-cuda=12.1
- numpy=1.24.3
- scikit-image
- pip:
- dominate>=2.8.0
- Pillow>=10.0.0
- wandb>=0.16.0
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `TypeError: Object of type 'Tensor' is not JSON serializable` | PyTorch version too old (< 2.4) | Upgrade to PyTorch 2.4+ |
| `Warning: wandb package cannot be found` | wandb not installed | `pip install wandb` or remove `--use_wandb` flag |
| `NotSupportedError: slicing multiple dimensions` | torchvision/pytorch version mismatch | Reinstall matching torchvision for your PyTorch version |
| `My PyTorch errors on CUDA related code` | PyTorch not built with CUDA | Reinstall PyTorch with CUDA support, or use `--gpu_ids -1` for CPU |
Compatibility Notes
- macOS: CPU-only execution; no CUDA support available.
- Docker: Pre-built image available at `taesungp/pytorch-cyclegan-and-pix2pix`. Requires nvidia-docker for GPU support.
- CPU mode: Set `--gpu_ids -1` to run without GPU. Training will be very slow but functional.
- Legacy PyTorch: For PyTorch 0.1-0.3, use the `pytorch0.3.1` branch instead.
Related Pages
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_TrainOptions_Parse
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_CycleGANModel_Optimize_Parameters
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Pix2PixModel_Optimize_Parameters
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Visualizer
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_TestModel_Forward
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Create_Dataset
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_HTML_Gallery
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Define_G_and_D
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_ImagePool_Query
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Save_Images
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_TestOptions_Parse
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Download_Dataset
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Combine_A_and_B
- Implementation:Junyanz_Pytorch_CycleGAN_and_pix2pix_Download_Pretrained_Model