implemented dog cat classifier
Browse files- app.py +28 -4
- cat.jpg +0 -0
- dog.jpg +0 -0
- hamster.jpg +0 -0
- models/dog_cat_model.pkl +3 -0
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: dog_cat_predicter.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'labels', 'image', 'label', 'examples', 'interface', 'is_cat', 'predict_image']
|
5 |
+
|
6 |
+
# %% dog_cat_predicter.ipynb 1
|
7 |
+
from fastai.vision.all import *
|
8 |
import gradio as gr
|
9 |
|
10 |
+
# %% dog_cat_predicter.ipynb 3
|
11 |
+
def is_cat(x): return x[0].isupper()
|
12 |
+
|
13 |
+
learn = load_learner('models/dog_cat_model.pkl')
|
14 |
+
|
15 |
+
# %% dog_cat_predicter.ipynb 5
|
16 |
+
labels = ['Dog', 'Cat']
|
17 |
+
|
18 |
+
def predict_image(img):
|
19 |
+
#Function to predict input image and return a dictionary with each label and probability (as a float)
|
20 |
+
pred,pred_idx,probs = learn.predict(img)
|
21 |
+
return dict(zip(labels, map(float, probs)))
|
22 |
+
|
23 |
+
# %% dog_cat_predicter.ipynb 7
|
24 |
+
#Define the Gradio Interface
|
25 |
+
|
26 |
+
image = gr.inputs.Image(shape=(224, 224))
|
27 |
+
label = gr.outputs.Label()
|
28 |
+
examples = ['dog.jpg', 'cat.jpg', 'hamster.jpg']
|
29 |
|
30 |
+
interface = gr.Interface(fn=predict_image, inputs=image, outputs=label, examples=examples)
|
31 |
+
interface.launch(inline=False)
|
cat.jpg
ADDED
dog.jpg
ADDED
hamster.jpg
ADDED
models/dog_cat_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d64b3d64e418b1660bd37c832374ddc8052f350ea003ab7c3dd20689b84c83dd
|
3 |
+
size 47071225
|