| |
|
|
| |
| __all__ = ['learn', 'categories', 'im_size', 'examples', 'intf', 'classify_image'] |
|
|
| |
| from fastai.vision.all import * |
| import gradio as gr |
| import pathlib |
| plt = platform.system() |
| if plt == 'Windows': pathlib.WindowsPath = pathlib.PosixPath |
|
|
|
|
| |
| learn = load_learner('ft_resnet18_10epochs.pkl') |
|
|
| |
| categories = ['city','town','countryside','ocean'] |
|
|
| def classify_image(img): |
| pred, idx, probs = learn.predict(img) |
| ret = dict( |
| zip(categories, |
| map(float,probs) |
| ) |
| ) |
| return ret |
|
|
| |
| im_size = 192 |
|
|
| |
| |
| examples = ['images/test/035cd8f1-2c9c-45ac-9d67-e0b80043ef22.jpg', |
| 'images/test/b8f604be-44c2-4ad1-badd-f9c2ed0b2b13.jpg', |
| 'images/test/92358e88-e4cd-4cd8-87dd-bfa90d0a861e.jpg', |
| 'images/test/a9614023-dae6-437e-ae88-4677e9035a1d.jpg'] |
|
|
| intf = gr.Interface(fn=classify_image, |
| inputs="image", |
| outputs="label", |
| examples=examples) |
| intf.launch(inline=False) |
|
|