本文记录可直接 follow 不报错 的常用文生图模型 benchmark 安装指南。
GenEval
论文 |官方仓库 af4902f |重要参考 issue#12
环境设置
1、创建 conda 环境:
1 2 conda create -n geneval -y python=3.8.10 conda activate geneval
2、安装 torch 依赖:
1 pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu121
3、安装其他依赖:
1 2 3 4 5 6 7 8 9 10 pip install networkx==2.8.8 pip install open-clip-torch==2.26.1 pip install clip-benchmark pip install -U openmim pip install einops python -m pip install lightning pip install diffusers transformers pip install tomli pip install platformdirs pip install setuptools==60.2.0
4、安装 mmcv 依赖:
1 mim install mmengine mmcv-full==1.7.2
5、安装 mmdet 依赖:
1 2 3 4 git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection git checkout 2.x pip install -v -e .
运行测试
1、Clone 仓库:
1 2 git clone https://github.com/djghosh13/geneval.git cd geneval
2、下载 Mask2Former 目标检测器:
1 ./evaluation/download_models.sh ./object_detector
3、下载 CLIP ViT-L/14,直接在终端开启一个 Python 交互界面执行以下代码:
1 2 import open_clip open_clip.create_model_and_transforms("ViT-L-14" , pretrained="openai" , device="cpu" )
4、生成图像:从 ./prompts/evaluation_metadata.jsonl 中逐行读取 prompt,生成 4 张图像,并按以下格式存储,其中 metadata.jsonl 包含上述 prompt 文件的对应行:
1 2 3 4 5 6 7 8 9 10 11 <IMAGE_FOLDER> ├── 00000 │ ├── metadata.jsonl │ └── samples │ ├── 0000.png │ ├── 0001.png │ ├── 0002.png │ └── 0003.png ├── 00001 │ └── ... └── ...
5、运行评测:
1 python evaluation/evaluate_images.py "<IMAGE_FOLDER>" --outfile "<RESULTS_FOLDER>/results.jsonl" --model-path ./object_detector
6、获取最终得分:
1 python evaluation/summary_scores.py "<RESULTS_FOLDER>/results.jsonl"
DPG-Bench
论文 |官方仓库 3c228f1 |重要参考 issue#65
环境设置
1、创建 conda 环境:
1 2 conda create -n dpg python=3.13 -y conda activate dpg
2、安装 torch 依赖:
1 pip install torch==2.11.0 torchvision==0.26.0 torchaudio==2.11.0 --index-url https://download.pytorch.org/whl/cu126
3、创建 requirements-for-dpg_bench-issues65.txt 写入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 accelerate==1.10.1 addict==2.4.0 cloudpickle==3.1.1 datasets==2.21.0 decord==0.6.0 diffusers==0.35.1 # fairseq==0.12.2 ftfy==6.0.3 librosa==0.10.1 modelscope==1.30.0 numpy==2.3.3 opencv-python==4.11.0.86 pandas==2.3.2 pillow==11.3.0 rapidfuzz==3.14.1 rouge-score<=0.0.4 safetensors==0.6.2 simplejson==3.20.1 sortedcontainers==2.4.0 soundfile==0.13.1 taming-transformers-rom1504==0.0.6 tiktoken==0.11.0 timm==1.0.19 tokenizers==0.22.1 tqdm==4.67.1 transformers==4.56.2 transformers-stream-generator==0.0.5 unicodedata2==16.0.0 zhconv==1.4.3
从该 txt 文件安装依赖:
1 pip install -r requirements-for-dpg_bench-issues65.txt
4、安装 fairseq 依赖:
1 pip install git+https://github.com/One-sixth/fairseq.git
运行测试
1、Clone 仓库:
1 2 git clone https://github.com/TencentQQGYLab/ELLA.git cd ELLA
2、下载 mPLUG VQA 模型,直接在终端开启一个 Python 交互界面执行以下代码:
1 2 3 4 from modelscope.pipelines import pipelinefrom modelscope.utils.constant import Tasks ckpt = "damo/mplug_visual-question-answering_coco_large_en" pipeline(Tasks.visual_question_answering, model=ckpt, device="cpu" )
3、生成图像:对仓库中 ./dpg_bench/prompts 内的每个 prompt,生成 4 张图并按 2x2 格子拼成一张大图,图像文件名应与 prompt 的 txt 文件名相同。
4、运行评测(N 为 GPU 数量):
1 PROCESSES=N bash dpg_bench/dist_eval.sh $YOUR_IMAGE_PATH $RESOLUTION
HPSv2
论文 |官方仓库 866735e |重要参考 issue#30
环境设置
1、创建 conda 环境:
1 2 conda create -n hpsv2 python=3.10 -y conda activate hpsv2
2、安装 torch 依赖(官方没有明确版本,其他版本可能也可以):
1 pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124
3、安装 hpsv2x 库(这是官方 hpsv2 库的修正版本,修正了 BPE 文件缺失问题):
1 pip install hpsv2x==1.2.0
运行测试
1、下载测试 prompt:
1 hf download zhwang/HPDv2 --include "benchmark/*.json" --repo-type dataset
2、生成图像:通过 hpsv2 库获取所有 prompt,按照 image_path/style/idx.jpg 的格式存储,参考代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 import osimport hpsv2 all_prompts = hpsv2.benchmark_prompts("all" )for style, prompts in all_prompts.items(): for idx, prompt in enumerate (prompts): image = TextToImageModel(prompt) image.save(os.path.join("<image_path>" , style, f"{idx:05d} .jpg" ))
3、运行评测:
1 2 3 4 5 import hpsv2 hpsv2.evaluate("<images_path>" , hps_version="<hps_version>" )
ImageReward
论文 |官方仓库 78f8051
环境设置
1 2 3 4 5 6 pip install "timm>=0.6.13" pip install "transformers>=4.27.4" pip install "datasets==4.0.0" pip install "fairscale>=0.4.13" pip install "huggingface_hub>=0.13.4" pip install "clip @ git+https://github.com/openai/CLIP.git"
运行测试
1、Clone 仓库:
1 2 git clone https://github.com/zai-org/ImageReward.git cd ImageReward
2、从 benchmark/benchmark-prompts.json 中逐行读取 prompt,生成 10 张图像,并按以下格式存储:
1 2 3 4 5 6 7 8 9 <IMG_DIR> └──<MODEL_NAME> ├──000246-0117_0.png ├──... ├──000246-0117_9.png ├──000304-0153_0.png ├──... ├──000304-0153_9.png └──...
3、运行评测,其中 <RESULT_DIR> 指保存评测结果的目录:
1 python test-benchmark.py --benchmark ImageReward-v1.0 --img_dir <IMG_DIR> --model <MODEL_NAME> --result_dir <RESULT_DIR>