Views
No views yet

1# Create and activate a new conda environment
2conda create -n OphthaReason_eval python=3.10
3conda activate OphthaReason_eval
4
5# Clone the repository and install dependencies
6git clone https://github.com/lxirich/OphthaReason.git
7cd OphthaReason
8pip install -r requirements_eval.txteval.py:
BASE64_ROOT Path to your base64 encoded imagesDS_ROOT: Path to your dataset JSON filesOUTPUT_DIR: Directory for output resultseval.py to point to your downloaded modelbash eval/eval.sh 1import base64
2from vllm import LLM, SamplingParams
3
4# Load the model
5model_path = "path/to/OphthaReason/model" # Replace with your model path
6model = LLM(model=model_path, tensor_parallel_size=1, gpu_memory_utilization=0.8)
7sampling_params = SamplingParams(temperature=0.0, max_tokens=2048)
8
9# Prepare instance image input
10image_paths = [
11 "path/to/retinal/image1.jpg",
12 "path/to/retinal/image2.jpg", # Additional image in the same instance
13 # Add more images as needed for this instance
14]
15
16# Convert images to base64
17image_contents = []
18for img_path in image_paths:
19 with open(img_path, "rb") as f:
20 image_content = base64.b64encode(f.read()).decode('utf-8')
21 image_contents.append(image_content)
22
23# Construct prompts
24system_prompt = (
25 "You're a professional ophthalmologist."
26 "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. "
27 "The assistant first thinks about the reasoning process in the mind and then provides the user with the answer..."
28)
29
30user_prompt = f"A 62-year-old woman presented with a one-month history of sudden painless visual loss..."
31
32# Build message content with multiple images for this instance
33content = [{"type": "text", "text": user_prompt}]
34for img_content in image_contents:
35 content.append({"type": "image_url", "image_url": f"data:image/jpeg;base64,{img_content}"})
36
37messages = [
38 {
39 "role": "system",
40 "content": [{"type": "text", "text": system_prompt}]
41 },
42 {
43 "role": "user",
44 "content": content
45 }
46]
47
48# Perform VQA inference on this instance
49outputs = model.chat([messages], sampling_params)
50result = outputs[0].outputs[0].text
51
52print(result)