File size: 1,311 Bytes
c43f521 c9c2cca 28ffd84 c43f521 28ffd84 c9c2cca c43f521 21961eb c43f521 c9c2cca c43f521 c9c2cca c43f521 c9c2cca c43f521 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
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)
|