Spaces:
Paused
Paused
Ming Chen
commited on
Commit
•
46aa155
1
Parent(s):
4ac5aff
Deploy pet breed classifier
Browse files- .gitignore +146 -0
- app.py +37 -0
- examples/leonberger.jpg +0 -0
- examples/samoyed.jpg +0 -0
- examples/siamese.jpg +0 -0
- makefile +31 -0
- model/model.pkl +3 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,146 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__/
|
2 |
+
*.py[cod]
|
3 |
+
*$py.class
|
4 |
+
|
5 |
+
# C extensions
|
6 |
+
*.so
|
7 |
+
|
8 |
+
# Distribution / packaging
|
9 |
+
.Python
|
10 |
+
env/
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
*.egg-info/
|
23 |
+
.installed.cfg
|
24 |
+
*.egg
|
25 |
+
|
26 |
+
# PyInstaller
|
27 |
+
# Usually these files are written by a python script from a template
|
28 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
29 |
+
*.manifest
|
30 |
+
*.spec
|
31 |
+
|
32 |
+
# Installer logs
|
33 |
+
pip-log.txt
|
34 |
+
pip-delete-this-directory.txt
|
35 |
+
|
36 |
+
# Unit test / coverage reports
|
37 |
+
htmlcov/
|
38 |
+
.tox/
|
39 |
+
.coverage
|
40 |
+
.coverage.*
|
41 |
+
.cache
|
42 |
+
nosetests.xml
|
43 |
+
coverage.xml
|
44 |
+
*,cover
|
45 |
+
.hypothesis/
|
46 |
+
|
47 |
+
# Translations
|
48 |
+
*.mo
|
49 |
+
*.pot
|
50 |
+
|
51 |
+
# Django stuff:
|
52 |
+
*.log
|
53 |
+
local_settings.py
|
54 |
+
|
55 |
+
# Flask stuff:
|
56 |
+
instance/
|
57 |
+
.webassets-cache
|
58 |
+
|
59 |
+
# Scrapy stuff:
|
60 |
+
.scrapy
|
61 |
+
|
62 |
+
# Sphinx documentation
|
63 |
+
docs/_build/
|
64 |
+
|
65 |
+
# PyBuilder
|
66 |
+
target/
|
67 |
+
|
68 |
+
# IPython Notebook
|
69 |
+
.ipynb_checkpoints
|
70 |
+
|
71 |
+
# pyenv
|
72 |
+
.python-version
|
73 |
+
|
74 |
+
# celery beat schedule file
|
75 |
+
celerybeat-schedule
|
76 |
+
|
77 |
+
# dotenv
|
78 |
+
.env
|
79 |
+
|
80 |
+
# virtualenv
|
81 |
+
venv/
|
82 |
+
ENV/
|
83 |
+
|
84 |
+
# Spyder project settings
|
85 |
+
.spyderproject
|
86 |
+
|
87 |
+
# Rope project settings
|
88 |
+
.ropeproject
|
89 |
+
### VirtualEnv template
|
90 |
+
# Virtualenv
|
91 |
+
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
92 |
+
.Python
|
93 |
+
[Bb]in
|
94 |
+
[Ii]nclude
|
95 |
+
[Ll]ib
|
96 |
+
[Ll]ib64
|
97 |
+
[Ll]ocal
|
98 |
+
[Ss]cripts
|
99 |
+
pyvenv.cfg
|
100 |
+
.venv
|
101 |
+
pip-selfcheck.json
|
102 |
+
### JetBrains template
|
103 |
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
104 |
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
105 |
+
|
106 |
+
# User-specific stuff:
|
107 |
+
.idea/workspace.xml
|
108 |
+
.idea/tasks.xml
|
109 |
+
.idea/dictionaries
|
110 |
+
.idea/vcs.xml
|
111 |
+
.idea/jsLibraryMappings.xml
|
112 |
+
|
113 |
+
# Sensitive or high-churn files:
|
114 |
+
.idea/dataSources.ids
|
115 |
+
.idea/dataSources.xml
|
116 |
+
.idea/dataSources.local.xml
|
117 |
+
.idea/sqlDataSources.xml
|
118 |
+
.idea/dynamic.xml
|
119 |
+
.idea/uiDesigner.xml
|
120 |
+
|
121 |
+
# Gradle:
|
122 |
+
.idea/gradle.xml
|
123 |
+
.idea/libraries
|
124 |
+
|
125 |
+
# Mongo Explorer plugin:
|
126 |
+
.idea/mongoSettings.xml
|
127 |
+
|
128 |
+
.idea/
|
129 |
+
|
130 |
+
## File-based project format:
|
131 |
+
*.iws
|
132 |
+
|
133 |
+
## Plugin-specific files:
|
134 |
+
|
135 |
+
# IntelliJ
|
136 |
+
/out/
|
137 |
+
|
138 |
+
# mpeltonen/sbt-idea plugin
|
139 |
+
.idea_modules/
|
140 |
+
|
141 |
+
# JIRA plugin
|
142 |
+
atlassian-ide-plugin.xml
|
143 |
+
|
144 |
+
**/.DS_Store
|
145 |
+
|
146 |
+
.vscode/
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import skimage
|
4 |
+
|
5 |
+
learn = load_learner("model/model.pkl")
|
6 |
+
|
7 |
+
labels = learn.dls.vocab
|
8 |
+
|
9 |
+
|
10 |
+
def predict(img):
|
11 |
+
img = PILImage.create(img)
|
12 |
+
pred, pred_idx, probs = learn.predict(img)
|
13 |
+
return dict(zip(labels, map(float, probs)))
|
14 |
+
|
15 |
+
|
16 |
+
title = "Pet Breed Classifier"
|
17 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai."
|
18 |
+
article = "<p style='text-align: center'><a href='https://github.com/mchen50' target='_blank'>My Github</a></p>"
|
19 |
+
examples = [
|
20 |
+
"examples/siamese.jpg",
|
21 |
+
"examples/leonberger.jpg",
|
22 |
+
"examples/leonberger.jpg",
|
23 |
+
]
|
24 |
+
interpretation = "default"
|
25 |
+
|
26 |
+
app = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=gr.Image(shape=(512, 512)),
|
29 |
+
outputs=gr.Label(num_top_classes=3),
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
article=article,
|
33 |
+
examples=examples,
|
34 |
+
interpretation=interpretation,
|
35 |
+
)
|
36 |
+
app.queue()
|
37 |
+
app.launch()
|
examples/leonberger.jpg
ADDED
![]() |
examples/samoyed.jpg
ADDED
![]() |
examples/siamese.jpg
ADDED
![]() |
makefile
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
SHELL := /bin/bash
|
2 |
+
|
3 |
+
.ONESHELL:
|
4 |
+
|
5 |
+
setup: clean install
|
6 |
+
|
7 |
+
install:
|
8 |
+
python -m venv venv; \
|
9 |
+
source venv/bin/activate; \
|
10 |
+
pip install -r requirements.txt \
|
11 |
+
|
12 |
+
test: clean
|
13 |
+
source venv/bin/activate; \
|
14 |
+
pytest tests/
|
15 |
+
|
16 |
+
clean-all: clean
|
17 |
+
rm -rf venv;
|
18 |
+
|
19 |
+
clean:
|
20 |
+
rm -rf .coverage; \
|
21 |
+
rm -rf .pytest_cache; \
|
22 |
+
rm -rf tests/.pytest_cache; \
|
23 |
+
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
|
24 |
+
|
25 |
+
check-format:
|
26 |
+
source venv/bin/activate; \
|
27 |
+
black --check --diff .
|
28 |
+
|
29 |
+
format:
|
30 |
+
source venv/bin/activate; \
|
31 |
+
black .
|
model/model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e43d68b43fc7aa8fba2595f3df21fa7160158ff6f623968d66371b25558c6d04
|
3 |
+
size 103041133
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
scikit-image
|