#!/usr/bin/env python # coding: utf-8 # In[32]: from fastai.vision.widgets import * from fastai.vision.core import * from fastai.learner import * # In[33]: learn_inf = load_learner('rackets.pkl') # In[47]: btn_upload = widgets.FileUpload() btn_classify = widgets.Button(description='Classify') out_image = widgets.Output() lbl_preds = widgets.Label() # In[48]: def fn_classify(change): img = PILImage.create(btn_upload.data[-1]) out_image.clear_output() with out_image: display(img.to_thumb(128,128)) pred,pred_idx,probs = learn_inf.predict(img) lbl_preds.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}' btn_classify.on_click(fn_classify) # ## Do you play tennis? # # I play squash. Often when people see me with my squash racket, they ask 'Do you play tennis?' As my first FastAI project, I thought I'd find out how difficult it is to distinguish a squash and tennis racket, by seeing how fastai's transfer learning models would perform. # # The result is the following web app, where you can upload an image and the fastai model will provides its prediction. Try it out! # In[49]: VBox([widgets.Label(), btn_upload, btn_classify, out_image, lbl_preds]) # In[ ]: