Update README.md
Browse files
README.md
CHANGED
|
@@ -1,6 +1,63 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
## Citation Information
|
| 5 |
If you find this work useful, we would be grateful if you consider citing the following papers:
|
| 6 |
```bibtex
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
---
|
| 4 |
+
## Inference
|
| 5 |
+
Our models are established on top of the Qwen2.5-VL family. So we include a simple use case here, and refer the readers to [the standard inference procedure of Qwen2.5-VL](https://github.com/QwenLM/Qwen2.5-VL).
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 10 |
+
from qwen_vl_utils import process_vision_info
|
| 11 |
+
|
| 12 |
+
# default: Load the model on the available device(s)
|
| 13 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 14 |
+
"Reallm-Labs/Infi-MMR-3B", torch_dtype="auto", device_map="auto"
|
| 15 |
+
)
|
| 16 |
+
min_pixels = 256*28*28
|
| 17 |
+
max_pixels = 1280*28*28
|
| 18 |
+
processor = AutoProcessor.from_pretrained("Reallm-Labs/Infi-MMR-3B", min_pixels=min_pixels, max_pixels=max_pixels)
|
| 19 |
+
|
| 20 |
+
messages = [
|
| 21 |
+
{
|
| 22 |
+
"role": "user",
|
| 23 |
+
"content": [
|
| 24 |
+
{
|
| 25 |
+
"type": "image",
|
| 26 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
| 27 |
+
},
|
| 28 |
+
{"type": "text", "text": "Describe this image."},
|
| 29 |
+
],
|
| 30 |
+
}
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
# Preparation for inference
|
| 34 |
+
text = processor.apply_chat_template(
|
| 35 |
+
messages, tokenize=False, add_generation_prompt=True
|
| 36 |
+
)
|
| 37 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 38 |
+
inputs = processor(
|
| 39 |
+
text=[text],
|
| 40 |
+
images=image_inputs,
|
| 41 |
+
videos=video_inputs,
|
| 42 |
+
padding=True,
|
| 43 |
+
return_tensors="pt",
|
| 44 |
+
)
|
| 45 |
+
inputs = inputs.to(model.device)
|
| 46 |
+
|
| 47 |
+
# Inference: Generation of the output
|
| 48 |
+
generated_ids = model.generate(**inputs, max_new_tokens=4096)
|
| 49 |
+
generated_ids_trimmed = [
|
| 50 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 51 |
+
]
|
| 52 |
+
output_text = processor.batch_decode(
|
| 53 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
| 54 |
+
)
|
| 55 |
+
print(output_text)
|
| 56 |
+
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
## Citation Information
|
| 62 |
If you find this work useful, we would be grateful if you consider citing the following papers:
|
| 63 |
```bibtex
|