Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- microsoft/git-base-coco
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
Given a photo of a face, will describe it.
|
| 10 |
+
Be careful as it can be unflattering.
|
| 11 |
+
|
| 12 |
+
Based on the GIT-Base-COCO image to text model and fine-tuned on [Face2Text](https://zenodo.org/records/10973388).
|
| 13 |
+
|
| 14 |
+
How to use:
|
| 15 |
+
```
|
| 16 |
+
from transformers import AutoProcessor, AutoModelForCausalLM, AutoTokenizer
|
| 17 |
+
import cv2
|
| 18 |
+
|
| 19 |
+
DEVICE = 'cpu' # cpu or cuda
|
| 20 |
+
IMG_PATH = 'face.png'
|
| 21 |
+
|
| 22 |
+
processor = AutoProcessor.from_pretrained('microsoft/git-base-coco')
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained('mtanti/face-describer')
|
| 24 |
+
tokeniser = AutoTokenizer.from_pretrained('microsoft/git-base-coco')
|
| 25 |
+
model.eval()
|
| 26 |
+
model.to(DEVICE)
|
| 27 |
+
|
| 28 |
+
img = cv2.imread(IMG_PATH)
|
| 29 |
+
tensor_img = processor(
|
| 30 |
+
images=[img[:, :, ::-1]],
|
| 31 |
+
return_tensors='pt',
|
| 32 |
+
)['pixel_values'].to(DEVICE)
|
| 33 |
+
desc = tokeniser.decode(
|
| 34 |
+
model.generate(pixel_values=tensor_img, max_length=100, repetition_penalty=1.05, do_sample=True)[0, :],
|
| 35 |
+
skip_special_tokens=True,
|
| 36 |
+
)
|
| 37 |
+
```
|