Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
Part of Advanced NLP Project for Team Shrine - Adnan Qidwai, Harshit Karwal and Shrikara Arun.
|
5 |
+
CleanCaption is an image captioning model that forget an object from the image when generating the caption. It is a finetuned version of `microsoft/Florence-2-large-ft`.
|
6 |
+
|
7 |
+
Usage:
|
8 |
+
```python
|
9 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
10 |
+
from PIL import Image
|
11 |
+
import torch
|
12 |
+
|
13 |
+
device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
|
14 |
+
|
15 |
+
processor = AutoProcessor.from_pretrained("microsoft/Florence-2-large-ft", trust_remote_code=True)
|
16 |
+
model = AutoModelForCausalLM.from_pretrained(
|
17 |
+
"sudokara/CleanCaption",
|
18 |
+
trust_remote_code=True
|
19 |
+
).eval().to(device)
|
20 |
+
|
21 |
+
def forget(prompt, image_path):
|
22 |
+
image = Image.open(image_path).convert("RGB")
|
23 |
+
prompt = f"Forget from caption: {str(prompt)}".strip(' :')
|
24 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to(device)
|
25 |
+
generated_ids = model.generate(
|
26 |
+
input_ids=inputs["input_ids"],
|
27 |
+
pixel_values=inputs["pixel_values"],
|
28 |
+
max_new_tokens=1024,
|
29 |
+
do_sample=True,
|
30 |
+
num_beams=3,
|
31 |
+
)
|
32 |
+
return processor.decode(generated_ids[0]).replace('<s>', '').replace('</s>', '')
|
33 |
+
|
34 |
+
image_path = "image.png"
|
35 |
+
print(forget(image_path = image_path, prompt = "water"))
|
36 |
+
```
|