# --- | |
# jupyter: | |
# jupytext: | |
# cell_metadata_filter: -all | |
# custom_cell_magics: kql | |
# text_representation: | |
# extension: .py | |
# format_name: percent | |
# format_version: '1.3' | |
# jupytext_version: 1.11.2 | |
# kernelspec: | |
# display_name: Python 3.9.14 64-bit | |
# language: python | |
# name: python3 | |
# --- | |
# %% | |
from fastai.vision.all import * | |
# %% | |
learn = load_learner("model.pkl") | |
# %% | |
categories = ("Bird", "Forest") | |
# %% | |
def classify_image(img): | |
pred,idx,probs = learn.predict(img) | |
print(probs) | |
print(*map(float,probs)) | |
print(*zip(categories, map(float,probs))) | |
print(dict(zip(categories, map(float,probs)))) | |
return dict(zip(categories, map(float,probs))) | |
# %% [markdown] | |
# | |
# im = PILImage.create("bird.jpg") | |
# im.to_thumb(256, 256) | |
# im | |
# %% [markdown] | |
# classify_image(im) | |