{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "7ec1278b", "metadata": {}, "outputs": [], "source": [ "import os \n", "os.environ[\"OMP_NUM_THREADS\"] = \"1\"" ] }, { "cell_type": "code", "execution_count": 3, "id": "e6b48302", "metadata": {}, "outputs": [], "source": [ "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 4, "id": "4af2b248", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/danielching/miniforge3/envs/fastai/lib/python3.10/site-packages/fastbook/__init__.py:11: UserWarning: Missing `ipywidgets` - please install it\n", " except ModuleNotFoundError: warn(\"Missing `ipywidgets` - please install it\")\n" ] } ], "source": [ "import fastbook" ] }, { "cell_type": "code", "execution_count": 5, "id": "9b33221c", "metadata": {}, "outputs": [], "source": [ "from fastbook import *" ] }, { "cell_type": "code", "execution_count": 6, "id": "59089808", "metadata": {}, "outputs": [], "source": [ "fastbook.setup_book()" ] }, { "cell_type": "code", "execution_count": null, "id": "0f5c2587", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading a new version of this dataset...\n" ] }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " 100.00% [811712512/811706944 01:51<00:00]\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/danielching/miniforge3/envs/fastai/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.\n", " warnings.warn(\n", "/Users/danielching/miniforge3/envs/fastai/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet34_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet34_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n", "Downloading: \"https://download.pytorch.org/models/resnet34-b627a593.pth\" to /Users/danielching/.cache/torch/hub/checkpoints/resnet34-b627a593.pth\n", "100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 83.3M/83.3M [00:09<00:00, 8.84MB/s]\n" ] }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " \n", " 0.00% [0/1 00:00<?]\n", "
\n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
epochtrain_lossvalid_losserror_ratetime

\n", "\n", "

\n", " \n", " 68.48% [63/92 10:03<04:37 0.2883]\n", "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from fastai.vision.all import *\n", "path = untar_data(URLs.PETS)/'images'\n", "\n", "def is_cat(x): return x[0].isupper()\n", "dls = ImageDataLoaders.from_name_func(\n", " path, get_image_files(path), valid_pct=0.2, seed=42,\n", " label_func=is_cat, item_tfms=Resize(224))\n", "\n", "learn = vision_learner(dls, resnet34, metrics=error_rate)\n", "learn.fine_tune(1)" ] }, { "cell_type": "code", "execution_count": null, "id": "05c39c1e", "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.10.4" } }, "nbformat": 4, "nbformat_minor": 5 }