Update README.md
Browse files
README.md
CHANGED
@@ -35,4 +35,129 @@ Radiology-Infer-Mini is a vision-language model fine-tuned from the Qwen2-VL-2B
|
|
35 |
5. **Multilingual Support for Medical Text**
|
36 |
Radiology-Infer-Mini supports the extraction and interpretation of multilingual texts embedded in radiological images, including English, Chinese, Arabic, Korean, Japanese, and most European languages. This feature ensures accessibility for a diverse global healthcare audience.
|
37 |
|
38 |
-
Radiology-Infer-Mini represents a transformative step in radiology-focused AI, enhancing productivity and accuracy in medical imaging and reporting.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
5. **Multilingual Support for Medical Text**
|
36 |
Radiology-Infer-Mini supports the extraction and interpretation of multilingual texts embedded in radiological images, including English, Chinese, Arabic, Korean, Japanese, and most European languages. This feature ensures accessibility for a diverse global healthcare audience.
|
37 |
|
38 |
+
Radiology-Infer-Mini represents a transformative step in radiology-focused AI, enhancing productivity and accuracy in medical imaging and reporting.
|
39 |
+
|
40 |
+
![radiology.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/S0JuOoKkXmXgj4li6a9OZ.png)
|
41 |
+
|
42 |
+
### How to Use
|
43 |
+
|
44 |
+
```python
|
45 |
+
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
|
46 |
+
from qwen_vl_utils import process_vision_info
|
47 |
+
|
48 |
+
# default: Load the model on the available device(s)
|
49 |
+
model = Qwen2VLForConditionalGeneration.from_pretrained(
|
50 |
+
"prithivMLmods/Radiology-Infer-Mini", torch_dtype="auto", device_map="auto"
|
51 |
+
)
|
52 |
+
|
53 |
+
# We recommend enabling flash_attention_2 for better acceleration and memory saving, especially in multi-image and video scenarios.
|
54 |
+
# model = Qwen2VLForConditionalGeneration.from_pretrained(
|
55 |
+
# "prithivMLmods/Radiology-Infer-Mini",
|
56 |
+
# torch_dtype=torch.bfloat16,
|
57 |
+
# attn_implementation="flash_attention_2",
|
58 |
+
# device_map="auto",
|
59 |
+
# )
|
60 |
+
|
61 |
+
# default processer
|
62 |
+
processor = AutoProcessor.from_pretrained("prithivMLmods/Radiology-Infer-Mini")
|
63 |
+
|
64 |
+
# 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.
|
65 |
+
# min_pixels = 256*28*28
|
66 |
+
# max_pixels = 1280*28*28
|
67 |
+
# processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct", min_pixels=min_pixels, max_pixels=max_pixels)
|
68 |
+
|
69 |
+
messages = [
|
70 |
+
{
|
71 |
+
"role": "user",
|
72 |
+
"content": [
|
73 |
+
{
|
74 |
+
"type": "image",
|
75 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
76 |
+
},
|
77 |
+
{"type": "text", "text": "Describe this image."},
|
78 |
+
],
|
79 |
+
}
|
80 |
+
]
|
81 |
+
|
82 |
+
# Preparation for inference
|
83 |
+
text = processor.apply_chat_template(
|
84 |
+
messages, tokenize=False, add_generation_prompt=True
|
85 |
+
)
|
86 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
87 |
+
inputs = processor(
|
88 |
+
text=[text],
|
89 |
+
images=image_inputs,
|
90 |
+
videos=video_inputs,
|
91 |
+
padding=True,
|
92 |
+
return_tensors="pt",
|
93 |
+
)
|
94 |
+
inputs = inputs.to("cuda")
|
95 |
+
|
96 |
+
# Inference: Generation of the output
|
97 |
+
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
98 |
+
generated_ids_trimmed = [
|
99 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
100 |
+
]
|
101 |
+
output_text = processor.batch_decode(
|
102 |
+
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
|
103 |
+
)
|
104 |
+
print(output_text)
|
105 |
+
```
|
106 |
+
### Buf
|
107 |
+
```python
|
108 |
+
buffer = ""
|
109 |
+
for new_text in streamer:
|
110 |
+
buffer += new_text
|
111 |
+
# Remove <|im_end|> or similar tokens from the output
|
112 |
+
buffer = buffer.replace("<|im_end|>", "")
|
113 |
+
yield buffer
|
114 |
+
```
|
115 |
+
### **Intended Use**
|
116 |
+
|
117 |
+
**Radiology-Infer-Mini** is designed to support healthcare professionals and researchers in tasks involving medical imaging and radiological analysis. Its primary applications include:
|
118 |
+
|
119 |
+
1. **Diagnostic Support**
|
120 |
+
- Analyze medical images (X-rays, MRIs, CT scans, ultrasounds) to identify abnormalities, annotate findings, and assist radiologists in forming diagnostic conclusions.
|
121 |
+
|
122 |
+
2. **Medical Report Generation**
|
123 |
+
- Automatically generate structured radiology reports from image data, reducing documentation time and improving workflow efficiency.
|
124 |
+
|
125 |
+
3. **Educational and Research Tools**
|
126 |
+
- Serve as a teaching aid for radiology students and support researchers in large-scale studies by automating image labeling and data extraction.
|
127 |
+
|
128 |
+
4. **Workflow Automation**
|
129 |
+
- Integrate with medical devices and hospital systems to automate triaging, anomaly detection, and report routing in clinical settings.
|
130 |
+
|
131 |
+
5. **Multi-modal Applications**
|
132 |
+
- Handle complex tasks involving both images and text, such as extracting patient data from images and synthesizing text-based findings with visual interpretations.
|
133 |
+
|
134 |
+
6. **Global Accessibility**
|
135 |
+
- Support multilingual radiological text understanding for use in diverse healthcare settings around the world.
|
136 |
+
|
137 |
+
### **Limitations**
|
138 |
+
|
139 |
+
While **Radiology-Infer-Mini** offers advanced capabilities, it has the following limitations:
|
140 |
+
|
141 |
+
1. **Medical Expertise Dependency**
|
142 |
+
- The model provides supplementary insights but cannot replace the expertise and judgment of a licensed radiologist or clinician.
|
143 |
+
|
144 |
+
2. **Data Bias**
|
145 |
+
- Performance may vary based on the training data, which might not fully represent all imaging modalities, patient demographics, or rare conditions.
|
146 |
+
|
147 |
+
3. **Edge Cases**
|
148 |
+
- Limited ability to handle edge cases, highly complex images, or uncommon medical scenarios that were underrepresented in its training dataset.
|
149 |
+
|
150 |
+
4. **Regulatory Compliance**
|
151 |
+
- It must be validated for compliance with local medical regulations and standards before clinical use.
|
152 |
+
|
153 |
+
5. **Interpretation Challenges**
|
154 |
+
- The model may misinterpret artifacts, noise, or low-quality images, leading to inaccurate conclusions in certain scenarios.
|
155 |
+
|
156 |
+
6. **Multimodal Integration**
|
157 |
+
- While capable of handling both visual and textual inputs, tasks requiring deep contextual understanding across different modalities might yield inconsistent results.
|
158 |
+
|
159 |
+
7. **Real-Time Limitations**
|
160 |
+
- Processing speed and accuracy might be constrained in real-time or high-throughput scenarios, especially on hardware with limited computational resources.
|
161 |
+
|
162 |
+
8. **Privacy and Security**
|
163 |
+
- Radiology-Infer-Mini must be used in secure environments to ensure the confidentiality and integrity of sensitive medical data.
|