Spaces:
Sleeping
Sleeping
Commit ·
7087444
1
Parent(s): a45fad6
setup fastai vision learner
Browse files- app.py +23 -4
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
def get_data():
|
| 6 |
+
# Label function
|
| 7 |
+
def is_cat(x:string): return x[0].isupper()
|
| 8 |
+
|
| 9 |
+
# Read the dataset from fastai
|
| 10 |
+
path = untar_data(URLs.PETS)/'images'
|
| 11 |
+
return ImageDataLoaders.from_name_func(
|
| 12 |
+
path,get_image_files(path), valid_pct=0.2, seed=42,
|
| 13 |
+
label_func=is_cat, item_tfms=Resize(224))
|
| 14 |
+
|
| 15 |
+
if __name__ == '__main__':
|
| 16 |
+
# This is required for windows users
|
| 17 |
+
multiprocessing.set_start_method('spawn')
|
| 18 |
+
dls = get_data()
|
| 19 |
+
|
| 20 |
+
# Train the model with vision_learner
|
| 21 |
+
learn = vision_learner(dls, resnet34, metrics=error_rate)
|
| 22 |
+
learn.fine_tune(1)
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(fn=learn.predict, inputs="image", outputs="text")
|
| 25 |
+
demo.launch()
|
| 26 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastai==2.7.7
|
| 2 |
+
gradio==3.20.0
|