Ethium commited on
Commit
33d5aa0
1 Parent(s): 76727fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ path = untar_data(URLs.PETS)
3
+ dls = ImageDataLoaders.from_name_re(path, get_image_files(path/'images'), pat='(.+)_\d+.jpg', item_tfms=Resize(460), batch_tfms=aug_transforms(size=224, min_scale=0.75))
4
+ learn = vision_learner(dls, models.resnet50, metrics=accuracy)
5
+ learn.fine_tune(1)
6
+ learn.path = Path('.')
7
+ learn.export()
8
+
9
+ learn = load_learner('your_model.pkl')
10
+
11
+ labels = learn.dls.vocab
12
+ def predict(img):
13
+ img = PILImage.create(img)
14
+ pred,pred_idx,probs = learn.predict(img)
15
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
+
17
+ import gradio as gr
18
+ gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)