prithivMLmods commited on
Commit
43aaefc
·
verified ·
1 Parent(s): 210ac96

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +101 -0
README.md CHANGED
@@ -17,6 +17,8 @@ tags:
17
  ---
18
  ### Qwen2-VL-OCR-2B-Instruct
19
 
 
 
20
  | **File Name** | **Size** | **Description** | **Upload Status** |
21
  |---------------------------|------------|------------------------------------------------|-------------------|
22
  | `.gitattributes` | 1.52 kB | Configures LFS tracking for specific model files. | Initial commit |
@@ -31,3 +33,102 @@ tags:
31
  | `vocab.json` | 2.78 MB | Vocabulary file for tokenization. | Uploaded |
32
 
33
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ---
18
  ### Qwen2-VL-OCR-2B-Instruct
19
 
20
+ The **Qwen2-VL-OCR-2B-Instruct** model is a fine-tuned version of **Qwen/Qwen2-VL-2B-Instruct**, tailored for tasks that involve **Optical Character Recognition (OCR)**, **image-to-text conversion**, and **math problem solving with LaTeX formatting**. This model integrates a conversational approach with visual and textual understanding to handle multi-modal tasks effectively.
21
+
22
  | **File Name** | **Size** | **Description** | **Upload Status** |
23
  |---------------------------|------------|------------------------------------------------|-------------------|
24
  | `.gitattributes` | 1.52 kB | Configures LFS tracking for specific model files. | Initial commit |
 
33
  | `vocab.json` | 2.78 MB | Vocabulary file for tokenization. | Uploaded |
34
 
35
  ---
36
+ ### How to Use
37
+
38
+ ```python
39
+ from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
40
+ from qwen_vl_utils import process_vision_info
41
+
42
+ # default: Load the model on the available device(s)
43
+ model = Qwen2VLForConditionalGeneration.from_pretrained(
44
+ "Qwen/Qwen2-VL-2B-Instruct", torch_dtype="auto", device_map="auto"
45
+ )
46
+
47
+ # We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
48
+ # model = Qwen2VLForConditionalGeneration.from_pretrained(
49
+ # "Qwen/Qwen2-VL-2B-Instruct",
50
+ # torch_dtype=torch.bfloat16,
51
+ # attn_implementation="flash_attention_2",
52
+ # device_map="auto",
53
+ # )
54
+
55
+ # default processer
56
+ processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
57
+
58
+ # The default range for the number of visual tokens per image in the model is 4-16384. You can set min_pixels and max_pixels according to your needs, such as a token count range of 256-1280, to balance speed and memory usage.
59
+ # min_pixels = 256*28*28
60
+ # max_pixels = 1280*28*28
61
+ # processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
62
+
63
+ messages = [
64
+ {
65
+ "role": "user",
66
+ "content": [
67
+ {
68
+ "type": "image",
69
+ "image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
70
+ },
71
+ {"type": "text", "text": "Describe this image."},
72
+ ],
73
+ }
74
+ ]
75
+
76
+ # Preparation for inference
77
+ text = processor.apply_chat_template(
78
+ messages, tokenize=False, add_generation_prompt=True
79
+ )
80
+ image_inputs, video_inputs = process_vision_info(messages)
81
+ inputs = processor(
82
+ text=[text],
83
+ images=image_inputs,
84
+ videos=video_inputs,
85
+ padding=True,
86
+ return_tensors="pt",
87
+ )
88
+ inputs = inputs.to("cuda")
89
+
90
+ # Inference: Generation of the output
91
+ generated_ids = model.generate(**inputs, max_new_tokens=128)
92
+ generated_ids_trimmed = [
93
+ out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
94
+ ]
95
+ output_text = processor.batch_decode(
96
+ generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
97
+ )
98
+ print(output_text)
99
+ ```
100
+
101
+ ### **Key Features**
102
+
103
+ 1. **Vision-Language Integration:**
104
+ - Combines **image understanding** with **natural language processing** to convert images into text.
105
+
106
+ 2. **Optical Character Recognition (OCR):**
107
+ - Extracts and processes textual information from images with high accuracy.
108
+
109
+ 3. **Math and LaTeX Support:**
110
+ - Solves math problems and outputs equations in **LaTeX format**.
111
+
112
+ 4. **Conversational Capabilities:**
113
+ - Designed to handle **multi-turn interactions**, providing context-aware responses.
114
+
115
+ 5. **Image-Text-to-Text Generation:**
116
+ - Inputs can include **images, text, or a combination**, and the model generates descriptive or problem-solving text.
117
+
118
+ 6. **Secure Weight Format:**
119
+ - Uses **Safetensors** for faster and more secure model weight loading.
120
+
121
+ ---
122
+
123
+ ### **Training Details**
124
+
125
+ - **Base Model:** [Qwen/Qwen2-VL-2B-Instruct](#)
126
+ - **Model Size:**
127
+ - 2.21 Billion parameters
128
+ - Optimized for **BF16** tensor type, enabling efficient inference.
129
+
130
+ - **Specializations:**
131
+ - OCR tasks in images containing text.
132
+ - Mathematical reasoning and LaTeX output for equations.
133
+
134
+ ---