Views
No views yet

image-reward. Following the commands below to prepare the environment:1# Clone the ImageReward repository (containing data for testing)
2git clone https://github.com/THUDM/ImageReward.git
3cd ImageReward
4
5# Install the integrated package `image-reward`
6pip install image-rewardassets/images directory of this repo. The example prompt is:a painting of an ocean with clouds and birds, day time, low depth field effect1import os
2import torch
3import ImageReward as reward
4
5if __name__ == "__main__":
6 prompt = "a painting of an ocean with clouds and birds, day time, low depth field effect"
7 img_prefix = "assets/images"
8 generations = [f"{pic_id}.webp" for pic_id in range(1, 5)]
9 img_list = [os.path.join(img_prefix, img) for img in generations]
10 model = reward.load("ImageReward-v1.0")
11 with torch.no_grad():
12 ranking, rewards = model.inference_rank(prompt, img_list)
13 # Print the result
14 print("\nPreference predictions:\n")
15 print(f"ranking = {ranking}")
16 print(f"rewards = {rewards}")
17 for index in range(len(img_list)):
18 score = model.score(prompt, img_list[index])
19 print(f"{generations[index]:>16s}: {score:.2f}")
20Preference predictions:
ranking = [1, 2, 3, 4]
rewards = [[0.5811622738838196], [0.2745276093482971], [-1.4131819009780884], [-2.029569625854492]]
1.webp: 0.58
2.webp: 0.27
3.webp: -1.41
4.webp: -2.03@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}
}