Spaces:
Running
Running
Nick Doiron
commited on
Commit
β’
3da4879
1
Parent(s):
e5e771c
image examples and demo
Browse files- .gitattributes +1 -0
- README.md +1 -1
- app.py +86 -0
- images/0a09aa7356c0.png +3 -0
- images/0a4e1a29ffff.png +3 -0
- images/0c43c79e8cfb.png +3 -0
- images/0c7e82daf5a0.png +3 -0
- images/i1.png +3 -0
- requirements.txt +8 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ 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 |
+
*.png filter=lfs diff=lfs merge=lfs
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Eyegazer Demo
|
3 |
-
emoji:
|
4 |
colorFrom: indigo
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: Eyegazer Demo
|
3 |
+
emoji: π
|
4 |
colorFrom: indigo
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from peft import PeftModel
|
4 |
+
from PIL import Image
|
5 |
+
import torch
|
6 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
7 |
+
|
8 |
+
from torchvision.transforms import (
|
9 |
+
CenterCrop,
|
10 |
+
Compose,
|
11 |
+
Normalize,
|
12 |
+
RandomHorizontalFlip,
|
13 |
+
RandomResizedCrop,
|
14 |
+
Resize,
|
15 |
+
ToTensor,
|
16 |
+
)
|
17 |
+
|
18 |
+
model_name = 'google/vit-large-patch16-224'
|
19 |
+
adapter = 'monsoon-nlp/eyegazer-vit-binary'
|
20 |
+
|
21 |
+
image_processor = AutoImageProcessor.from_pretrained(model_name)
|
22 |
+
|
23 |
+
normalize = Normalize(mean=image_processor.image_mean, std=image_processor.image_std)
|
24 |
+
train_transforms = Compose(
|
25 |
+
[
|
26 |
+
RandomResizedCrop(image_processor.size["height"]),
|
27 |
+
RandomHorizontalFlip(),
|
28 |
+
ToTensor(),
|
29 |
+
normalize,
|
30 |
+
]
|
31 |
+
)
|
32 |
+
|
33 |
+
val_transforms = Compose(
|
34 |
+
[
|
35 |
+
Resize(image_processor.size["height"]),
|
36 |
+
CenterCrop(image_processor.size["height"]),
|
37 |
+
ToTensor(),
|
38 |
+
normalize,
|
39 |
+
]
|
40 |
+
)
|
41 |
+
|
42 |
+
model = AutoModelForImageClassification.from_pretrained(
|
43 |
+
model_name,
|
44 |
+
ignore_mismatched_sizes=True,
|
45 |
+
num_labels=2,
|
46 |
+
)
|
47 |
+
|
48 |
+
lora_model = PeftModel.from_pretrained(model, adapter)
|
49 |
+
|
50 |
+
def query(img):
|
51 |
+
pimg = val_transforms(img.convert("RGB"))
|
52 |
+
batch = pimg.unsqueeze(0)
|
53 |
+
op = lora_model(batch)
|
54 |
+
vals = op.logits.tolist()[0]
|
55 |
+
|
56 |
+
if vals[0] > vals[1]:
|
57 |
+
return "Predicted unaffected"
|
58 |
+
else:
|
59 |
+
return "Predicted affected to some degree"
|
60 |
+
|
61 |
+
iface = gr.Interface(
|
62 |
+
fn=query,
|
63 |
+
examples=[
|
64 |
+
os.path.join(os.path.dirname(__file__), "images/i1.png"),
|
65 |
+
os.path.join(os.path.dirname(__file__), "images/0a09aa7356c0.png"),
|
66 |
+
os.path.join(os.path.dirname(__file__), "images/0a4e1a29ffff.png"),
|
67 |
+
os.path.join(os.path.dirname(__file__), "images/0c43c79e8cfb.png"),
|
68 |
+
os.path.join(os.path.dirname(__file__), "images/0c7e82daf5a0.png"),
|
69 |
+
],
|
70 |
+
inputs=[
|
71 |
+
gr.inputs.Image(
|
72 |
+
image_mode='RGB',
|
73 |
+
sources=['upload', 'clipboard'],
|
74 |
+
type='pil',
|
75 |
+
label='Input Fundus Camera Image',
|
76 |
+
show_label=True,
|
77 |
+
),
|
78 |
+
],
|
79 |
+
outputs=[
|
80 |
+
gr.Markdown(value="", label="Predicted label"),
|
81 |
+
],
|
82 |
+
title="ViT retinopathy model",
|
83 |
+
description="Diabetic retinopathy model trained on APTOS 2019 dataset; demonstration, not medical dvice",
|
84 |
+
allow_flagging="never",
|
85 |
+
)
|
86 |
+
iface.launch()
|
images/0a09aa7356c0.png
ADDED
Git LFS Details
|
images/0a4e1a29ffff.png
ADDED
Git LFS Details
|
images/0c43c79e8cfb.png
ADDED
Git LFS Details
|
images/0c7e82daf5a0.png
ADDED
Git LFS Details
|
images/i1.png
ADDED
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers==4.33.0
|
2 |
+
sentencepiece==0.1.97
|
3 |
+
peft==0.6.0
|
4 |
+
accelerate==0.23.0
|
5 |
+
bitsandbytes==0.41.1
|
6 |
+
datasets==2.12.0
|
7 |
+
torchvision==0.15.2
|
8 |
+
pillow==9.5.0
|