Spaces:
Sleeping
Sleeping
Add image classification functionality with FastAI
Browse files- .gitattributes +1 -0
- app.py +25 -0
- images/cat.jpg +3 -0
- images/catdog.jpg +3 -0
- images/dog.jpg +3 -0
- model.pkl +3 -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 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.vision.all import load_learner
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
def is_cat(x): return x[0].isupper()
|
6 |
+
|
7 |
+
learn = load_learner('model.pkl')
|
8 |
+
|
9 |
+
categories = ('Dog', 'Cat')
|
10 |
+
|
11 |
+
def classify_image(img):
|
12 |
+
pred,idx,probs = learn.predict(img)
|
13 |
+
return dict(zip(categories, map(float, probs)))
|
14 |
+
|
15 |
+
image = gr.Image()
|
16 |
+
label = gr.Label()
|
17 |
+
|
18 |
+
# put all images from the images folder into the examples list
|
19 |
+
examples = []
|
20 |
+
for file in os.listdir("images"):
|
21 |
+
if file.endswith(".jpg"):
|
22 |
+
examples.append("images/" + file)
|
23 |
+
|
24 |
+
iface = gr.Interface(fn=classify_image, inputs="image", outputs="label", examples=examples)
|
25 |
+
iface.launch()
|
images/cat.jpg
ADDED
Git LFS Details
|
images/catdog.jpg
ADDED
Git LFS Details
|
images/dog.jpg
ADDED
Git LFS Details
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:99993089d49b046920f11f6fa2b8d997820513dd143c5954e05aacc12fd80313
|
3 |
+
size 47064766
|