Spaces:
Sleeping
Sleeping
| # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. | |
| # %% auto 0 | |
| __all__ = ['path', 'dls', 'learn', 'categories', 'title', 'description', 'article', 'inputs', 'outputs', 'examples', 'intf', | |
| 'is_cat', 'classify_image'] | |
| # %% app.ipynb 1 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| def is_cat(x): return x[0].isupper() | |
| # %% app.ipynb 4 | |
| path = untar_data(URLs.PETS)/'images' | |
| dls = ImageDataLoaders.from_name_func('.', | |
| get_image_files(path), valid_pct=0.2, seed=42, | |
| label_func=is_cat, | |
| item_tfms=Resize(192)) | |
| # %% app.ipynb 8 | |
| learn = load_learner('model.pkl') | |
| # %% app.ipynb 10 | |
| categories = ('Dog', 'Cat') | |
| def classify_image(img): | |
| img = PILImage.create(img) | |
| pred,pred_idx,probs = learn.predict(img) | |
| return {categories[i]: float(probs[i]) for i in range(len(categories))} # convert probs (pytorch tensor) into floats | |
| # %% app.ipynb 12 | |
| title = "Cat and Dog Classifier" | |
| description = "A classifier built with a fine-tuned Resnet 18 model." | |
| article="<p style='text-align: center'><a href='https://github.com/deenasun' target='_blank'>Deena Sun on Github</a></p>" | |
| inputs= gr.Image() | |
| outputs= gr.Label() | |
| examples = ['dog.jpg', 'cat.jpg', 'dino.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article) | |
| intf.launch(share=True) | |