{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "bf596b85", "metadata": {}, "outputs": [], "source": [ "!pip install -Uqq fastai" ] }, { "cell_type": "code", "execution_count": 3, "id": "f6529ac6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/devudilip/projects/AI/fastai_pet_classifier\r\n" ] } ], "source": [ "!pwd" ] }, { "cell_type": "code", "execution_count": 11, "id": "0473c217", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fastai: 2.8.0\n", "fastcore: 1.8.0\n", "torch: 2.4.1\n" ] } ], "source": [ "import fastai\n", "import fastcore\n", "import torch\n", "\n", "print(f\"fastai: {fastai.__version__}\")\n", "print(f\"fastcore: {fastcore.__version__}\")\n", "print(f\"torch: {torch.__version__}\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "15b4cdfd", "metadata": {}, "outputs": [], "source": [ "from fastai.vision.all import *\n", "import dill" ] }, { "cell_type": "code", "execution_count": 5, "id": "399533a7", "metadata": {}, "outputs": [], "source": [ "path = untar_data(URLs.PETS)/'images'" ] }, { "cell_type": "code", "execution_count": 6, "id": "51e0bbe2", "metadata": {}, "outputs": [], "source": [ "def is_cat(x): return x[0].isupper() " ] }, { "cell_type": "code", "execution_count": 7, "id": "915cbf12", "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": 8, "id": "9bae55cc", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Downloading: \"https://download.pytorch.org/models/resnet18-f37072fd.pth\" to /Users/devudilip/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth\n", "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44.7M/44.7M [00:09<00:00, 4.89MB/s]\n" ] }, { "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.1976390.0457300.01556201:37
" ], "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.0783310.0545970.01826802:22
10.0492790.0382200.01014902:40
20.0239270.0261680.00879602:56
" ], "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": 14, "id": "9119ee21", "metadata": {}, "outputs": [], "source": [ "learn.export('model.pkl', pickle_module=dill)" ] }, { "cell_type": "code", "execution_count": null, "id": "25a3e6c4", "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.9" }, "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 }