| | |
| | """Copy of dogs_cats.ipynb |
| | |
| | Automatically generated by Colaboratory. |
| | |
| | Original file is located at |
| | https://colab.research.google.com/drive/1pu75-TcRCtcDPFHn3zA6IqSsH8BM5yka |
| | |
| | ## Gradio Pets |
| | |
| | # New Section |
| | """ |
| |
|
| | |
| |
|
| |
|
| | |
| |
|
| | from fastai.vision.all import * |
| | import gradio as gr |
| |
|
| | def is_cat(x): return x[0].isupper() |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | |
| |
|
| | |
| | |
| |
|
| | |
| |
|
| | |
| | learn= load_learner('model.pk1') |
| |
|
| | categories= ('Dog', 'Cat') |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| |
|
| |
|
| | def classify_image(img): |
| | pred,idx,probs= learn.predict(img) |
| | return dict(zip(categories, map(float, probs))) |
| |
|
| | im=PILImage.create('dog.jpg') |
| | im.thumbnail((192,192)) |
| | im |
| |
|
| | learn.predict(im) |
| |
|
| | classify_image(im) |
| |
|
| | examples= ['dog.jpg', 'cat.jpg'] |
| |
|
| | gr.Interface(fn=classify_image, inputs=[gr.Image(type="pil")], outputs=[gr.Label(num_top_classes=2)], examples=examples).launch() |