abdurrahimyilmaz commited on
Commit
7717955
·
verified ·
1 Parent(s): 256cbad

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -9
README.md CHANGED
@@ -27,25 +27,32 @@ GPU: 1xRTX4090 <br>
27
  ## Usage
28
 
29
  ```python
 
30
  from transformers import MllamaForConditionalGeneration, AutoProcessor
31
  from peft import PeftModel
 
32
  from PIL import Image
33
 
34
  # Load base model
35
- base_model_name = "meta-llama/Llama-3.2-11B-Vision-Instruct"
36
- model = MllamaForConditionalGeneration.from_pretrained(base_model_name)
 
 
37
  processor = AutoProcessor.from_pretrained(base_model_name)
38
 
39
  # Load LoRA adapter
40
- adapter_path = "DermaVLM/DermatoLLama-200k"
41
  model = PeftModel.from_pretrained(model, adapter_path)
 
 
 
 
42
 
43
- # Inference
44
- image_path = "DERM12345.jpg"
45
- image = Image.open(image_path).convert("RGB")
46
- prompt_text = "Describe the image in detail."
47
  messages = []
48
  content_list = []
 
 
49
  if image:
50
  content_list.append({"type": "image"})
51
 
@@ -59,7 +66,7 @@ input_text = processor.apply_chat_template(
59
  tokenize=False,
60
  )
61
 
62
- # Prepare final inputs
63
  inputs = processor(
64
  images=image,
65
  text=input_text,
@@ -68,7 +75,7 @@ inputs = processor(
68
  ).to(model.device)
69
 
70
  generation_config = {
71
- "max_new_tokens": 256,
72
  "do_sample": True,
73
  "temperature": 0.4,
74
  "top_p": 0.95,
@@ -76,6 +83,10 @@ generation_config = {
76
 
77
  input_length = inputs.input_ids.shape[1]
78
 
 
 
 
 
79
  with torch.no_grad():
80
  outputs = model.generate(
81
  **inputs,
@@ -89,7 +100,11 @@ with torch.no_grad():
89
  generated_tokens = outputs[0][input_length:]
90
  raw_output = processor.decode(generated_tokens, skip_special_tokens=True)
91
 
 
 
 
92
  print(raw_output)
 
93
  ```
94
 
95
  ## Citation
 
27
  ## Usage
28
 
29
  ```python
30
+ # %%
31
  from transformers import MllamaForConditionalGeneration, AutoProcessor
32
  from peft import PeftModel
33
+ import torch
34
  from PIL import Image
35
 
36
  # Load base model
37
+ base_model_name = "meta-llama/Llama-3.2-11B-Vision-Instruct"
38
+ model = MllamaForConditionalGeneration.from_pretrained(
39
+ base_model_name, torch_dtype=torch.bfloat16, device_map="auto"
40
+ )
41
  processor = AutoProcessor.from_pretrained(base_model_name)
42
 
43
  # Load LoRA adapter
44
+ adapter_path = "DermaVLM/DermatoLLama-full"
45
  model = PeftModel.from_pretrained(model, adapter_path)
46
+ # %%
47
+ # Load image using Pillow
48
+ image_path = rf"IMAGE_LOCATION" # Replace with your image path
49
+ image = Image.open(image_path)
50
 
51
+ prompt_text = "Analyze the dermatological condition shown in the image and provide a detailed report including body location."
 
 
 
52
  messages = []
53
  content_list = []
54
+
55
+ # Add the image to the content
56
  if image:
57
  content_list.append({"type": "image"})
58
 
 
66
  tokenize=False,
67
  )
68
 
69
+ # Prepare final inputs with the loaded image
70
  inputs = processor(
71
  images=image,
72
  text=input_text,
 
75
  ).to(model.device)
76
 
77
  generation_config = {
78
+ "max_new_tokens": 512, # be careful with this, it can cause very long inference times
79
  "do_sample": True,
80
  "temperature": 0.4,
81
  "top_p": 0.95,
 
83
 
84
  input_length = inputs.input_ids.shape[1]
85
 
86
+ print(f"Processing image: {image_path}")
87
+ print(f"Image size: {image.size}")
88
+ print("Generating response...")
89
+
90
  with torch.no_grad():
91
  outputs = model.generate(
92
  **inputs,
 
100
  generated_tokens = outputs[0][input_length:]
101
  raw_output = processor.decode(generated_tokens, skip_special_tokens=True)
102
 
103
+ print("\n" + "="*50)
104
+ print("DERMATOLOGY ANALYSIS:")
105
+ print("="*50)
106
  print(raw_output)
107
+ print("="*50)
108
  ```
109
 
110
  ## Citation