【图像生成模型评价指标】-- HPS及实践
一、用HPS V2给模型生成的图片打分测试
Step1: 在本地通过git和pip安装HPS V2
git clone https://github.com/tgxs002/HPSv2.git
cd HPSv2 && python -m pip install .
Step2: 加载模型和图像进行测试(我这里抽取了test中的前八张,用对应的prompt进行了测试)
import hpsv2
imgs_path = ["/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00000.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00001.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00002.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00003.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00004.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00005.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00006.jpg",
"/content/drive/MyDrive/ColabNotebooks/GenerateModelMetrix/HPSv2/hpsv2/tests/my_test/test/00007.jpg"]
prompt = 'Dwayne the Rock Johnson wrestles Jesus Christ in a WWE match in a hell in a cell'
result = hpsv2.score(imgs_path,prompt)
# print(result)
enum_list = list(enumerate(result))
# 使用lambda函数对元素进行排序,基于元素的值
sorted_enum_list = sorted(enum_list, key=lambda x: x[1])
# 输出排序后的元素的下标
for index, value in sorted_enum_list:
print(f"Value: {value}, Index: {index}")
测试图片:
Step3: 测试结果
Value: 0.18597152829170227, Index: 5
Value: 0.21305252611637115, Index: 4
Value: 0.21651141345500946, Index: 0
Value: 0.2222018837928772, Index: 3
Value: 0.22932952642440796, Index: 7
Value: 0.23164474964141846, Index: 1
Value: 0.2394677996635437, Index: 2
Value: 0.24284183979034424, Index: 6
也就是说,认为与prompt最匹配的依次是图6、2、1、7、3、0、4、5。
和我的判断基本符合。