learning / app.py
wanghe
test
21961eb
import gradio
from fastai.vision.all import *
def gradioeet(name):
return "Hello " + name + "!!"
def is_cat(x): return x[0].isupper()
# path = untar_data(URLs.DOGS) / 'images'
# dls = ImageDataLoaders.from_name_func('.',
# get_image_files(path), valid_pct=0.2, seed=42,
# label_func=is_cat,
# item_tfms=Resize(192))
#
# dls.valid.show_batch(max_n=4, nrows=1)
#
#
# learn = vision_learner(dls, resnet18, metrics=error_rate)
# learn.fine_tune(3)
# interp = ClassificationInterpretation.from_learner(learn)
# interp.plot_confusion_matrix()
#
# learn.export('model2.pkl')
learn = load_learner("model_last2.pkl")
categories = {"No_Cat", "Cat"}
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
image = gradio.Image(height=192, width=192)
label = gradio.Label()
examples = ["[email protected]", "[email protected]", "[email protected]",
"[email protected]"]
intf = gradio.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)
# demo = gradio.Interface(fn=gradioeet, inputs="text", outputs="text")
# demo.launch(inline=False)