asusevski commited on
Commit
1e28fa3
1 Parent(s): 6901829

add everything

Browse files
Files changed (3) hide show
  1. app.py +47 -0
  2. dogs_labels.txt +71 -0
  3. requirements.txt +143 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
3
+ import numpy as np
4
+ import torch
5
+ import torch.nn as nn
6
+ from torchvision.transforms import Compose, ColorJitter, ToTensor, RandomPerspective
7
+ from transformers import AutoFeatureExtractor, AutoModelForImageClassification
8
+
9
+
10
+ with open("dogs_labels.txt", "r") as f:
11
+ labels = f.read().split('\n')
12
+
13
+
14
+ num_labels = len(labels)
15
+ id2label = {str(i): c for i, c in enumerate(labels)}
16
+
17
+
18
+ def classify_image(inp):
19
+ # Load model
20
+ model = AutoModelForImageClassification.from_pretrained(pretrained_model_name_or_path="asusevski/vit-dog-classifier")
21
+
22
+ # Preprocess
23
+ model_preprocessor_name = "google/vit-base-patch16-224"
24
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_preprocessor_name)
25
+ augs = Compose(
26
+ [
27
+ ColorJitter(brightness=0.25, contrast=0.25, saturation=0.25, hue=0.4),
28
+ RandomPerspective(distortion_scale=0.3),
29
+ ToTensor(),
30
+ ]
31
+ )
32
+
33
+ inp = np.array(augs(inp.convert('RGB')))
34
+
35
+ inp = torch.tensor(feature_extractor(images=inp)['pixel_values'])
36
+ preds = model(inp)['logits']
37
+ preds = torch.flatten(preds)
38
+ preds = nn.functional.softmax(preds, dim=0)
39
+ confidences = {labels[i]: preds[i].item() for i in range(num_labels)}
40
+ return confidences
41
+
42
+
43
+ gr.Interface(fn=classify_image,
44
+ inputs=gr.Image(type="pil"),
45
+ outputs=gr.Label(num_top_classes=3),
46
+ examples=['./data/dogs/train/Yorkie/01.jpg', './data/dogs/train/Yorkie/02.jpg']
47
+ ).launch()
dogs_labels.txt ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Afghan
2
+ African Wild Dog
3
+ Airedale
4
+ American Spaniel
5
+ American Hairless
6
+ American Spaniel
7
+ Basenji
8
+ Basset
9
+ Beagle
10
+ Bearded Collie
11
+ Bermaise
12
+ Bichon Frise
13
+ Blenheim
14
+ Bloodhound
15
+ Bluetick
16
+ Border Collie
17
+ Borzoi
18
+ Boston Terrier
19
+ Boxer
20
+ Bull Mastiff
21
+ Bull Terrier
22
+ Bulldog
23
+ Cairn
24
+ Chihuahua
25
+ Chinese Crested
26
+ Chow
27
+ Clumber
28
+ Cockapoo
29
+ Cocker
30
+ Collie
31
+ Corgi
32
+ Coyote
33
+ Dalmation
34
+ Dhole
35
+ Dingo
36
+ Doberman
37
+ Elk Hound
38
+ French Bulldog
39
+ German Sheperd
40
+ Golden Retriever
41
+ Great Dane
42
+ Great Perenees
43
+ Greyhound
44
+ Groenendael
45
+ Irish Spaniel
46
+ Irish Wolfhound
47
+ Japanese Spaniel
48
+ Komondor
49
+ Labradoodle
50
+ Labrador
51
+ Lhasa
52
+ Malinois
53
+ Maltese
54
+ Mex Hairless
55
+ Newfoundland
56
+ Pekinese
57
+ Pit Bull
58
+ Pomeranian
59
+ Poodle
60
+ Pug
61
+ Rhodesian
62
+ Rottweiler
63
+ Saint Bernard
64
+ Schnauzer
65
+ Scotch Terrier
66
+ Shar_Pei
67
+ Shiba Inu
68
+ Shih-Tzu
69
+ Siberian Husky
70
+ Vizsla
71
+ Yorkie
requirements.txt ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ attrs==19.3.0
2
+ Automat==0.8.0
3
+ backcall==0.1.0
4
+ bleach==3.1.1
5
+ blinker==1.4
6
+ blis==0.7.8
7
+ catalogue==2.0.7
8
+ certifi==2019.11.28
9
+ cffi==1.15.0
10
+ chardet==3.0.4
11
+ charset-normalizer==2.0.12
12
+ click==8.1.3
13
+ cloud-init==20.1
14
+ colorama==0.4.3
15
+ command-not-found==0.3
16
+ configobj==5.0.6
17
+ constantly==15.1.0
18
+ cryptography==37.0.2
19
+ cymem==2.0.6
20
+ dataclasses==0.6
21
+ dbus-python==1.2.16
22
+ decorator==4.4.2
23
+ defusedxml==0.6.0
24
+ distro==1.4.0
25
+ distro-info===0.23ubuntu1
26
+ entrypoints==0.3
27
+ filelock==3.7.1
28
+ html5lib==1.0.1
29
+ httplib2==0.14.0
30
+ huggingface-hub==0.8.1
31
+ hyperlink==19.0.0
32
+ idna==2.8
33
+ importlib-metadata==1.5.0
34
+ incremental==16.10.1
35
+ ipykernel==5.2.0
36
+ ipython==7.13.0
37
+ ipython-genutils==0.2.0
38
+ ipywidgets==6.0.0
39
+ jedi==0.15.2
40
+ Jinja2==2.10.1
41
+ joblib==1.1.0
42
+ jsonpatch==1.22
43
+ jsonpointer==2.0
44
+ jsonschema==3.2.0
45
+ jupyter-client==6.1.2
46
+ jupyter-console==6.0.0
47
+ jupyter-core==4.6.3
48
+ keyring==18.0.1
49
+ langcodes==3.3.0
50
+ language-selector==0.1
51
+ launchpadlib==1.10.13
52
+ lazr.restfulclient==0.14.2
53
+ lazr.uri==1.0.3
54
+ MarkupSafe==1.1.0
55
+ mistune==0.8.4
56
+ more-itertools==4.2.0
57
+ murmurhash==1.0.7
58
+ nbconvert==5.6.1
59
+ nbformat==5.0.4
60
+ netifaces==0.10.4
61
+ nltk==3.7
62
+ notebook==6.0.3
63
+ numpy==1.23.0
64
+ oauthlib==3.1.0
65
+ packaging==21.3
66
+ pandas==1.5.2
67
+ pandocfilters==1.4.2
68
+ parso==0.5.2
69
+ pathy==0.6.2
70
+ pdfminer.six==20220524
71
+ pdfplumber==0.7.1
72
+ pexpect==4.6.0
73
+ pickleshare==0.7.5
74
+ Pillow==9.1.1
75
+ preshed==3.0.6
76
+ prometheus-client==0.7.1
77
+ prompt-toolkit==2.0.10
78
+ pyasn1==0.4.2
79
+ pyasn1-modules==0.2.1
80
+ pycparser==2.21
81
+ pydantic==1.8.2
82
+ Pygments==2.3.1
83
+ PyGObject==3.36.0
84
+ PyHamcrest==1.9.0
85
+ PyJWT==1.7.1
86
+ pymacaroons==0.13.0
87
+ PyNaCl==1.3.0
88
+ pyOpenSSL==19.0.0
89
+ pyparsing==3.0.9
90
+ pyrsistent==0.15.5
91
+ pyserial==3.4
92
+ python-apt==2.0.0
93
+ python-dateutil==2.8.2
94
+ python-dbusmock==0.19
95
+ python-debian===0.1.36ubuntu1
96
+ pytz==2022.7.1
97
+ PyYAML==5.3.1
98
+ pyzmq==18.1.1
99
+ regex==2022.6.2
100
+ requests==2.22.0
101
+ requests-unixsocket==0.2.0
102
+ scikit-learn==1.1.1
103
+ scipy==1.8.1
104
+ SecretStorage==2.3.1
105
+ Send2Trash==1.5.0
106
+ sentence-transformers==2.2.2
107
+ sentencepiece==0.1.96
108
+ service-identity==18.1.0
109
+ simplejson==3.16.0
110
+ six==1.14.0
111
+ smart-open==5.2.1
112
+ spacy==3.3.1
113
+ spacy-legacy==3.0.9
114
+ spacy-loggers==1.0.2
115
+ srsly==2.4.3
116
+ ssh-import-id==5.10
117
+ systemd-python==234
118
+ terminado==0.8.2
119
+ testpath==0.4.4
120
+ thinc==8.0.17
121
+ threadpoolctl==3.1.0
122
+ tokenizers==0.12.1
123
+ torch==1.12.0
124
+ torchvision==0.13.0
125
+ tornado==5.1.1
126
+ tqdm==4.64.0
127
+ traitlets==4.3.3
128
+ transformers==4.20.1
129
+ Twisted==18.9.0
130
+ typer==0.4.2
131
+ typing-extensions==4.3.0
132
+ ubuntu-advantage-tools==20.3
133
+ ufw==0.36
134
+ unattended-upgrades==0.1
135
+ urllib3==1.25.8
136
+ wadllib==1.3.3
137
+ Wand==0.6.7
138
+ wasabi==0.9.1
139
+ wcwidth==0.1.8
140
+ webencodings==0.5.1
141
+ widgetsnbextension==2.0.0
142
+ zipp==1.0.0
143
+ zope.interface==4.7.1