HuggingFace镜像/PickScore_v1
模型介绍
文件和版本
分析

PickScore v1 模型卡片

本模型是一个针对文本生成图像的评分函数。它接收一个提示词和一张生成图像作为输入,并输出相应的评分分数。 该模型可用作通用评分函数,适用于人类偏好预测、模型评估、图像排序等多种任务。 更多技术细节请参阅我们的论文《Pick-a-Pic: 文本生成图像用户偏好开放数据集》。

模型详情

模型描述

本模型基于CLIP-H架构,使用Pick-a-Pic数据集进行微调训练。

模型来源 [可选]

  • 代码仓库: 访问PickScore代码库
  • 研究论文: Pick-a-Pic: 文本生成图像用户偏好开放数据集
  • 演示demo [可选]: PickScore的Huggingface Spaces演示

快速开始

使用以下代码即可快速启用本模型。

# 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 数据集 进行训练。

训练流程

待补充 - 添加论文说明。

引用声明 [可选]

若认为本研究成果对您有帮助,请引用:

@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:

[需要更多信息]