Upload 3 files
Browse files- .gitattributes +2 -0
- README.md +110 -0
- assets/case.png +3 -0
- assets/model.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/case.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/model.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
base_model:
|
| 5 |
+
- OpenGVLab/InternVL3-2B
|
| 6 |
+
- Qwen/Qwen2.5-VL-3B-Instruct
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
# Bridging the Gap in Ophthalmic AI: MM-Retinal-Reason Dataset and OphthaReason Model toward Dynamic Multimodal Reasoning
|
| 10 |
+
|
| 11 |
+
<div align="center">
|
| 12 |
+
|
| 13 |
+
[](https://arxiv.org/abs/2508.16129)
|
| 14 |
+
[](https://github.com/lxirich/OphthaReason)
|
| 15 |
+
[](https://huggingface.co/lxirich/OphthaReason)
|
| 16 |
+
[](https://huggingface.co/datasets/lxirich/MM-Retinal-Reason)
|
| 17 |
+
|
| 18 |
+
</div>
|
| 19 |
+
|
| 20 |
+
## 🔥 Overview
|
| 21 |
+
|
| 22 |
+
We introduce MM-Retinal-Reason, the first ophthalmic multimodal dataset with the full spectrum of perception and reasoning. It encompasses both basic reasoning tasks and complex reasoning tasks, aiming to enhance visual-centric fundamental reasoning capabilities and emulate realistic clinical thinking patterns. Building upon MM-Retinal-Reason, we propose OphthaReason, the first ophthalmology-specific multimodal reasoning model with step-by-step reasoning traces. To enable flexible adaptation to both basic and complex reasoning tasks, we specifically design a novel method called Uncertainty-Aware Dynamic Thinking (UADT), which estimates sample-level uncertainty via entropy and dynamically modulates the model’s exploration depth using a shaped advantage mechanism.
|
| 23 |
+
|
| 24 |
+
<img src="./assets/model.png" width="100%">
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
## 🌴 OphthaReason Model
|
| 28 |
+
### 1. Pretrain Model Download
|
| 29 |
+
The OphthaReason model can be downloaded from [Hugging Face Link](https://huggingface.co/lxirich/OphthaReason).
|
| 30 |
+
|
| 31 |
+
### 2. Setup
|
| 32 |
+
```bash
|
| 33 |
+
# Create and activate a new conda environment
|
| 34 |
+
conda create -n OphthaReason_eval python=3.10
|
| 35 |
+
conda activate OphthaReason_eval
|
| 36 |
+
|
| 37 |
+
# Clone the repository and install dependencies
|
| 38 |
+
git clone https://github.com/lxirich/OphthaReason.git
|
| 39 |
+
cd OphthaReason
|
| 40 |
+
pip install -r requirements_eval.txt
|
| 41 |
+
```
|
| 42 |
+
### 3. Batch Evaluation
|
| 43 |
+
1. Update the following paths in `eval.py`:
|
| 44 |
+
- `BASE64_ROOT` Path to your base64 encoded images
|
| 45 |
+
- `DS_ROOT`: Path to your dataset JSON files
|
| 46 |
+
- `OUTPUT_DIR`: Directory for output results
|
| 47 |
+
2. Modify the model path in `eval.py` to point to your downloaded model
|
| 48 |
+
3. Run the evaluation script:
|
| 49 |
+
```bash
|
| 50 |
+
bash eval/eval.sh
|
| 51 |
+
```
|
| 52 |
+
### 4. Single Instance VQA Inference
|
| 53 |
+
For Visual Question Answering with a single instance (which may include multiple images), use the following example:
|
| 54 |
+
```python
|
| 55 |
+
import base64
|
| 56 |
+
from vllm import LLM, SamplingParams
|
| 57 |
+
|
| 58 |
+
# Load the model
|
| 59 |
+
model_path = "path/to/OphthaReason/model" # Replace with your model path
|
| 60 |
+
model = LLM(model=model_path, tensor_parallel_size=1, gpu_memory_utilization=0.8)
|
| 61 |
+
sampling_params = SamplingParams(temperature=0.0, max_tokens=2048)
|
| 62 |
+
|
| 63 |
+
# Prepare instance image input
|
| 64 |
+
image_paths = [
|
| 65 |
+
"path/to/retinal/image1.jpg",
|
| 66 |
+
"path/to/retinal/image2.jpg", # Additional image in the same instance
|
| 67 |
+
# Add more images as needed for this instance
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
# Convert images to base64
|
| 71 |
+
image_contents = []
|
| 72 |
+
for img_path in image_paths:
|
| 73 |
+
with open(img_path, "rb") as f:
|
| 74 |
+
image_content = base64.b64encode(f.read()).decode('utf-8')
|
| 75 |
+
image_contents.append(image_content)
|
| 76 |
+
|
| 77 |
+
# Construct prompts
|
| 78 |
+
system_prompt = (
|
| 79 |
+
"You're a professional ophthalmologist."
|
| 80 |
+
"A conversation between User and Assistant. The user asks a question, and the Assistant solves it. "
|
| 81 |
+
"The assistant first thinks about the reasoning process in the mind and then provides the user with the answer..."
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
user_prompt = f"A 62-year-old woman presented with a one-month history of sudden painless visual loss..."
|
| 85 |
+
|
| 86 |
+
# Build message content with multiple images for this instance
|
| 87 |
+
content = [{"type": "text", "text": user_prompt}]
|
| 88 |
+
for img_content in image_contents:
|
| 89 |
+
content.append({"type": "image_url", "image_url": f"data:image/jpeg;base64,{img_content}"})
|
| 90 |
+
|
| 91 |
+
messages = [
|
| 92 |
+
{
|
| 93 |
+
"role": "system",
|
| 94 |
+
"content": [{"type": "text", "text": system_prompt}]
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"role": "user",
|
| 98 |
+
"content": content
|
| 99 |
+
}
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
# Perform VQA inference on this instance
|
| 103 |
+
outputs = model.chat([messages], sampling_params)
|
| 104 |
+
result = outputs[0].outputs[0].text
|
| 105 |
+
|
| 106 |
+
print(result)
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### 5. Case Study
|
| 110 |
+
<img src="./assets/case.png" width="100%">
|
assets/case.png
ADDED
|
Git LFS Details
|
assets/model.png
ADDED
|
Git LFS Details
|