yuvalkirstain
commited on
Commit
•
5d7a24c
1
Parent(s):
4811ca8
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Model Card for Model ID
|
2 |
+
|
3 |
+
This model is a scoring function for images generated from text. It takes as input a prompt and a generated image and outputs a score.
|
4 |
+
It can be used a general scoring function, human preference prediction, model evaluation, image ranking, and more.
|
5 |
+
|
6 |
+
|
7 |
+
## Model Details
|
8 |
+
|
9 |
+
### Model Description
|
10 |
+
|
11 |
+
This model was finetuned from CLIP-H.
|
12 |
+
|
13 |
+
### Model Sources [optional]
|
14 |
+
|
15 |
+
<!-- Provide the basic links for the model. -->
|
16 |
+
|
17 |
+
- **Repository:** [See the PickScore repo](https://github.com/yuvalkirstain/PickScore)
|
18 |
+
- **Paper [optional]:** TODO
|
19 |
+
- **Demo [optional]:** TODO
|
20 |
+
|
21 |
+
## How to Get Started with the Model
|
22 |
+
|
23 |
+
Use the code below to get started with the model.
|
24 |
+
|
25 |
+
```python
|
26 |
+
# import
|
27 |
+
from transformers import AutoProcessor, AutoModel
|
28 |
+
|
29 |
+
# load model
|
30 |
+
device = "cuda"
|
31 |
+
processor_name_or_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
32 |
+
model_pretrained_name_or_path = "yuvalkirstain/PickScore_v1"
|
33 |
+
|
34 |
+
processor = AutoProcessor.from_pretrained(processor_name_or_path)
|
35 |
+
model = AutoModel.from_pretrained(model_pretrained_name_or_path).eval().to(device)
|
36 |
+
|
37 |
+
def calc_probs(prompt, images):
|
38 |
+
|
39 |
+
# preprocess
|
40 |
+
image_inputs = processor(
|
41 |
+
images=images,
|
42 |
+
padding=True,
|
43 |
+
truncation=True,
|
44 |
+
max_length=77,
|
45 |
+
return_tensors="pt",
|
46 |
+
).to(device)
|
47 |
+
|
48 |
+
text_inputs = processor(
|
49 |
+
text=prompt,
|
50 |
+
padding=True,
|
51 |
+
truncation=True,
|
52 |
+
max_length=77,
|
53 |
+
return_tensors="pt",
|
54 |
+
).to(device)
|
55 |
+
|
56 |
+
|
57 |
+
with torch.no_grad():
|
58 |
+
# embed
|
59 |
+
image_embs = model.get_image_features(**image_inputs)
|
60 |
+
image_embs = image_embs / torch.norm(image_embs, dim=-1, keepdim=True)
|
61 |
+
|
62 |
+
text_embs = model.get_text_features(**text_inputs)
|
63 |
+
text_embs = text_embs / torch.norm(text_embs, dim=-1, keepdim=True)
|
64 |
+
|
65 |
+
# score
|
66 |
+
scores = model.logit_scale.exp() * (text_embs @ image_embs.T)[0]
|
67 |
+
|
68 |
+
# get probabilities if you have multiple images to choose from
|
69 |
+
probs = torch.softmax(scores, dim=-1)
|
70 |
+
|
71 |
+
return probs.cpu().tolist()
|
72 |
+
|
73 |
+
pil_images = [Image.open("my_amazing_images/1.jpg"), Image.open("my_amazing_images/2.jpg")]
|
74 |
+
prompt = "fantastic, increadible prompt"
|
75 |
+
print(calc_probs(prompt, pil_images))
|
76 |
+
```
|
77 |
+
## Training Details
|
78 |
+
|
79 |
+
### Training Data
|
80 |
+
|
81 |
+
This model was trained on the [Pick-a-Pic dataset](https://huggingface.co/datasets/yuvalkirstain/pickapic_v1).
|
82 |
+
|
83 |
+
|
84 |
+
### Training Procedure
|
85 |
+
|
86 |
+
TODO - add paper.
|
87 |
+
|
88 |
+
|
89 |
+
## Citation [optional]
|
90 |
+
|
91 |
+
TODO add paper
|
92 |
+
|
93 |
+
**BibTeX:**
|
94 |
+
|
95 |
+
[More Information Needed]
|
96 |
+
|
97 |
+
**APA:**
|
98 |
+
|
99 |
+
[More Information Needed]
|
100 |
+
|
101 |
+
|