Update README.md
Browse files
README.md
CHANGED
@@ -49,21 +49,33 @@ See https://llava-vl.github.io/ for more details.
|
|
49 |
usage is as follows
|
50 |
|
51 |
```python
|
52 |
-
from transformers import LlavaProcessor,
|
|
|
|
|
|
|
53 |
|
54 |
-
PATH_TO_CONVERTED_WEIGHTS = "shauray/Llava-Llama-2-
|
55 |
|
56 |
-
model =
|
57 |
-
|
|
|
58 |
|
59 |
url = "https://llava-vl.github.io/static/images/view.jpg"
|
60 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
61 |
-
prompt = "How
|
62 |
-
inputs = processor(text=prompt, images=image, return_tensors="pt")
|
63 |
|
|
|
|
|
64 |
# Generate
|
65 |
-
generate_ids = model.generate(**inputs,
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
"""The photograph shows a wooden dock floating on the water, with mountains in the background. It is an idyllic scene that captures both
|
69 |
nature and human-made structures at their finest moments of beauty or tranquility depending upon one's perspective as they gaze into it"""
|
|
|
49 |
usage is as follows
|
50 |
|
51 |
```python
|
52 |
+
from transformers import LlavaProcessor, LlavaForCausalLM
|
53 |
+
from PIL import Image
|
54 |
+
import requests
|
55 |
+
import torch
|
56 |
|
57 |
+
PATH_TO_CONVERTED_WEIGHTS = "shauray/Llava-Llama-2-7B-hf"
|
58 |
|
59 |
+
model = LlavaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS,
|
60 |
+
device_map="cuda",torch_dtype=torch.float16).to("cuda")
|
61 |
+
processor = LlavaProcessor.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
|
62 |
|
63 |
url = "https://llava-vl.github.io/static/images/view.jpg"
|
64 |
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
65 |
+
prompt = "How can you best describe this image?"
|
|
|
66 |
|
67 |
+
inputs = processor(text=prompt, images=image, return_tensors="pt").to("cuda",
|
68 |
+
torch.float16)
|
69 |
# Generate
|
70 |
+
generate_ids = model.generate(**inputs,
|
71 |
+
do_sample=True,
|
72 |
+
max_length=1024,
|
73 |
+
temperature=0.1,
|
74 |
+
top_p=0.9,
|
75 |
+
)
|
76 |
+
out = processor.decode(generate_ids[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()
|
77 |
+
|
78 |
+
print(out)
|
79 |
|
80 |
"""The photograph shows a wooden dock floating on the water, with mountains in the background. It is an idyllic scene that captures both
|
81 |
nature and human-made structures at their finest moments of beauty or tranquility depending upon one's perspective as they gaze into it"""
|