模型:

yuvalkirstain/PickScore_v1

英文

PickScore v1 模型卡片

该模型是一个用于文本生成图片的评分函数。它以提示和生成的图片作为输入,并输出一个得分。它可以用作通用的评分函数,用于人类偏好预测、模型评估、图片排序等任务。有关更多详细信息,请参阅我们的论文 Pick-a-Pic: An Open Dataset of User Preferences for Text-to-Image Generation

模型细节

模型描述

该模型是使用 Pick-a-Pic dataset 对 CLIP-H 进行微调而得到的。

模型来源[可选]

如何开始使用模型

使用下面的代码来开始使用该模型。

# import
from transformers import AutoProcessor, AutoModel

# load model
device = "cuda"
processor_name_or_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
model_pretrained_name_or_path = "yuvalkirstain/PickScore_v1"

processor = AutoProcessor.from_pretrained(processor_name_or_path)
model = AutoModel.from_pretrained(model_pretrained_name_or_path).eval().to(device)

def calc_probs(prompt, images):
    
    # preprocess
    image_inputs = processor(
        images=images,
        padding=True,
        truncation=True,
        max_length=77,
        return_tensors="pt",
    ).to(device)
    
    text_inputs = processor(
        text=prompt,
        padding=True,
        truncation=True,
        max_length=77,
        return_tensors="pt",
    ).to(device)


    with torch.no_grad():
        # embed
        image_embs = model.get_image_features(**image_inputs)
        image_embs = image_embs / torch.norm(image_embs, dim=-1, keepdim=True)
    
        text_embs = model.get_text_features(**text_inputs)
        text_embs = text_embs / torch.norm(text_embs, dim=-1, keepdim=True)
    
        # score
        scores = model.logit_scale.exp() * (text_embs @ image_embs.T)[0]
        
        # get probabilities if you have multiple images to choose from
        probs = torch.softmax(scores, dim=-1)
    
    return probs.cpu().tolist()

pil_images = [Image.open("my_amazing_images/1.jpg"), Image.open("my_amazing_images/2.jpg")]
prompt = "fantastic, increadible prompt"
print(calc_probs(prompt, pil_images))

训练细节

训练数据

该模型是在 Pick-a-Pic dataset 上训练的。

训练过程

TODO - 添加论文。

引用[可选]

如果您发现这个工作有用,请引用:

@inproceedings{Kirstain2023PickaPicAO,
  title={Pick-a-Pic: An Open Dataset of User Preferences for Text-to-Image Generation},
  author={Yuval Kirstain and Adam Polyak and Uriel Singer and Shahbuland Matiana and Joe Penna and Omer Levy},
  year={2023}
}

APA:

[需要更多信息]