monsoon-nlp commited on
Commit
25f706b
1 Parent(s): 652448b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -7
README.md CHANGED
@@ -5,23 +5,81 @@ base_model: google/vit-large-patch16-224
5
 
6
  ## LoRA Image Binary Classification LoRA adapter
7
 
8
- Model: google/vit-large-patch16-224
 
9
 
10
- Dataset: https://www.kaggle.com/c/aptos2019-blindness-detection - fundus images of the back of the eye, and diabetic retinopathy score
11
 
12
- Source docs: https://huggingface.co/docs/peft/task_guides/image_classification_lora
13
 
14
  Training notebook: https://colab.research.google.com/drive/1TVsUyyou87E26Sz40CdBH3CzWoVckgtq?usp=sharing
15
 
16
- Adapted to binary classifier (diagnosis=0 vs. all others; 50-50% distribution in training data)
17
-
18
  On 10% held-out of training data: accuracy 98%
19
 
20
  - PEFT 0.5.0
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ## Future goals
24
 
25
  - More documentation
26
- - Modify loss for regression on 0-4 score
27
- - Script and Gradio to use raw images
 
5
 
6
  ## LoRA Image Binary Classification LoRA adapter
7
 
8
+ Trained on APTOS 2019 Kaggle competition for identifying diabetic retinopathy. In this case I've modified the problem
9
+ to binary classifier (diagnosis=0 vs. all others; 50-50% distribution in training data)
10
 
11
+ Base Model: [google/vit-large-patch16-224](https://huggingface.co/google/vit-large-patch16-224)
12
 
13
+ Dataset: https://www.kaggle.com/c/aptos2019-blindness-detection - fundus images of the back of the eye, and diabetic retinopathy score
14
 
15
  Training notebook: https://colab.research.google.com/drive/1TVsUyyou87E26Sz40CdBH3CzWoVckgtq?usp=sharing
16
 
 
 
17
  On 10% held-out of training data: accuracy 98%
18
 
19
  - PEFT 0.5.0
20
 
21
+ PEFT Image classifier inference / [Gradio app](https://huggingface.co/spaces/monsoon-nlp/eyegazer-demo/blob/main/app.py)
22
+
23
+ ```python
24
+ from peft import PeftModel
25
+ from PIL import Image
26
+ from transformers import AutoImageProcessor, AutoModelForImageClassification
27
+
28
+ from torchvision.transforms import (
29
+ CenterCrop,
30
+ Compose,
31
+ Normalize,
32
+ RandomHorizontalFlip,
33
+ RandomResizedCrop,
34
+ Resize,
35
+ ToTensor,
36
+ )
37
+
38
+ model_name = 'google/vit-large-patch16-224'
39
+ adapter = 'monsoon-nlp/eyegazer-vit-binary'
40
+
41
+ image_processor = AutoImageProcessor.from_pretrained(model_name)
42
+
43
+ normalize = Normalize(mean=image_processor.image_mean, std=image_processor.image_std)
44
+ train_transforms = Compose(
45
+ [
46
+ RandomResizedCrop(image_processor.size["height"]),
47
+ RandomHorizontalFlip(),
48
+ ToTensor(),
49
+ normalize,
50
+ ]
51
+ )
52
+
53
+ val_transforms = Compose(
54
+ [
55
+ Resize(image_processor.size["height"]),
56
+ CenterCrop(image_processor.size["height"]),
57
+ ToTensor(),
58
+ normalize,
59
+ ]
60
+ )
61
+
62
+ model = AutoModelForImageClassification.from_pretrained(
63
+ model_name,
64
+ ignore_mismatched_sizes=True,
65
+ num_labels=2,
66
+ )
67
+
68
+ lora_model = PeftModel.from_pretrained(model, adapter)
69
+
70
+ img = Image.open("sample.png")
71
+ pimg = val_transforms(img.convert("RGB"))
72
+ batch = pimg.unsqueeze(0)
73
+ op = lora_model(batch)
74
+ vals = op.logits.tolist()[0]
75
+
76
+ if vals[0] > vals[1]:
77
+ return "Predicted unaffected"
78
+ else:
79
+ return "Predicted affected to some degree"
80
+ ```
81
 
82
  ## Future goals
83
 
84
  - More documentation
85
+ - Modify loss for regression on 0-4 score