deep-learning/practical-deep-learning-for-coders/lesson-2/bear_classifier.ipynb

661 lines
1.1 MiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bear Classifier\n",
"\n",
"Grizzly, Black, or Teddy Bear?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from fastai.data.all import *\n",
"from fastai.vision.all import *\n",
"from fastcore.all import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Image Download"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from duckduckgo_search import DDGS\n",
"\n",
"def search_images(search_term, max_images = 100):\n",
" return L(DDGS().images(search_term, max_results = max_images)).itemgot('image')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <progress value='335872' class='' max='332689' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" 100.96% [335872/332689 00:00&lt;00:00]\n",
" </div>\n",
" "
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDA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sSr4KX1kkqEPIWZSMIKL479DFXyBZEKuz2TRbHa7sDS8FHT2Sy51Vy1Wi/PF8XsNASCv45I6CBaFaRmColI+dTDXvBjydjGRJHcSbJL2Uyj2rS8FMYTckNh/OMh0/lCcbeYe7xsGpTabVJ4glU8mCvEVjJL2fW+tAfbdhs3yeN53nKhDKOWSlAp/UrZM1tFkkoFxECA9K0glcIkYJpIsZ2Eg4ULL2T1fHGh/2QWdpt5wDM7eNzprHfrQX8ANK/iQWJpuO3NPmx2yCdNghj2B3cS0hae2HJwJzvGVhjAtSfAYCso8kuPVa83RYT8eiZfXM1nvUHXDViWcKSJo7arwn+RSagou8BnMgGi7TzqwjpYqAwDF3ceQXMoxmq5SMxOkB+E5cNyeQBv9EpB4QeH5eeBZCKIgv3Att1kOinli7VyeTqfMC3eHe/1wQxHvBfOCUMEleWonX1aBgHgs7imLUe2WoS5dL9exBtsduVyncwngNCasR7pXKlUdkUvCO0D52LZyGIS76cys9mcWlsv71mvxVHrVqMVBMoilCfwD1EOuGJFhHM
"text/plain": [
"<PIL.Image.Image image mode=RGB size=256x171>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from fastdownload import download_url\n",
"\n",
"image_urls = search_images('grizzly', max_images = 1)\n",
"\n",
"destination = 'bears/grizzly.jpg'\n",
"download_url(image_urls[0], destination)\n",
"\n",
"image = Image.open(destination)\n",
"image.to_thumb(256, 256)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"data_set_path = Path('bears')"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from fastai.vision.utils import download_images\n",
"\n",
"bear_types = 'grizzly', 'black', 'teddy'\n",
"\n",
"for bear_type in bear_types:\n",
" destination = data_set_path/bear_type\n",
" destination.mkdir(exist_ok = True)\n",
" search_results = search_images(f'{bear_type} bear', max_images = 100)\n",
" download_images(destination, urls = search_results)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Verify Images"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from fastai.vision.utils import get_image_files, verify_images\n",
"\n",
"failed_images = verify_images(get_image_files(data_set_path))\n",
"failed_images.map(Path.unlink)\n",
"len(failed_images)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Sets"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"bears_data = 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(128),\n",
" batch_tfms = aug_transforms(mult = 2)\n",
").dataloaders(data_set_path)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7YAAAHwCAYAAACSZPPAAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOz9eaxu23bYBf7GnGutr9ndOefec273+s6O7Tg2DkqQS7YDiWSEUkkpiMJFMFEJoRAiIcMfJZWQ4gSJEpQQEgGCpUhQgReXUCIhSsKYchMhZKUSJ37EcRz7PT+/5r7bnHu63XzNauYc9cds1lzf/va55z6/l3fO5RtX5+69VzPXbEY/xhxTVFU5wAEOcIADHOAABzjAAQ5wgAMc4AUF853uwAEOcIADHOAABzjAAQ5wgAMc4AC/FzgYtgc4wAEOcIADHOAABzjAAQ5wgBcaDobtAQ5wgAMc4AAHOMABDnCAAxzghYaDYXuAAxzgAAc4wAEOcIADHOAAB3ih4WDYHuAABzjAAQ5wg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DNYEOvDex7EG+jMGvAqK4KTCo3hVBg8GYW4sy8oxs47jauDq8pzLi3O+/tVvcHl5wZMnD0F7RJTKWESEylZ85tOfpqprMIbf/Me/xbbrmR3f5vYrH2d5dpeTOx9FTAXGMqiiXnHeF7QMYkyY/8qG9TKCRr4R5sLEdQ08I5EmgPr4viSeE9e54PeChzzPGv7SgCheQQcXeIJTNOKH9x4T+VdlE/8Mc6ve0W8vOH/wVdbn73DaKFYCD4C4RtZyeXnJdrtl6LbMGmExs5wsG+ZNxdF8zvHRgqa2zARmdYURw9/7wm9wudqw2vZcPLlCvWO
"text/plain": [
"<Figure size 1200x600 with 8 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"bears_data.train.show_batch(max_n = 8, nrows = 2, unique = True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Train Model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>error_rate</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>1.775698</td>\n",
" <td>0.452870</td>\n",
" <td>0.185185</td>\n",
" <td>00:11</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>error_rate</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.647827</td>\n",
" <td>0.233713</td>\n",
" <td>0.111111</td>\n",
" <td>00:10</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.504331</td>\n",
" <td>0.249407</td>\n",
" <td>0.055556</td>\n",
" <td>00:10</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.387142</td>\n",
" <td>0.229750</td>\n",
" <td>0.055556</td>\n",
" <td>00:10</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>0.331931</td>\n",
" <td>0.204678</td>\n",
" <td>0.055556</td>\n",
" <td>00:10</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"model = vision_learner(bears_data, resnet18, metrics = error_rate)\n",
"model.fine_tune(4)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAdMAAAHp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NkyZKGj4+P8fzzzxsnTpyw9omMjMz2c5RkREdH2+yLlStXGg0bNjRcXFyMKVOmWKeFhIQYhmEYWVlZRsuWLY2yZcsacXFx1uWnp6cbderUMapWrWqkpKTccZtR/HDOFLiDH374QVWrVtXf/va3XPUPCwvTuHHj9PDDD2vKlClq0aKFJk2apO7du2fr+/vvv+v555/Xk08+qfDwcJUuXVqhoaE6cOCAJKlLly6aMmWKJKlHjx5asGCBpk6dmqf6Dxw4oPbt2ys9PV0TJkxQeHi4OnbsqM2bN992vjVr1qht27aKj4/XW2+9peHDh2vLli1q2rRpjucdu3XrpuTkZE2aNEndunVTVFSUxo8fn6saL168qPbt2+vRRx/V5MmT5eLiou7du+urr75S9+7d9eyzz+q9995Tamqqnn/+eSUnJ1vn/fXXX7VlyxZ1795d06dP14ABA7R27Vq1bNlSaWlpkqTmzZtryJAhkqT/+7//04IFC7RgwQLVqlXLupzDhw+rR48eevLJJzVt2jTVr18/W50Wi0Xz5s3TlStXNGDAAGv7m2++qQMHDigyMlLu7u652mYUM/ZOc6AwS0xMNCQZnTp1ylX/PXv2GJKMsLAwm/aRI0cakox169ZZ2wICAgxJxsaNG61t8fHxhouLizFixAhr241R4wcffGCzzNyOTKdMmWJIMhISEm5Zd04j0/r16xu+vr7G+fPnrW179+41HBwcjF69emVbX58+fWyW+dxzzxllypS55TpvaNGihSHJWLhwobXt0KFDhiTDwcHB2LZtm7X9559/zlZnWlpatmVu3brVkGR8/vnn1ravv/7aZjT6Vzf2xcqVK3OcdmNkesPHH39sSDK++OILY9u2bYajo6MxdOjQO24rii9GpsBtJCUlSZI8PT1z1f/HH3+UJA0fPtymfcSIEZKU7dxq7dq11axZM+v3cuXKKTg4WMePH7/rmm9241zrd999p6ysrFzNExMToz179ig0NFQ+Pj7W9rp16+rJJ5+0budf/XWkJknNmjXT+fPnrT/D2/Hw8LAZuQcHB6tUqVKqVauWHn30UWv7jT//9efj6upq/XNGRobOnz+voKAglSpVSrt27crF1l4XGBiotm3b5q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3a2rp1q9asWaMyZcrY9Ktfv74cHR31/vvvKzExUS4uLmrVqpV8fX3ztL7IyEitWLFCUVFRqlSpkqTr4f3Pf/5Ts2fP1qBBg/Jt21CE2PVaYqAIOXLkiNGvXz+jSpUqhrOzs+Hp6Wk0bdrUmDFjhs0DGTIyMozx48cbgYGBRokSJQx/f//bPrThZi1atDBatGhh/X6rW2MM4/rDGOrUqWM4OzsbwcHBxhdffJHt1pi1a9canTp1MipWrGg4OzsbFStWNHr06GEcOXIk2zpufmjDmjVrjKZNmxqurq6Gl5eX0aFDh1s+tOHmW29uPCjhrw9PyMmNhzbc7FY/H0nG4MGDrd8vXrxo9O7d2yhbtqzh4eFhtG3b1jh06FCOt7R8+umnRtWqVQ1HR8ccH9qQk78u58yZM4a3t7fRoUOHbP2ee+45w93d3Th+/PhttxfFE8/mBQDAJM6ZAgBgEmEKAIBJhCkAACYRpgAAmESYAgBgEmEKAIBJPLQhn2VlZenPP/+Up6dnvj6+DABwbxmGoeTkZFWsWFEODrcfexKm+ezPP//M9qYLAEDRdebMGevTrm6FMM1nN957Wab7HDk480qm+8FvUzrbuwQABSA5KUlBgf65ep8xYZrPbhzadXB2lYOzm52rwb1w452nAIqn3Jyy4wIkAABMIkwBADCJMAUAwCTCFAA
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"interpretation = ClassificationInterpretation.from_learner(model)\n",
"interpretation.plot_confusion_matrix()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABKwAAAEJCAYAAAC5Tr+zAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd5wV1dn4v+fMzG27bGFZqoqADdFoYlciVkTsSjEWNGhU0FgxeWP0tSQmMZZoYiwxClGxF3xVYsNesUaxxAYqnaVtu/dOOef3x5mZ3cvuwoKKwG++n89VdubMzDkzpzznOc/zHKG11iQkJCQkJCQkJCQkJCQkJCQkJKwjyB86AwkJCQkJCQkJCQkJCQkJCQkJCa1JFFYJCQkJCQkJCQkJCQkJCQkJCesUicIqISEhISEhISEhISEhISEhIWGdIlFYJSQkJCQkJCQkJCQkJCQkJCSsUyQKq4SEhISEhISEhISEhISEhISEdYpEYZWQkJCQkJCQkJCQkJCQkJCQsE6RKKwSEhISEhISEhISEhISEhISEtYpEoVVQkJCQkJCQkJCQkJCQkJCQsI6RaKwSkhISEhISEhISEhISEhISEhYp0gUVgkJCQkJGwRCiPg3adKk+PikSZNKzn3f7LXXXvGzTjzxxO/9eQmrxyWXXBJ/n0033fSHzk7CSlib32pNn3XiiSfG1+21114l59aVPikhISEhIWF9JVFYJSQkJCS0y/PPP18yqWr9Ky8vZ+utt+aXv/wlX3755Q+d1bXG+qqMuvDCCxFCMG7cuDbn5s+fj+M4Jd93xIgR39mz11cF0XHHHYcQgiuuuAIoVUxsCEqGVZUv+lmWRU1NDXvuuSd/+9vfcF33B875hk2izEpISEhISGjB/qEzkJCQkJCw/tHU1MTHH3/Mxx9/zG233cYjjzzCfvvt90Nnq1122mknrrzyyrX2vHHjxnHwwQcDsM0226y1566Mhx9+GIDDDz+8zbk77rgD3/dLjj366KMsWbKErl27ro3srXN4nsfjjz8OtP/O1ndWp3xKKZYsWcJLL73ESy+9xO23384zzzxDZWXlWsjpus/RRx8dt/ONN964U9es7T4pISEhISFhfSVRWCUkJCQkdIrRo0ez44474rour732Go899hgAzc3NHH/88cyaNYt0Or3Se9TX11NRUbE2shszaNAgBg0atNaeN3r06LX2rM7w+eef89FHH1FRUcHee+/d5vy//vWvNsdc1+Wuu+7ijDPOWBtZXOd4/vnnWbZsGVtttRVbbrnlD52d75zOlC9SqCxbtox77rmHL774AoC33nqLSy65hL/85S+rfE4QBBSLRXK53HeX+XWMYcOGMWzYsNW6Zm33SQkJCQkJCesriUtgQkJCQkKnGDZsGBMmTOCCCy7g0Ucf5dhjj43PzZ8/n1deeaWNG+Hnn3/OVVddxcCBA0mn04wZMya+RinFHXfcwdChQ+nevTupVIra2loOOuggpk6d2m4efN/nT3/6E5tvvjnpdJoBAwbw+9//Hs/zOsz3qlxsfN/ntttuY+jQofTo0SPOx6677sqll14KtLi1vfDCC/F1//rXv0ruO2vWLGDVboOffvop48aNY8sttySXy5HL5dhiiy049dRT+eSTT9qkXzFGzrx58zjllFPo1asX6XSagQMHcsstt3RY/si6avjw4aRSqZJzb775Jh9++GH89xZbbFHy3lbGM888w+jRo+nbty+ZTIbKykq22WYbxo8fT11dXVwXoncI8NVXX7Ub12dlcYBWrFPRewZ47733GD9+PLvssgt9+vQhm82SyWTo27cvo0eP5uWXX15pGTpiypQpwHdjXTVt2jRGjBjBRhttRDqdpqKigp/85CdcfPHFLFmypE36r776ilNPPZXNN988Lk+fPn3YY489OPfcc/n4449L0k+aNIm99tqLbt264TgO1dXVbLnllowePZobbrhhjcs3YcIEJkyYwO9//3veeOONEkXzgw8+GP97xW/39ddfc/zxx9OjRw8cx+Gpp56K086ZM4fzzz+fbbfdlvLycjKZDJtuuinHHXcc06dPX+W7bGho4LzzzmPjjTcmk8mw9dZbc/3116O1Lkn3XdSLzj5rZXW3I9rrk2bNmoUQgp///OclaVunu+SSS7j44ovjvzfeeGOUUiXpP/zww5Jr3njjjU7lKSEhISEhYZ1EJyQkJCQktMNzzz2ngfg3ceLEkvPXX399yfnJkye3ueanP/1pyd+HHXaY1lrr5uZmvd9++5WcW/F37rnntsnT0Ucf3W7agw46qMO8Tpw4seRcaxYvXqx32mmnDvNQWVmptdb64osvXmleAT1z5kyttdZDhgyJj51wwgklz7vvvvt0JpPp8B7pdFrffffdJdeccMIJ8fn+/fvrXr16tXvtrbfe2u533H333TWg77333jbnxo0bF1+/0UYb6SlTppTc8/33329zjVJKn3zyySt9F++++26butDeL/pOrcs4ZMiQkueteJ/oPWut9d/+9reV3l8I0abetv6Wffv2bbd8ffr00YB+44032v0OnRWfzj333JXmr0+fPnrGjBlx+gULFuja2tqVXnPjjTe2W5b2fj169PjOyrfjjjvG5xzHafe6zTffXPfs2bPkPg8//LDWWusXXnhBV1dXd5hXKaW++uqrS57Zunw9evQoyUPr3y9/+cuS675tvVidZ62s7rZX17Vuv0+aOXPmKtvLxRdfrOfOnasdx4mPPf744yXP/N///d/43NZbb93mOyYkJCQkJKxPJC6BCQkJCQlrxGuvvVbyd8+ePdukeemllxg0aBCHHHIIWmssywLgnHPO4ZlnngEglUpx9NFHs/nmm/PBBx9w//33o7XmmmuuYYcdduCYY44B4IEHHuCee+6J773ZZpsxatQo5syZwx133LFGZTj++ON58803478HDhzI8OHDSafTvPvuu7F1wtChQykvL+fGG2+Mg8zvuOOOJe5/q4r39Pnnn3P88cdTLBYBqKmp4YQTTkAIwb/+9S/q6uooFouccMIJ7LDDDmy++eZt7vHll1+SyWQYN24c2WyWG2+8kXw+D8Cf//xnxo4dW5J+wYIFvP7666TTaQ488MCSc8ViseR9jho1igMPPJCqqiqWLVsGGEuQq6++uuS6q666in/+85/x3zU1NYwaNYoePXrw6aef8sgjjwAwYMAArrzySp566imefvppAKqrq7ngggvia3faaaeVvrNVkU6n2XXXXdl+++2pqamhvLyc5cuXM23aNN5880201px33nmMHj2abDbbqXu++eabzJkzhz59+nyr/N1xxx1cc8018d+DBg3iiCOOYO7cufzrX/8iCALmzJnDkUceyYcffoht2zz44IMsWrQIMO/q5z//OTU1NcydO5dPPvmEl156qeQZN954Y/zv/fbbj7322oumpia++eYbXn755bhufNvyLV68mE8//TT+u722DvDZZ58BcOSRR7Lddtvx1VdfUVlZybJlyzjyyCNZunQpANlslp///OdUVFRw991389VXX6GUYsKECeywww4MGTKkzb0XLFjAsmXLOO2006iqquLOO+9k9uzZAPztb3/jqKOOiq/7tvVidZ71XdG1a1euvPJK3nrrLe699974eOtYV7vvvju9evXiqKOOitvuP//5T4YPHx6nuf/+++N/r2itlZCQkJCQsN7xw+rLEhISEhLWVVa0bBk9erS+8sor9eWXX64POeSQNpYc+Xy+zTW77rqrzufzJfddvHixtm07TnPbbbeVnB8/fnx87sc//nF8/IADDoiPV1ZW6sWLF8fnLr/88tWyZtBa6/fff7/k+PDhw7XruiV5+eKLL0r+Xpn11KrSnHXWWSXWJB988EF87oMPPtBSyvj8WWedFZ9b0fJlypQp8blrr7225Fx9fX1JXm6++WYN6AMPPLBNPu+9996Sa998802ttdZjx44t+a6e58XXBEFQYgHUp08fvWDBgpL71tXV6WXLlsV/r8qiacUyro6FVcR//vMffeedd+rrrrtOX3nllfr3v/99yTUvvvhip/Pzm9/8RgN63LhxHea
"text/plain": [
"<Figure size 1500x300 with 5 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"interpretation.plot_top_losses(5, nrows = 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Clean Data Set\n",
"\n",
"**NOTE:** This currently doesn't work in Visual Studio Code.\n",
"\n",
"**TODO:** Jupyter Notebook instead?"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from fastai.vision.widgets import ImageClassifierCleaner\n",
"\n",
"cleaner = ImageClassifierCleaner(model)\n",
"cleaner"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Export Model"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"model.export()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}