imagereward-evaluation / imagereward-evaluation.py
kenjiqq's picture
Upload 2 files
eab68ca
import datasets
import json
import json
import os
import datasets
_DESCRIPTION = """\
Dataset to perform Aesthetic evaluation from Table 2 in ImageReward: Learning and Evaluating Human Preferences for Text-to-Image Generation.
@misc{xu2023imagereward,
title={ImageReward: Learning and Evaluating Human Preferences for Text-to-Image Generation},
author={Jiazheng Xu and Xiao Liu and Yuchen Wu and Yuxuan Tong and Qinkai Li and Ming Ding and Jie Tang and Yuxiao Dong},
year={2023},
eprint={2304.05977},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
"""
class ImagerewardEvaluation(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
"id": datasets.Value("string"),
"prompt": datasets.Value("string"),
"generations": datasets.Sequence(datasets.Image()),
"ranking": datasets.Sequence(datasets.Value("int32")),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract("./test.json")
images = dl_manager.download_and_extract("./images.zip")
print(downloaded_files, images)
return [
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"metadata_path": downloaded_files, "images_path": os.path.join(images, "test_images")}),
]
def _generate_examples(self, metadata_path, images_path):
with open(metadata_path, encoding="utf-8") as f:
data = json.load(f)
for item in data:
yield item["id"], {
"id": item["id"],
"prompt": item["prompt"],
"generations": [os.path.join(images_path, x) for x in item["generations"]],
"ranking": item["ranking"],
}