Nick Doiron commited on
Commit
3da4879
β€’
1 Parent(s): e5e771c

image examples and demo

Browse files
.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

  • SHA256: 92f2459dc7e6a60eedde42c90ae6b6f867a52a496ed38c0b5566c0a95591d245
  • Pointer size: 132 Bytes
  • Size of remote file: 5.24 MB
images/0a4e1a29ffff.png ADDED

Git LFS Details

  • SHA256: d3ec757a0698168f14a48f0306ff653033a6a1d93b930810fc5bddf789b723af
  • Pointer size: 132 Bytes
  • Size of remote file: 1.01 MB
images/0c43c79e8cfb.png ADDED

Git LFS Details

  • SHA256: e28d13cb1b88538da0eb8d88eb60b0f7db404164a2bc01d208d295eb008de9ee
  • Pointer size: 132 Bytes
  • Size of remote file: 5.5 MB
images/0c7e82daf5a0.png ADDED

Git LFS Details

  • SHA256: ec71d1b6d6e1778c4362eec6808582e963daed47d865e96f2e38f997ad98f99a
  • Pointer size: 132 Bytes
  • Size of remote file: 1.34 MB
images/i1.png ADDED

Git LFS Details

  • SHA256: a05a22912b98fdd60fcc20cc9d81f4974e7ef92a27e588f0c40016133377bf72
  • Pointer size: 132 Bytes
  • Size of remote file: 3.55 MB
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