shauray commited on
Commit
74b3107
1 Parent(s): 93674c9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -8
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, LlavaLlamaForCausalLM
 
 
 
53
 
54
- PATH_TO_CONVERTED_WEIGHTS = "shauray/Llava-Llama-2-13B-hf"
55
 
56
- model = LlavaLlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
57
- processor = LlavaProcessor.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
 
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 would you best describe the image given?"
62
- inputs = processor(text=prompt, images=image, return_tensors="pt")
63
 
 
 
64
  # Generate
65
- generate_ids = model.generate(**inputs, max_length=30)
66
- tokenizer.batch_decode(generate_ids, skip_special_tokens=True)[0]
 
 
 
 
 
 
 
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"""