{ "cells": [ { "cell_type": "code", "execution_count": 10, "id": "568693f3", "metadata": {}, "outputs": [], "source": [ "!pip install -Uqq fastai\n", "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 11, "id": "f4dc2701", "metadata": {}, "outputs": [], "source": [ "path = untar_data(URLs.PETS)/'images'" ] }, { "cell_type": "code", "execution_count": 14, "id": "4a0c1feb", "metadata": {}, "outputs": [], "source": [ "def is_cat(x): return x[0].isupper() " ] }, { "cell_type": "code", "execution_count": 15, "id": "88a468a4", "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": 16, "id": "2473d452", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
epochtrain_lossvalid_losserror_ratetime
00.1929780.0505100.01623800:56
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
epochtrain_lossvalid_losserror_ratetime
00.0763800.0468580.01420801:09
10.0424340.0230650.00879601:09
20.0204550.0211090.00811901:09
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n", "learn.fine_tune(3)" ] }, { "cell_type": "code", "execution_count": 17, "id": "5bc7c88a", "metadata": {}, "outputs": [], "source": [ "learn.export('model.pkl')" ] }, { "cell_type": "code", "execution_count": null, "id": "e8ccd1cf", "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.12.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }