Image-Prompt Alignment¶
Eval Recipe for model migration¶
This Eval Recipe demonstrates how to use a prompt alignment autorater to compare image generation quality of two models (Imagen2 and Imagen3) using Vertex AI Evaluation Service.
-
Use case: Image Generation
-
We use a separate unlabeled dataset in JSONL format for each model:
dataset_imagen2.jsonl
anddataset_imagen3.jsonl
. Each record in these datasets includes 2 attributes:prompt
: full text of the image generation promptimage_path
: local path to the JPG image generated based on this prompt
-
The autorater instructions are stored in
autorater_instructions.txt
. These instructions are imported into the multiodal prompt templatesprompt_imagen2.yaml
andprompt_imagen3.yaml
that combine the images from our dataset with the autorater instructions. -
The evaluation is configured in
eval.py
:load_dataset
: loads the dataset including the images referenced from the JSONL file.image_prompt_alignment_autorater
: assembles the autorater prompt and runs inference in order to identify gaps between the prompt and the generated image and calculate the prompt alignment score.run_eval
: executes evalulation based on one dataset file.compare_models
: orchestrates evaluations for both models and prints the results.
-
Shell script
run.sh
installs the required Python libraries and runseval.py
How to run this Eval Recipe¶
-
Google Cloud Shell is the easiest option as it automatically clones our Github repo:
-
Alternatively, you can use the following command to clone this repo to any Linux environment with configured Google Cloud Environment:
git clone --filter=blob:none --sparse https://github.com/GoogleCloudPlatform/applied-ai-engineering-samples.git && \ cd applied-ai-engineering-samples && \ git sparse-checkout init && \ git sparse-checkout set genai-on-vertex-ai/gemini/model_upgrades && \ git pull origin main cd genai-on-vertex-ai/gemini/model_upgrades
-
Navigate to the Eval Recipe directory in terminal, set your Google Cloud Project ID and run the shell script
run.sh
. -
The resulting metrics will be displayed in the script output.
- You can use Vertex AI Experiments to view the history of evaluations for each experiment, including the final scores.
How to customize this Eval Recipe:¶
- Edit the Python script
eval.py
:- set the
project
parameter of vertexai.init to your Google Cloud Project ID. - configure a unique
experiment_name
for tracking purposes. - (optional) you can customize the autorater prompt located in the global variable
_AUTORATER_PROMPT_TEMPLATE
.
- set the
- Replace the contenx of the two JSONL files with your image generation prompts.
- Replace the generated images located in the
images
folder with images generated based on your prompts.