fastbook/clean/05_pet_breeds.ipynb

1807 lines
600 KiB
Plaintext
Raw Normal View History

2020-03-06 18:19:03 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#hide\n",
2020-09-03 22:51:00 +00:00
"!pip install -Uqq fastbook\n",
"import fastbook\n",
"fastbook.setup_book()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#hide\n",
"from fastbook import *"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"# Image Classification"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"## From Dogs and Cats to Pet Breeds"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
2020-08-21 19:36:27 +00:00
"from fastai.vision.all import *\n",
2020-03-06 18:19:03 +00:00
"path = untar_data(URLs.PETS)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#hide\n",
"Path.BASE_PATH = path"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(#3) [Path('annotations'),Path('images'),Path('models')]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"path.ls()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(#7394) [Path('images/great_pyrenees_173.jpg'),Path('images/wheaten_terrier_46.jpg'),Path('images/Ragdoll_262.jpg'),Path('images/german_shorthaired_3.jpg'),Path('images/american_bulldog_196.jpg'),Path('images/boxer_188.jpg'),Path('images/staffordshire_bull_terrier_173.jpg'),Path('images/basset_hound_71.jpg'),Path('images/staffordshire_bull_terrier_37.jpg'),Path('images/yorkshire_terrier_18.jpg')...]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(path/\"images\").ls()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fname = (path/\"images\").ls()[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['great_pyrenees']"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"re.findall(r'(.+)_\\d+.jpg$', fname.name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pets = DataBlock(blocks = (ImageBlock, CategoryBlock),\n",
" get_items=get_image_files, \n",
" splitter=RandomSplitter(seed=42),\n",
" get_y=using_attr(RegexLabeller(r'(.+)_\\d+.jpg$'), 'name'),\n",
" item_tfms=Resize(460),\n",
" batch_tfms=aug_transforms(size=224, min_scale=0.75))\n",
"dls = pets.dataloaders(path/\"images\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Presizing"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
2020-05-14 12:18:31 +00:00
"hide_input": false
2020-03-06 18:19:03 +00:00
},
"outputs": [
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAACmCAYAAAB5qlzZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nOy8ya5lWZqt9f2zWtUuTmlmXrtHkXEzCVK6onHRbd4ubZ4AISFegBZdXoL7AjwK4gohkcrIjIiMygszO3aqXa1iljTmdk+QrjsQkUQ0sF86DbNt+9hae8815vjHGP+UUgrv6329r/f1vv48pf7SF/C+3tf7el//f6r3oPu+3tf7el9/xnoPuu/rfb2v9/VnrPeg+77e1/t6X3/Geg+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0DpXiaFr0EpRkiGFmTyPlLanZIWyDpZS29e4UJSgXAcoio6I1JYKgJLJyQMgohHRQIZSUGQKiq6toGWbysiGVY9rO+LiOdz9nnn/QCzTnwidf3zN08I4zrTOVCYmtR2uD2QFCgqokjCqoBByDqisINUHWYyhbR0lRxpnUJLRBnIIaD0jurbz2AZBaLsWlCKrUltTyndAGONMzpkYQCmFURprDLaxaNegjAKtyMeAnL+biIMo5JS/I5clZ+JyAsCPI8s4E7NQxIJoSoGSChICOWa0NRjnSNljuhY7bBBRdKsO6xxeEqPVpJyJsQLl+X+qLPfbH+pmAP9MdEUUpUiVGqxCaUWOilQiJWaKCLkUcgHrLG3fMaxWdF2Hc67KA7mCpDIK21iM1eQ
2020-03-06 18:19:03 +00:00
"text/plain": [
2020-04-28 17:12:59 +00:00
"<Figure size 432x216 with 2 Axes>"
2020-03-06 18:19:03 +00:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"dblock1 = DataBlock(blocks=(ImageBlock(), CategoryBlock()),\n",
" get_y=parent_label,\n",
" item_tfms=Resize(460))\n",
"dls1 = dblock1.dataloaders([(Path.cwd()/'images'/'grizzly.jpg')]*100, bs=8)\n",
"dls1.train.get_idxs = lambda: Inf.ones\n",
"x,y = dls1.valid.one_batch()\n",
"_,axs = subplots(1, 2)\n",
"\n",
"x1 = TensorImage(x.clone())\n",
"x1 = x1.affine_coord(sz=224)\n",
"x1 = x1.rotate(draw=30, p=1.)\n",
"x1 = x1.zoom(draw=1.2, p=1.)\n",
"x1 = x1.warp(draw_x=-0.2, draw_y=0.2, p=1.)\n",
"\n",
"tfms = setup_aug_tfms([Rotate(draw=30, p=1, size=224), Zoom(draw=1.2, p=1., size=224),\n",
" Warp(draw_x=-0.2, draw_y=0.2, p=1., size=224)])\n",
"x = Pipeline(tfms)(x)\n",
"#x.affine_coord(coord_tfm=coord_tfm, sz=size, mode=mode, pad_mode=pad_mode)\n",
"TensorImage(x[0]).show(ctx=axs[0])\n",
"TensorImage(x1[0]).show(ctx=axs[1]);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Checking and Debugging a DataBlock"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgQAAACzCAYAAAD2UgRyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nOy9eZRlx13n+fn9IuLe+97LpbIWlVSSJdmSbEveN7xiTDPmsC/TzTQHzNKmgZmhe4ZuONPQ9rC0aQ69DXiYHvocaPAwcIBuGBrG0ICNbRYbW9jgBdvaLGspbbVlVma+5d4bEb/5I26WUuVSycKyy2O97zmZ790tbtwbEb/l+/tFPDEzllhiiSWWWGKJJzf0UldgiSWWWGKJJZa49FgaBEssscQSSyyxxNIgWGKJJZZYYokllgbBEkssscQSSyzB0iBYYoklllhiiSVYGgRLLLHEEksssQRPIoNARN4lIr9wqesBICJ3icgbL3U9lvj8h4i8RkRMRK661HXZwxNZp6Gc1+3bfsyxISJvEZG3f6b3XmKJJR4Jf6krsMQSS1wU7wGuAE5c6oosscQSX9hYGgRLLPF5ChGpzKwDHrzUdVliiSW+8PGkCRkMUBH5KRE5JSLbIvILIjLaOygi/1hEbhGRhYjcLiJvEBG/7/i3iMj7ROTsUMbvicjT999ARF4gIu8dyrhNRP7eY9GgIuJF5MdE5JPDdR8Vke/97LyCJS4GEXntEF46M7Tzn4jIF+07bkM/+Q0RmYrIPUMbr4vIr4rIjojcKSJ/97xyjw5U98nhnHeLyKv3Hd+j4b9aRP5cRBbA91yInheR60TkPw91nInIh0Xka4ZjGyLyK0O95iJyq4j8gIjIvuvfI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SVB6aOUjOwf5GFqdE84fRVFMP4lJdv5ZyhGwuIi9foeirB8A8Wb+WPgO4A7P9MHXuLTh5llStjoOkpOwFso7ffAZ1juguLBvh/4JUpY6v+hzEQ5P7b/WGU9ALyK0o9/n9IX/yUPe95vosTPf4cSK92gKMzPBn5wuN8HgVcCX29mx4d6RuDvU9iVv6bM3HgD+8bLp4nXD+W/lfJc91ESBvfjDcDPU9rqo5Rx+joz++OhLkYJ10yBPxvK+q8U4+li43KJS49HldnA/0XpV/8HZWw9hU/t6z8zHH8zpR++jGIkLNv9ApAh63KJzxJE5BqKUfF1Zvb/XuLqLLHEEoCIrFJmfrzRzH72UtdniU+FiLwLuMPM/uETXO4vAs8zsxc9keV+IeDJnlT4hEPKuuz3USjiayhzyu+mJCQuscQSlwAi8nWUEMHHKazFj1Jo4/90Keu1xGcXInKMwg69kzJr62sp08n/0aWs1+crlgbBE49DlIVgrgTOUKbJfNN5U7yWWOLzFiLyUR45zXI/fsXM/vvPZX2eIIwpa3tcSwkdfAB4lZk9dCkrtcRnHYkSBnwTZQruHcD/YGY/f0lr9XmKZchgiSWWeASGMFd4lMPbZrb8oaUllvgCxNIgWGKJJZZYYoklnnSzDJZYYoklllhiiQvgojkEX/OSp9uBcU0TPBurI0beMxl5mqCsjMfUlWdl0hCcow4BRFDnUBW8d3inVE5x3iEoThUkgwhioAJlpeDhzwBL9F2L5cRivkNKib7vIIOhiAiqDucdznlUBecD6hw+eFQU7wKo4IIf9leoKOor1HuaZkSoR4CAOgRBUBRHVocZiHgMJVvAUBaLRIyZWRfpojHtE50l0niCNg3VyhohBCaTCVUIVHWNcx7xDhHFuVJ3EV+eQRQERLQsaad7x+Xcd+Dc54Wwx+6c+8SwC6w3J8MOGf7JRdaGudj9/jbnnX/Z3+aizwTfeuQKQzOpjeSNEYYQ44yzbWbeQReh7Tq
2020-03-06 18:19:03 +00:00
"text/plain": [
"<Figure size 648x216 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2020-03-19 13:21:55 +00:00
"dls.show_batch(nrows=1, ncols=3)"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Setting-up type transforms pipelines\n",
"Collecting items from /home/jhoward/.fastai/data/oxford-iiit-pet/images\n",
"Found 7390 items\n",
"2 datasets of sizes 5912,1478\n",
"Setting up Pipeline: PILBase.create\n",
"Setting up Pipeline: partial -> Categorize\n",
"\n",
"Building one sample\n",
" Pipeline: PILBase.create\n",
" starting from\n",
" /home/jhoward/.fastai/data/oxford-iiit-pet/images/american_pit_bull_terrier_31.jpg\n",
" applying PILBase.create gives\n",
" PILImage mode=RGB size=500x414\n",
" Pipeline: partial -> Categorize\n",
" starting from\n",
" /home/jhoward/.fastai/data/oxford-iiit-pet/images/american_pit_bull_terrier_31.jpg\n",
" applying partial gives\n",
" american_pit_bull_terrier\n",
" applying Categorize gives\n",
" TensorCategory(13)\n",
"\n",
"Final sample: (PILImage mode=RGB size=500x414, TensorCategory(13))\n",
"\n",
"\n",
"Setting up after_item: Pipeline: ToTensor\n",
"Setting up before_batch: Pipeline: \n",
"Setting up after_batch: Pipeline: IntToFloatTensor\n",
"\n",
"Building one batch\n",
"Applying item_tfms to the first sample:\n",
" Pipeline: ToTensor\n",
" starting from\n",
" (PILImage mode=RGB size=500x414, TensorCategory(13))\n",
" applying ToTensor gives\n",
" (TensorImage of size 3x414x500, TensorCategory(13))\n",
"\n",
"Adding the next 3 samples\n",
"\n",
"No before_batch transform to apply\n",
"\n",
"Collating items in a batch\n",
"Error! It's not possible to collate your items in a batch\n",
"Could not collate the 0-th members of your tuples because got the following shapes\n",
"torch.Size([3, 414, 500]),torch.Size([3, 375, 500]),torch.Size([3, 500, 281]),torch.Size([3, 203, 300])\n"
]
},
{
"ename": "RuntimeError",
"evalue": "invalid argument 0: Sizes of tensors must match except in dimension 0. Got 414 and 375 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022060824/work/aten/src/TH/generic/THTensor.cpp:612",
"output_type": "error",
"traceback": [
2020-04-28 17:12:59 +00:00
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-11-8c0a3d421ca2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0msplitter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mRandomSplitter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m get_y=using_attr(RegexLabeller(r'(.+)_\\d+.jpg$'), 'name'))\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mpets1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msummary\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;34m\"images\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
2020-08-21 19:36:27 +00:00
"\u001b[0;32m~/git/fastai/fastai/data/block.py\u001b[0m in \u001b[0;36msummary\u001b[0;34m(self, source, bs, show_batch, **kwargs)\u001b[0m\n\u001b[1;32m 182\u001b[0m \u001b[0mwhy\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_find_fail_collate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 183\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Make sure all parts of your samples are tensors of the same size\"\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mwhy\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mwhy\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 184\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 185\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mf\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mf\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mdls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mafter_batch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfs\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m'noop'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m!=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/git/fastai/fastai/data/block.py\u001b[0m in \u001b[0;36msummary\u001b[0;34m(self, source, bs, show_batch, **kwargs)\u001b[0m\n\u001b[1;32m 176\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"\\nCollating items in a batch\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 177\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 178\u001b[0;31m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdls\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 179\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mretain_types\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_listy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 180\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/git/fastai/fastai/data/load.py\u001b[0m in \u001b[0;36mcreate_batch\u001b[0;34m(self, b)\u001b[0m\n\u001b[1;32m 125\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mretain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mres\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mretain_types\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mres\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mis_listy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 126\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcreate_item\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mit\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdataset\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 127\u001b[0;31m \u001b[0;32mdef\u001b[0m \u001b[0mcreate_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mfa_collate\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfa_convert\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprebatched\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 128\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdo_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mretain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbefore_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdevice\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdevice\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/git/fastai/fastai/data/load.py\u001b[0m in \u001b[0;36mfa_collate\u001b[0;34m(t)\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m return (default_collate(t) if isinstance(b, _collate_types)\n\u001b[0;32m---> 46\u001b[0;31m \u001b[0;32melse\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfa_collate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 47\u001b[0m else default_collate(t))\n\u001b[1;32m 48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/git/fastai/fastai/data/load.py\u001b[0m in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m return (default_collate(t) if isinstance(b, _collate_types)\n\u001b[0;32m---> 46\u001b[0;31m \u001b[0;32melse\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfa_collate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 47\u001b[0m else default_collate(t))\n\u001b[1;32m 48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/git/fastai/fastai/data/load.py\u001b[0m in \u001b[0;36mfa_collate\u001b[0;34m(t)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mfa_collate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 45\u001b[0;31m return (default_collate(t) if isinstance(b, _collate_types)\n\u001b[0m\u001b[1;32m 46\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfa_collate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mt\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m else default_collate(t))\n",
2020-03-06 18:19:03 +00:00
"\u001b[0;32m~/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/collate.py\u001b[0m in \u001b[0;36mdefault_collate\u001b[0;34m(batch)\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0mstorage\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstorage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_new_shared\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0melem\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnew\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstorage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 55\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstack\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 56\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0melem_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__module__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'numpy'\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0melem_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m'str_'\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0melem_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m'string_'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mRuntimeError\u001b[0m: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 414 and 375 in dimension 2 at /opt/conda/conda-bld/pytorch_1579022060824/work/aten/src/TH/generic/THTensor.cpp:612"
]
}
],
"source": [
"pets1 = DataBlock(blocks = (ImageBlock, CategoryBlock),\n",
" get_items=get_image_files, \n",
" splitter=RandomSplitter(seed=42),\n",
" get_y=using_attr(RegexLabeller(r'(.+)_\\d+.jpg$'), 'name'))\n",
"pets1.summary(path/\"images\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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",
2020-04-28 17:12:59 +00:00
" <td>1.551305</td>\n",
" <td>0.322132</td>\n",
" <td>0.106225</td>\n",
" <td>00:19</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" </tbody>\n",
"</table>"
],
"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",
2020-04-28 17:12:59 +00:00
" <td>0.529473</td>\n",
" <td>0.312148</td>\n",
" <td>0.095399</td>\n",
2020-03-06 18:19:03 +00:00
" <td>00:23</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
2020-04-28 17:12:59 +00:00
" <td>0.330207</td>\n",
" <td>0.245883</td>\n",
" <td>0.080514</td>\n",
" <td>00:24</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fine_tune(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"## Cross-Entropy Loss"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Viewing Activations and Labels"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x,y = dls.one_batch()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
2020-04-28 17:12:59 +00:00
"TensorCategory([ 0, 5, 23, 36, 5, 20, 29, 34, 33, 32, 31, 24, 12, 36, 8, 26, 30, 2, 12, 17, 7, 23, 12, 29, 21, 4, 35, 33, 0, 20, 26, 30, 3, 6, 36, 2, 17, 32, 11, 6, 3, 30, 5, 26, 26, 29, 7, 36,\n",
" 31, 26, 26, 8, 13, 30, 11, 12, 36, 31, 34, 20, 15, 8, 8, 23], device='cuda:5')"
2020-03-06 18:19:03 +00:00
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
2020-04-28 17:12:59 +00:00
"tensor([9.9911e-01, 5.0433e-05, 3.7515e-07, 8.8590e-07, 8.1794e-05, 1.8991e-05, 9.9280e-06, 5.4656e-07, 6.7920e-06, 2.3486e-04, 3.7872e-04, 2.0796e-05, 4.0443e-07, 1.6933e-07, 2.0502e-07, 3.1354e-08,\n",
" 9.4115e-08, 2.9782e-06, 2.0243e-07, 8.5262e-08, 1.0900e-07, 1.0175e-07, 4.4780e-09, 1.4285e-07, 1.0718e-07, 8.1411e-07, 3.6618e-07, 4.0950e-07, 3.8525e-08, 2.3660e-07, 5.3747e-08, 2.5448e-07,\n",
" 6.5860e-08, 8.0937e-05, 2.7464e-07, 5.6760e-07, 1.5462e-08])"
2020-03-06 18:19:03 +00:00
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"preds,_ = learn.get_preds(dl=[(x,y)])\n",
"preds[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(37, tensor(1.0000))"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(preds[0]),preds[0].sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Softmax"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD7CAYAAACRxdTpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXiV5Z3/8fcXCCQk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dM6tRU7iJR4OWVu7j5+VWcMKIvj155AvE99Nbu7PQKEIlwB4t9+siGYu/ZXW9rUbmLRLQln+/h5udXMWNkMo9eeQJx3bsGHUnCRKhLIUUkzPwlK5ebnl3J8cP6sODKdBW7/AOVu0gEej87nxsXrWTS4CQeu0pTMfJFKneRCJOxrYDvPZnB6P4JPHHVdK2KkRap3EUiyNrdxVy1cBmDkuJ48prpJPVUsUvLVO4iEWLrvjIuf/QzEnp048lrZ9AvQZ88lUNTuYtEgLziSuYu+JR6d568ZgaDe8cFHUnCnMpdJMwVV9ZwxWPLKCirZuFVJzCmf0Lr3ySdnspdJIxV1dYx78nlbNxbwkOXTeO4Ib2DjiQRQuunRMJUfb3z4xc+5+PN+7nvojROGac7lknodOYuEqZ+/dZ6Xsvcza1nj+eCqUOCjiMRRuUuEoae+t/tPPz+Fi47cRjfO2VU0HEkAqncRcLMu+v3cucra/ja+P7cde4kzCzoSBKBVO4iYWTt7mJuXLSSiYMSeeA7U+nWVW9ROTJ65YiEibziSq59fBlJcTEsuEJ7ssvR0atHJAxUVNfx3ScyKKyo4YV5M0lNjA06kkQ
2020-03-06 18:19:03 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_function(torch.sigmoid, min=-4,max=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#hide\n",
"torch.random.manual_seed(42);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[ 0.6734, 0.2576],\n",
" [ 0.4689, 0.4607],\n",
" [-2.2457, -0.3727],\n",
" [ 4.4164, -1.2760],\n",
" [ 0.9233, 0.5347],\n",
" [ 1.0698, 1.6187]])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"acts = torch.randn((6,2))*2\n",
"acts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[0.6623, 0.5641],\n",
" [0.6151, 0.6132],\n",
" [0.0957, 0.4079],\n",
" [0.9881, 0.2182],\n",
" [0.7157, 0.6306],\n",
" [0.7446, 0.8346]])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"acts.sigmoid()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.6025, 0.5021, 0.1332, 0.9966, 0.5959, 0.3661])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(acts[:,0]-acts[:,1]).sigmoid()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[0.6025, 0.3975],\n",
" [0.5021, 0.4979],\n",
" [0.1332, 0.8668],\n",
" [0.9966, 0.0034],\n",
" [0.5959, 0.4041],\n",
" [0.3661, 0.6339]])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sm_acts = torch.softmax(acts, dim=1)\n",
"sm_acts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Log Likelihood"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"targ = tensor([0,1,0,1,1,0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([[0.6025, 0.3975],\n",
" [0.5021, 0.4979],\n",
" [0.1332, 0.8668],\n",
" [0.9966, 0.0034],\n",
" [0.5959, 0.4041],\n",
" [0.3661, 0.6339]])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sm_acts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.6025, 0.4979, 0.1332, 0.0034, 0.4041, 0.3661])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"idx = range(6)\n",
"sm_acts[idx, targ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table ><thead> <tr> <th class=\"col_heading level0 col0\" >3</th> <th class=\"col_heading level0 col1\" >7</th> <th class=\"col_heading level0 col2\" >targ</th> <th class=\"col_heading level0 col3\" >idx</th> <th class=\"col_heading level0 col4\" >loss</th> </tr></thead><tbody>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row0_col0\" class=\"data row0 col0\" >0.602469</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row0_col1\" class=\"data row0 col1\" >0.397531</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row0_col2\" class=\"data row0 col2\" >0</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row0_col3\" class=\"data row0 col3\" >0</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row0_col4\" class=\"data row0 col4\" >0.602469</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row1_col0\" class=\"data row1 col0\" >0.502065</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row1_col1\" class=\"data row1 col1\" >0.497935</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row1_col2\" class=\"data row1 col2\" >1</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row1_col3\" class=\"data row1 col3\" >1</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row1_col4\" class=\"data row1 col4\" >0.497935</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row2_col0\" class=\"data row2 col0\" >0.133188</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row2_col1\" class=\"data row2 col1\" >0.866811</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row2_col2\" class=\"data row2 col2\" >0</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row2_col3\" class=\"data row2 col3\" >2</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row2_col4\" class=\"data row2 col4\" >0.133188</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row3_col0\" class=\"data row3 col0\" >0.99664</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row3_col1\" class=\"data row3 col1\" >0.00336017</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row3_col2\" class=\"data row3 col2\" >1</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row3_col3\" class=\"data row3 col3\" >3</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row3_col4\" class=\"data row3 col4\" >0.00336017</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row4_col0\" class=\"data row4 col0\" >0.595949</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row4_col1\" class=\"data row4 col1\" >0.404051</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row4_col2\" class=\"data row4 col2\" >1</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row4_col3\" class=\"data row4 col3\" >4</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row4_col4\" class=\"data row4 col4\" >0.404051</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" <tr>\n",
2020-04-28 17:12:59 +00:00
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row5_col0\" class=\"data row5 col0\" >0.366118</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row5_col1\" class=\"data row5 col1\" >0.633882</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row5_col2\" class=\"data row5 col2\" >0</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row5_col3\" class=\"data row5 col3\" >5</td>\n",
" <td id=\"T_6b1e5e2c_8421_11ea_8806_bdb274b1aa15row5_col4\" class=\"data row5 col4\" >0.366118</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" </tbody></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from IPython.display import HTML\n",
"df = pd.DataFrame(sm_acts, columns=[\"3\",\"7\"])\n",
"df['targ'] = targ\n",
"df['idx'] = idx\n",
"df['loss'] = sm_acts[range(6), targ]\n",
"t = df.style.hide_index()\n",
"#To have html code compatible with our script\n",
"html = t._repr_html_().split('</style>')[1]\n",
"html = re.sub(r'<table id=\"([^\"]+)\"\\s*>', r'<table >', html)\n",
"display(HTML(html))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([-0.6025, -0.4979, -0.1332, -0.0034, -0.4041, -0.3661])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"-sm_acts[idx, targ]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([-0.6025, -0.4979, -0.1332, -0.0034, -0.4041, -0.3661])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"F.nll_loss(sm_acts, targ, reduction='none')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Taking the Log"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAD7CAYAAACVMATUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAegElEQVR4nO3de3ycVYH/8c/JrWnuzb1Jm6Rpmt5paUNb7iCgwHJTdAFBwRVRLu7PxXVdV1kr6Etx1133ta8FZBdWVy5eAREFlFuhIpRS2tJLkrZJ2zTNPU0yuScz5/fHDKXUtEmbZ+aZPPN9v17zMp0cZ749Gb59cp4zzxhrLSIi4g1xbgcQERHnqNRFRDxEpS4i4iEqdRERD1Gpi4h4SILbAXJzc21ZWZnbMUREppS333673Vqbd/T9rpd6WVkZGzdudDuGiMiUYozZN9b9Wn4REfEQlbqIiIeo1EVEPESlLiLiISp1EREPUamLiHiISl1ExENc36cuIhILAgFLq2+IvR197OvoY29HP7edN5f05ERHn0elLiLikEDA0uIbpL69j30d/ext7zv89b7OPgZHAofHJsYbrlxexIJClbqIiGustXT2DVPf3kdde9/h4n6vvAdG/IfHJsXHUZKTQllOKmfPy6U0N5U5OamU5qRQlDWd+DjjeD6VuojIGPqHR4PF3fZ+ade191Hf1kvP4OjhcQlxhpLsFMpyUzmzIpeyUHGX5aYwMzM8xX08KnURiVmBgKWpZ5C6tl72tPZS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BDwYaAd+Jq19jEnn0NOzuC
2020-03-06 18:19:03 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_function(torch.log, min=0,max=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"loss_func = nn.CrossEntropyLoss()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor(1.8045)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"loss_func(acts, targ)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor(1.8045)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"F.cross_entropy(acts, targ)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.5067, 0.6973, 2.0160, 5.6958, 0.9062, 1.0048])"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nn.CrossEntropyLoss(reduction='none')(acts, targ)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Interpretation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsQAAALTCAYAAAARhhSgAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAJOgAACToB8GSSSgAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nOydeXhV1dm37x+EKAoiOCEJlgQEJMggCGKB4lBHsE4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jZB5LaAycBPQKnHbDdzJ6UVACMDdYmH2Jm/5L0PvDvGGNsBZQuthkb4z3244hDU7n1nM40lZBg7vqtLPx4R43vM+7K0WRnv8O2rVvp0vE4br3tDsaMmxCVm5KSwtT7pzHs/LMpKSlhzNjxdMvKql6Mk1ubPiH2d5Vs78ldd91NznjddTcRXUVab+HUPZLmAZPMbHZY2Y3AdcBnwFfAicC7hGaD9wVtfgH0MrNRwfXZwL3APqAo8PMJzSQfDAi4z8wekzQRKDCz+4L+bzazJZKOBJaYWQdJQ4LyoZIGAI8FsbwNXBm0GUtodvmGIIZZQR/zKnveo3qdbrFmqvuXZ6qLGs9U5ziO4zg1o3kzPWtmI8LLfECc4ASDz6lm9la8Y6kJPiCuH3xA7DiO4zg1I9KA2P+LmKBIOlzSemBPsg2GHcdxHMdxkglfQ5ygmNnXQOd4x+E4juM4jtPQ8QGxc0AY1OkIHo9x6cN5Dy6Iud85Nw6M2Y0X23btjdk9ouVBdRiJ4ziO4zROfMmE4ziO4ziO06jxAbHjOI7jOI7TqPEBsVNvXHf1BDLat6XfST2iap/aVDw8uie
2020-03-06 18:19:03 +00:00
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"interp = ClassificationInterpretation.from_learner(learn)\n",
"interp.plot_confusion_matrix(figsize=(12,12), dpi=60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('american_pit_bull_terrier', 'staffordshire_bull_terrier', 10),\n",
2020-04-28 17:12:59 +00:00
" ('Ragdoll', 'Birman', 8),\n",
" ('Siamese', 'Birman', 6),\n",
" ('Bengal', 'Egyptian_Mau', 5),\n",
" ('american_pit_bull_terrier', 'american_bulldog', 5)]"
2020-03-06 18:19:03 +00:00
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"interp.most_confused(min_val=5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"## Improving Our Model"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### The Learning Rate Finder"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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",
2020-04-28 17:12:59 +00:00
" <td>2.778816</td>\n",
" <td>5.150732</td>\n",
" <td>0.504060</td>\n",
2020-03-06 18:19:03 +00:00
" <td>00:20</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"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",
2020-04-28 17:12:59 +00:00
" <td>4.354680</td>\n",
" <td>3.003533</td>\n",
" <td>0.834235</td>\n",
2020-03-06 18:19:03 +00:00
" <td>00:24</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fine_tune(1, base_lr=0.1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2020-04-28 17:12:59 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEQCAYAAACeDyIUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3gc1dn+8e+jblnNsuWu4t4LxhVscOg1wAuhtwRCCL83pNBSCSQkhBAgIS9JICF0EmoooTcbAwYsA8a4d9lyUy9W3z2/P3YFwshWsbSzu7o/17WXd2dnZu8Vyz575sw5Y845REREOirG6wAiIhKZVEBERKRTVEBERKRTVEBERKRTVEBERKRTVEBERKRT4rwO0FX69evn8vLyvI4hIhJRli5dWuycy+rMtlFTQPLy8sjPz/c6hohIRDGzLZ3dVoewRESkU1RARESkU1RARESkU1RARESkU1RARESkU0JWQMxsgZnVmVl18LZmH+vdYGaNLdarNrPhocopIiLtE+oWyP8651KCtzH7We+xFuulOOc2hiqgz+/w+TXFvYhIW3QIK8jvdzyev5UZv3mdnz+z3Os4IiJhL9QF5GYzKzazd81s/n7WO9nMSs1shZl9d18rmdllZpZvZvlFRUWdDrVyeyXfuHsx1z75KXWNPv67bAcNTf5O7086psnnp6qukaKqeraW1rB+dxWfFVZQUl3vdTQR2Y9QjkS/DlgJNABnA8+b2VTn3Ia91nscuAfYBcwCnjKzcufcv/beoXPunuC6TJ8+vVPHnR54bzM3Pr+CjOQEbj1jMn2SE7j0wXze31jCYaM7Nbpf9sHvd6zaWcl760t4d0Mxn2wtp7quiab9HDLsn5rIuEFpTBmazlkzcxiS0SuEiUVkf0JWQJxzH7R4+ICZnQOcAPx5r/VWtnj4npn9CTgD+EoB6QrTcvpwzswcrjl2DBnJCdQ1+ugVH8urK3f22AJSUl3PxuI95GQm0z81ETPr8D6Kquq5+aV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z4qRB3HjKBPqlJHodTUQFBLq3gEBg3MRvX1zF22uLyOvXm5FZKYzon8JR4waQlfrFF8HlDy1l0boiFlzztS8tX7WjkuFZvUmM+2KcxYI1u7n4viVcc+wYzp+Vy2UP5fPBplK+degwFm8sYdWOSiYMTuMnx+tsqWhQ09DE39/exF1vrSclKY7fnjaR4yYO8jqW9HAqIHR/AWmvjUXVHHPH25w9M5ubTp1EcXU9v3x2BS8s38GUoen85fyDGZLRi7pGH8fc8TZxscZL359HYlws9U0+rnp8Gf/9dAdD+/TimmN1tlQ0WruriqseX8bywgpOmTqYa48bG9HjcCSyqYAQPgUE4PpnP+ORDwr48XFj+evCDVTXNXHWjGye+biQuFjjz+dMY8nmUv70xjoeuXQWh478onXh9zvyt5R9PjGhRKdGn5+/vLWBP7+5jia/4+DcPpw8eRAnTB5E/1QNRpTQUQEhvApIcXU9829dQHV9E1OyM7j1jMmMHpDKxqJqLn94Ket2VxMXYxw/cRB3nnOQ13HFQ1tLa3hu2XaeX7ad1TurSIiL4ebTJnH6wUO9jiY9hAoI4VVAAF5fuYsdFbWcMzPnS2dB1TQ08dOnl/PehhL++7259NfUFxK0blcVv3xuBe9tKOGSucP4yfFjdQaddDsVEMKvgLTF73fq25CvaPL5+c2Lq7jv3c3MHdmP/zv3IDKS9z+IVeRAHEgB0c8bj6h4SGviYmP45ckT+P0Zk/lwUyln3/M+VXWNXscSaZUKiEgYOnN6Nv+4aDrrd1dzxSMf0ejzex1J5CtUQETC1GGjs/jt/0xi0bpifvr0cqLlcLNED02mKBLGzpyezbbSGu58cz3ZmcntnuFAJBR
2020-03-06 18:19:03 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"lr_min,lr_steep = learn.lr_find()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2020-04-28 17:12:59 +00:00
"Minimum/10: 1.00e-02, steepest point: 5.25e-03\n"
2020-03-06 18:19:03 +00:00
]
}
],
"source": [
"print(f\"Minimum/10: {lr_min:.2e}, steepest point: {lr_steep:.2e}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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",
2020-04-28 17:12:59 +00:00
" <td>1.328591</td>\n",
" <td>0.344678</td>\n",
" <td>0.114344</td>\n",
" <td>00:20</td>\n",
2020-03-06 18:19:03 +00:00
" </tr>\n",
" </tbody>\n",
"</table>"
],
"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",
2020-04-28 17:12:59 +00:00
" <td>0.540180</td>\n",
" <td>0.420945</td>\n",
" <td>0.127876</td>\n",
2020-03-06 18:19:03 +00:00
" <td>00:24</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
2020-04-28 17:12:59 +00:00
" <td>0.329827</td>\n",
" <td>0.248813</td>\n",
" <td>0.083221</td>\n",
2020-03-06 18:19:03 +00:00
" <td>00:24</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fine_tune(2, base_lr=3e-3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Unfreezing and Transfer Learning"
2020-03-06 18:19:03 +00:00
]
},
2020-04-28 17:12:59 +00:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"learn.fine_tune??"
]
},
2020-03-06 18:19:03 +00:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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.188042</td>\n",
" <td>0.355024</td>\n",
" <td>0.102842</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.534234</td>\n",
" <td>0.302453</td>\n",
" <td>0.094723</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.325031</td>\n",
" <td>0.222268</td>\n",
" <td>0.074425</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fit_one_cycle(3, 3e-3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"learn.unfreeze()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(1.0964782268274575e-05, 1.5848931980144698e-06)"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXxcdb3/8dcnaZIuSdeke9KmNF2ha0AQyr4U0RbFpXhVuKKIgOiD31XBDQW5Kl69chEvVMXlKlZAvRbsZVHZodCkC9CNtmmzdE2bpEmzL5/fHzNthzBtk3ZOZiZ9Px+PeTRnm/PJeUzm3XO+3/M95u6IiIh0lhLvAkREJDEpIEREJCoFhIiIRKWAEBGRqBQQIiISlQJCRESi6hPvAmIlOzvbx48fH+8yRESSSnFx8V53z4m2rNcExPjx4ykqKop3GSIiScXMSo+0TJeYREQkKgWEiIhEpYAQEZGoFBAiIhKVAkJERKJSQIiISFQKCBGRJLZiWxXFpdWBvLcCQkQkif3nM29z1xPrAnlvBYSISBIrqaxnQs6AQN5bASEikqTqm9vYVdvEhGwFhIiIRNi6tx6ACTmZgby/AkJEJEltqTwAkJyXmMxsvpltNLPNZnbbEdb5qJmtM7O1ZvZwxPxrzGxT+HVNkHWKiCSjksp6zGD8sGACIrDRXM0sFbgfuASoAFaY2VJ3XxexTgFwO3C2u1eb2fDw/KHAHUAh4EBxeNtg+nKJiCShkr31jBncj75pqYG8f5BnEGcAm929xN1bgCXAwk7rfBa4/+AXv7vvCc+/DHjG3avCy54B5gdYq4hI0tm690Bg7Q8QbECMAcojpivC8yJNAiaZ2ctmttzM5ndjWxGRk5a7s7WyPrAeTBDsA4MsyjyPsv8C4HxgLPCimZ3axW0xs+uB6wHy8vJOpFYRkaSyu7aZ+pZ2TgmogRqCPYOoAHIjpscCO6Ks81d3b3X3rcBGQoHRlW1x98Xu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+xDwUJD1iYgkEndnZVkNF00ZHu9SAN1JLSKSMLbta6CqviUh2h9AASEikjCKS0PtD3MUECIiEqm4tJqsvn2YmJMZ71IABYSISMJYWVrNnLwhpKREuxWs5ykgREQSQG1TK2/vqUuY9gdQQIiIJITVZTW4o4AQEZF3Ki6tJsWI+xDfkRQQIiIJYGVZNZNHDiQzjk+Q60wBISISZ+0dzuqyGuaOS5yzB1BAiIjE3aY9ddQ1tyVU+wMoIERE4u7QDXJ5CggREYlQXFpNdmY6eUP7x7uUd1BAiIjE2aqyGubkDcEsMW6QO0gBISISR/sONLN1b33CtT+AAkJEJK5WltUAiTNAXyQFhIhIHBWXVpOWapw2ZlC8S3kXBYSISBytLK1m2uhB9E1LjXcp7xJoQJjZfDPbaGabzey2o6z3YTNzMysMT483s0YzWx1+PRBknSIi8dDc1s6aihpOT8DLSxDgI0fNLBW4H7gEqABWmNlSd1/Xab0s4BbgtU5vscXdZwVVn4hIvL21vZbmtg4Kxw+NdylRBXkGcQaw2d1L3L0FWAIsjLLeXcA9QFOAtYiIJJyibVUAFI5PzDOIIANiDFAeMV0RnneImc0Gct39iSjb55vZKjN73szmBViniEhcrNhWTX72ALIzM+JdSlRBDhsY7Y4PP7TQLAX4T+DaKOvtBPLcfZ+ZzQX+18ymu3vtO3Zgdj1wPUBeXl6s6hYRCZy7U1xaxcVTR8S7lCMK8gyiAsiNmB4L7IiYzgJOBZ4zs23AmcBSMyt092Z33wfg7sXAFmBS5x24+2J3L3T3wpycnIB+DRGR2NtSWU91QyunJ2j7A3QxIMzsFDPLCP98vpndYmbHGpd2BVBgZvlmlg4sApYeXOju+909293Hu/t4YDmwwN2LzCw
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"learn.lr_find()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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.263579</td>\n",
" <td>0.217419</td>\n",
" <td>0.069012</td>\n",
" <td>00:24</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.253060</td>\n",
" <td>0.210346</td>\n",
" <td>0.062923</td>\n",
" <td>00:24</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.224340</td>\n",
" <td>0.207357</td>\n",
" <td>0.060217</td>\n",
" <td>00:24</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>0.200195</td>\n",
" <td>0.207244</td>\n",
" <td>0.061570</td>\n",
" <td>00:24</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>0.194269</td>\n",
" <td>0.200149</td>\n",
" <td>0.059540</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>0.173164</td>\n",
" <td>0.202301</td>\n",
" <td>0.059540</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn.fit_one_cycle(6, lr_max=1e-5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Discriminative Learning Rates"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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.145300</td>\n",
" <td>0.345568</td>\n",
" <td>0.119756</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.533986</td>\n",
" <td>0.251944</td>\n",
" <td>0.077131</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.317696</td>\n",
" <td>0.208371</td>\n",
" <td>0.069012</td>\n",
" <td>00:20</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"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.257977</td>\n",
" <td>0.205400</td>\n",
" <td>0.067659</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.246763</td>\n",
" <td>0.205107</td>\n",
" <td>0.066306</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.240595</td>\n",
" <td>0.193848</td>\n",
" <td>0.062246</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>0.209988</td>\n",
" <td>0.198061</td>\n",
" <td>0.062923</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>0.194756</td>\n",
" <td>0.193130</td>\n",
" <td>0.064276</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>0.169985</td>\n",
" <td>0.187885</td>\n",
" <td>0.056157</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6</td>\n",
" <td>0.153205</td>\n",
" <td>0.186145</td>\n",
" <td>0.058863</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7</td>\n",
" <td>0.141480</td>\n",
" <td>0.185316</td>\n",
" <td>0.053451</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8</td>\n",
" <td>0.128564</td>\n",
" <td>0.180999</td>\n",
" <td>0.051421</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9</td>\n",
" <td>0.126941</td>\n",
" <td>0.186288</td>\n",
" <td>0.054127</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10</td>\n",
" <td>0.130064</td>\n",
" <td>0.181764</td>\n",
" <td>0.054127</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11</td>\n",
" <td>0.124281</td>\n",
" <td>0.181855</td>\n",
" <td>0.054127</td>\n",
" <td>00:25</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = cnn_learner(dls, resnet34, metrics=error_rate)\n",
"learn.fit_one_cycle(3, 3e-3)\n",
"learn.unfreeze()\n",
"learn.fit_one_cycle(12, lr_max=slice(1e-6,1e-4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYAAAAD4CAYAAADlwTGnAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3xV5f3A8c83e0NIAgmEPWVERlgOhlILWpVW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qdNn4SAOq/TWdPn3MGxAMQFWo1i5SU131Qn6xX/7fXtV1ZVbchomu01W83M/8Ejy/a0Wyfq5RSDfGLRmDPAFBV7SAoMID84nKqjWFQtyiCAgIY3y8OgJCgAEKDAihqxgAQGeL+zzxtaNc6+7t5DEDbfqjudBFKKdUS/KME4DGgq6zKwZHicsY8vIRxjywlt6iciJCa/e+jQoMoKvM9APz+w828vy673v0OA907hfHxrefws3P71dkfEhTAQzOttT93HS7WdYmVUqeFfwSAAHcbQFllNTOf+5/r/b78E4TVCgD5JRXMW7Pfp6HjG7MKmLdmP//37kZ2Hfbey6ii2kFIUAAjkjvV283zugm9efaqUVRUO/jpa2u5/MX6G6yVUqo5+EcA8KgCKq2oJrvWpGyeXTM9FftQDbRqT75r+3tPfeV1eumKKt+mlUjsZFUFfZNxhLWZx1pkMJpSSjn5RwDwePg6u3t6qh0A7vz+YAA+2XSwzrG11X5Ie6s6qqw2PgWAhKjQGu8PFJxo9ByllDpZfhEAPCtdyr3Ur4f
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"learn.recorder.plot_loss()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Selecting the Number of Epochs"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Deeper Architectures"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"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.427505</td>\n",
" <td>0.310554</td>\n",
" <td>0.098782</td>\n",
" <td>00:21</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.606785</td>\n",
" <td>0.302325</td>\n",
" <td>0.094723</td>\n",
" <td>00:22</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.409267</td>\n",
" <td>0.294803</td>\n",
" <td>0.091340</td>\n",
" <td>00:21</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"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.261121</td>\n",
" <td>0.274507</td>\n",
" <td>0.083897</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.296653</td>\n",
" <td>0.318649</td>\n",
" <td>0.084574</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.242356</td>\n",
" <td>0.253677</td>\n",
" <td>0.069012</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3</td>\n",
" <td>0.150684</td>\n",
" <td>0.251438</td>\n",
" <td>0.065629</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4</td>\n",
" <td>0.094997</td>\n",
" <td>0.239772</td>\n",
" <td>0.064276</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5</td>\n",
" <td>0.061144</td>\n",
" <td>0.228082</td>\n",
" <td>0.054804</td>\n",
" <td>00:26</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2020-08-21 19:36:27 +00:00
"from fastai.callback.fp16 import *\n",
2020-03-06 18:19:03 +00:00
"learn = cnn_learner(dls, resnet50, metrics=error_rate).to_fp16()\n",
"learn.fine_tune(6, freeze_epochs=3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"## Conclusion"
2020-03-06 18:19:03 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Questionnaire"
]
},
2020-03-18 00:34:07 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Why do we first resize to a large size on the CPU, and then to a smaller size on the GPU?\n",
2020-05-14 12:18:31 +00:00
"1. If you are not familiar with regular expressions, find a regular expression tutorial, and some problem sets, and complete them. Have a look on the book's website for suggestions.\n",
2020-03-18 00:34:07 +00:00
"1. What are the two ways in which data is most commonly provided, for most deep learning datasets?\n",
"1. Look up the documentation for `L` and try using a few of the new methods is that it adds.\n",
2020-05-14 12:18:31 +00:00
"1. Look up the documentation for the Python `pathlib` module and try using a few methods of the `Path` class.\n",
2020-03-18 00:34:07 +00:00
"1. Give two examples of ways that image transformations can degrade the quality of the data.\n",
2020-05-14 12:18:31 +00:00
"1. What method does fastai provide to view the data in a `DataLoaders`?\n",
"1. What method does fastai provide to help you debug a `DataBlock`?\n",
2020-03-18 00:34:07 +00:00
"1. Should you hold off on training a model until you have thoroughly cleaned your data?\n",
2020-05-14 12:18:31 +00:00
"1. What are the two pieces that are combined into cross-entropy loss in PyTorch?\n",
2020-03-18 00:34:07 +00:00
"1. What are the two properties of activations that softmax ensures? Why is this important?\n",
"1. When might you want your activations to not have these two properties?\n",
2020-05-14 12:18:31 +00:00
"1. Calculate the `exp` and `softmax` columns of <<bear_softmax>> yourself (i.e., in a spreadsheet, with a calculator, or in a notebook).\n",
"1. Why can't we use `torch.where` to create a loss function for datasets where our label can have more than two categories?\n",
2020-03-18 00:34:07 +00:00
"1. What is the value of log(-2)? Why?\n",
"1. What are two good rules of thumb for picking a learning rate from the learning rate finder?\n",
2020-05-14 12:18:31 +00:00
"1. What two steps does the `fine_tune` method do?\n",
"1. In Jupyter Notebook, how do you get the source code for a method or function?\n",
2020-03-18 00:34:07 +00:00
"1. What are discriminative learning rates?\n",
2020-05-14 12:18:31 +00:00
"1. How is a Python `slice` object interpreted when passed as a learning rate to fastai?\n",
"1. Why is early stopping a poor choice when using 1cycle training?\n",
"1. What is the difference between `resnet50` and `resnet101`?\n",
"1. What does `to_fp16` do?"
2020-03-18 00:34:07 +00:00
]
},
2020-03-06 18:19:03 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2020-05-14 12:18:31 +00:00
"### Further Research"
2020-03-06 18:19:03 +00:00
]
},
2020-03-18 00:34:07 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1. Find the paper by Leslie Smith that introduced the learning rate finder, and read it.\n",
2020-05-14 12:18:31 +00:00
"1. See if you can improve the accuracy of the classifier in this chapter. What's the best accuracy you can achieve? Look on the forums and the book's website to see what other students have achieved with this dataset, and how they did it."
2020-03-18 00:34:07 +00:00
]
},
2020-03-06 18:19:03 +00:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
2020-03-19 13:21:55 +00:00
"jupytext": {
"split_at_heading": true
},
2020-03-06 18:19:03 +00:00
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
2020-09-03 22:51:00 +00:00
},
"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.7.7"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
2020-03-06 18:19:03 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}