{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "fccb1a4c", "metadata": {}, "outputs": [], "source": [ "!pip install -Uqq fastai pandas gdown zipfile" ] }, { "cell_type": "code", "execution_count": null, "id": "a07a5ad4", "metadata": {}, "outputs": [], "source": [ "from fastcore.all import *\n", "from fastai.vision.all import *\n", "from time import sleep\n", "import pandas as pd\n", "from io import StringIO\n", "import gdown\n", "import zipfile" ] }, { "cell_type": "code", "execution_count": null, "id": "5ace4a07", "metadata": {}, "outputs": [], "source": [ "file_id = \"YOUR_FILE_ID\"\n", "url = f'https://drive.google.com/uc?id={file_id}'\n", "output = 'images.zip'\n", "gdown.download(url, output, quiet=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "95f78949", "metadata": {}, "outputs": [], "source": [ "with zipfile.ZipFile('images.zip', 'r') as zip_ref:\n", " zip_ref.extractall('images')" ] }, { "cell_type": "code", "execution_count": null, "id": "8558997b", "metadata": {}, "outputs": [], "source": [ "path = Path('images')\n", "\n", "dls = DataBlock(\n", " blocks=(ImageBlock, CategoryBlock), \n", " get_items=get_image_files, \n", " splitter=RandomSplitter(valid_pct=0.2, seed=42),\n", " get_y=parent_label,\n", " item_tfms=[Resize(192, method='squish')]\n", ").dataloaders(path, bs=64)\n", "\n", "dls.show_batch(max_n=6)" ] }, { "cell_type": "code", "execution_count": null, "id": "b6d7f347", "metadata": {}, "outputs": [], "source": [ "learn = vision_learner(dls, resnet18, metrics=error_rate)\n", "learn.fine_tune(5)" ] }, { "cell_type": "code", "execution_count": null, "id": "ca176cad", "metadata": {}, "outputs": [], "source": [ "learn.export('model.pkl')" ] } ], "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.10.9" } }, "nbformat": 4, "nbformat_minor": 5 }