### Install CycleReward with pip Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Installs the cyclereward package from PyPI. ```bash pip install cyclereward ``` -------------------------------- ### Clone repository and install dependencies Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Clones the CycleReward repository, creates a conda environment named 'crwd' with Python 3.10, and installs the required dependencies. ```bash git clone https://github.com/hjbahng/cyclereward.git cd cyclereward conda create -n crwd python=3.10 conda activate crwd pip install -r requirements.txt ``` -------------------------------- ### Build preference dataset from cycle consistency scores Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Run make_dataset.py after generation to create the preference dataset for reward model training. Use the same --output_path and --cycle as in generation, and specify the destination with --save_path. ```bash python make_dataset.py \ --output_path /path/to/save/results \ --dataset DCI \ --cycle i2t2i \ --save_path /path/to/save/preference_dataset ``` -------------------------------- ### Format input data for image-to-text and text-to-image generation Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Prepare unpaired data for cycle consistency generation. Use image_dataset for image-to-text and text_dataset for text-to-image tasks. Each entry requires a 'real_image' or 'real_text' key respectively. ```python # for image-to-text generation image_dataset = [{'real_image': image_path}, ...] # for text-to-image generation text_dataset = [{'real_text': caption}, ...] ``` -------------------------------- ### Load CyclePrefDB dataset Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Loads the CyclePrefDB-I2T dataset from Hugging Face using the datasets library. ```python from datasets import load_dataset dataset = load_dataset("carolineec/CyclePrefDB-I2T") ``` -------------------------------- ### Generate cycle consistency scores with LLaVA-1.5-13B and Stable Diffusion 3 Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Run generate.py to produce cycle consistency scores for comparison pairs. Specify the forward (I2T) model with --model_name_or_path and the backward (T2I) model with --pretrained_model_name_or_path. Repeat for multiple forward models to build comparison pairs. ```bash python generate.py \ --cycle i2t2i \ --model_name_or_path llava-hf/llava-1.5-13b-hf \ --pretrained_model_name_or_path stabilityai/stable-diffusion-3-medium-diffusers \ --dataset DCI \ --data_path /path/to/densely_captioned_images \ --output_path /path/to/save/results \ --cache_dir /path/to/download/models ``` -------------------------------- ### Measure image-caption alignment with CycleReward Source: https://github.com/hjbahng/cyclereward/blob/main/README.md Loads the CycleReward-Combo model and scores the alignment between an image and a caption. Uses CUDA if available. The score is higher for better alignment. ```python from cyclereward import cyclereward from PIL import Image import torch device = "cuda" if torch.cuda.is_available() else "cpu" model, preprocess = cyclereward(device=device, model_type="CycleReward-Combo") caption = "a photo of a cat" image = preprocess(Image.open("cat.jpg")).unsqueeze(0).to(device) score = model.score(image, caption) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.