{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "41971c73-6b80-487e-acdc-836991e62c9d", "metadata": {}, "outputs": [], "source": [ "#|default_exp main" ] }, { "cell_type": "code", "execution_count": null, "id": "12171d9b-9822-461a-9c16-3925a275e859", "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr\n", "\n", "def is_cat(x): return x[0].isupper()" ] }, { "cell_type": "code", "execution_count": null, "id": "5f678c6f-a7a8-4da2-845c-2c82f056e890", "metadata": {}, "outputs": [], "source": [ "path = untar_data(URLs.PETS)/'images'" ] }, { "cell_type": "code", "execution_count": null, "id": "9a2dd42f-3fae-4bcf-a7a9-932dedb19684", "metadata": {}, "outputs": [], "source": [ "dls = ImageDataLoaders.from_name_func('.',\n", " get_image_files(path), valid_pct=0.2, seed=42,\n", " label_func=is_cat,\n", " item_tfms=Resize(192))" ] }, { "cell_type": "code", "execution_count": null, "id": "09e8e2ad-30eb-45bc-aa4b-9fe5a256287a", "metadata": {}, "outputs": [], "source": [ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n", "learn.fine_tune(3)" ] }, { "cell_type": "code", "execution_count": null, "id": "b601d058-559a-4246-b4bb-2ad490d826f5", "metadata": {}, "outputs": [], "source": [ "learn.export('model.pkl')" ] }, { "cell_type": "code", "execution_count": null, "id": "5b01bcd5-5c99-4531-9f93-70dc32238dc4", "metadata": {}, "outputs": [], "source": [ "#|export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": null, "id": "77bd55bf-2d8a-4ca0-bf94-ff9078eb124b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.13" } }, "nbformat": 4, "nbformat_minor": 5 }