Upload folder using huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
pipeline_tag: image-text-to-text
|
| 7 |
+
tags:
|
| 8 |
+
- art
|
| 9 |
+
- autoquant
|
| 10 |
+
- gguf
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Fine-tuned version of PaliGemma 224x224 on image-prompt pairs.
|
| 14 |
+
|
| 15 |
+
```
|
| 16 |
+
pip install git+https://github.com/huggingface/transformers
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
|
| 21 |
+
from PIL import Image
|
| 22 |
+
import requests
|
| 23 |
+
import torch
|
| 24 |
+
|
| 25 |
+
model_id = "gokaygokay/SDXL-Captioner"
|
| 26 |
+
|
| 27 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
|
| 28 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 29 |
+
|
| 30 |
+
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id).to('cuda').eval()
|
| 31 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 32 |
+
|
| 33 |
+
## prefix
|
| 34 |
+
prompt = "caption en"
|
| 35 |
+
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to('cuda')
|
| 36 |
+
input_len = model_inputs["input_ids"].shape[-1]
|
| 37 |
+
|
| 38 |
+
with torch.inference_mode():
|
| 39 |
+
generation = model.generate(**model_inputs, repetition_penalty=1.10, max_new_tokens=256, do_sample=False)
|
| 40 |
+
generation = generation[0][input_len:]
|
| 41 |
+
decoded = processor.decode(generation, skip_special_tokens=True)
|
| 42 |
+
print(decoded)
|
| 43 |
+
|
| 44 |
+
```
|