Spaces:
No application file
No application file
# %% | |
#id first_training | |
#caption Results from the first training | |
# CLICK ME | |
#|export | |
from fastai.vision.all import * | |
path = untar_data(URLs.PETS)/'images' | |
def is_cat(x): return x[0].isupper() | |
dls = ImageDataLoaders.from_name_func( | |
path, get_image_files(path), | |
valid_pct=0.2, | |
seed=42, | |
label_func=is_cat, | |
item_tfms=Resize(224) | |
) | |
learn = vision_learner(dls, resnet34, metrics=error_rate) | |
learn.fine_tune(1) | |
# %% | |
from IPython.display import display | |
from ipywidgets import widgets | |
uploader = widgets.FileUpload() | |
display(uploader) | |
# %% | |
#|export | |
# For the book, we can't actually click an upload button, so we fake it | |
uploader = SimpleNamespace(data = ['data/interim/th-1.webp']) | |
# %% | |
#|export | |
img = PILImage.create(uploader.data[0]) | |
is_cat,_,probs = learn.predict(img) | |
print(f"Is this a cat?: {is_cat}.") | |
print(f"Probability it's a cat: {probs[1].item():.6f}") | |