Skip to main content

ImageReward

Project description

ImageReward-Pypi

ImageReward is the first general-purpose text-to-image human preference RM which is trained on in total 137k pairs of expert comparisons, based on text prompts and corresponding model outputs from DiffusionDB. We demonstrate that ImageReward outperforms existing text-image scoring methods, such as CLIP, Aesthetic, and BLIP, in terms of understanding human preference in text-to-image synthesis through extensive analysis and experiments.

Usage

import os
import torch
import ImageReward as reward

if __name__ == "__main__":
    prompt = "a painting of an ocean with clouds and birds, day time, low depth field effect"
    img_prefix = "assets/images"
    generations = [f"{pic_id}.webp" for pic_id in range(1, 5)]
    img_list = [os.path.join(img_prefix, img) for img in generations]
    model = reward.load()
    with torch.no_grad():
        ranking, rewards = model.inference_rank(prompt, img_list)
        # Print the result
        print("\nPreference predictions:\n")
        print(f"ranking = {ranking}")
        print(f"rewards = {rewards}")
        for index in range(len(img_list)):
            score = model.score(prompt, img_list[index])
            print(f"{generations[index]:>16s}: {score:.2f}")

The output will look like the following (the exact numbers may be slightly different depending on the compute device):

Preference 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image-reward-0.92.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

image_reward-0.92-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file image-reward-0.92.tar.gz.

File metadata

  • Download URL: image-reward-0.92.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for image-reward-0.92.tar.gz
Algorithm Hash digest
SHA256 8b11ae58a01a95a3d5f78e569a500b1ab3b9aa8653040427a626f8d48f5be047
MD5 47c16d164e181096383eed5557a15232
BLAKE2b-256 dd47cb7539ab34e0c728acbd07ef67066b8867db7910283cad2a415217acb03f

See more details on using hashes here.

File details

Details for the file image_reward-0.92-py3-none-any.whl.

File metadata

  • Download URL: image_reward-0.92-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.16

File hashes

Hashes for image_reward-0.92-py3-none-any.whl
Algorithm Hash digest
SHA256 a412fdae56471cc2178d7b89c8213a7fdcd75930030ea9e66b35da9aca6497dd
MD5 16a644ecf8e48d1be1d9b75430ce217c
BLAKE2b-256 34bcdf7bb6dfe3a973493e729853f8c0cf4120e9110fa889cda28162b08aee3c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page