update for chat template
Browse files
README.md
CHANGED
@@ -115,6 +115,27 @@ output = model.generate(**inputs_video, max_new_tokens=100, do_sample=False)
|
|
115 |
print(processor.decode(output[0][2:], skip_special_tokens=True))
|
116 |
```
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
### Inference with images as inputs
|
119 |
|
120 |
To generate from images use the below code after loading the model as shown above:
|
|
|
115 |
print(processor.decode(output[0][2:], skip_special_tokens=True))
|
116 |
```
|
117 |
|
118 |
+
-----------
|
119 |
+
From transformers>=v4.48, you can also pass image/video url or local path to the conversation history, and let the chat template handle the rest.
|
120 |
+
For video you also need to indicate how many `num_frames` to sample from video, otherwise the whole video will be loaded.
|
121 |
+
Chat template will load the image/video for you and return inputs in `torch.Tensor` which you can pass directly to `model.generate()`.
|
122 |
+
|
123 |
+
```python
|
124 |
+
messages = [
|
125 |
+
{
|
126 |
+
"role": "user",
|
127 |
+
"content": [
|
128 |
+
{"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
|
129 |
+
{"type": "video", "path": "my_video.mp4"},
|
130 |
+
{"type": "text", "text": "What is shown in this image and video?"},
|
131 |
+
],
|
132 |
+
},
|
133 |
+
]
|
134 |
+
|
135 |
+
inputs = processor.apply_chat_template(messages, num_frames=8, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors"pt")
|
136 |
+
output = model.generate(**inputs, max_new_tokens=50)
|
137 |
+
```
|
138 |
+
|
139 |
### Inference with images as inputs
|
140 |
|
141 |
To generate from images use the below code after loading the model as shown above:
|