|
|
|
|
|
"""dogs_cats.ipynb |
|
|
|
|
|
Automatically generated by Colaboratory. |
|
|
|
|
|
Original file is located at |
|
|
https://colab.research.google.com/drive/1M-mzhZdFQ2XWBSbLCuKzrmLsm0aLEYxQ |
|
|
|
|
|
## Gradio Pets |
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from fastai.vision.all import * |
|
|
|
|
|
def is_cat(x): return x[0].isupper() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
learn = load_learner('cat_dog.pkl') |
|
|
|
|
|
|
|
|
categories = ('Dog','Cat') |
|
|
def classify_image(img): |
|
|
pred,idx,probs=learn.predict(img) |
|
|
return dict(zip(categories,map(float,probs))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio |
|
|
image = gradio.Image(type='pil') |
|
|
label = gradio.Label() |
|
|
|
|
|
examples = ['dog.jpeg','cat.jpeg'] |
|
|
intf = gradio.Interface(fn=classify_image,inputs=image,outputs=label,examples=examples) |
|
|
intf.launch(inline=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|