mirror of
https://github.com/mrdbourke/pytorch-deep-learning.git
synced 2026-11-27 06:07:09 +00:00
add comparison graph code
This commit is contained in:
1 parent
f6f7cb264e
commit
26b0040b14
1 file changed
+267
-133
+267
-133
@@ -75,7 +75,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 78,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -123,7 +123,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 79,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -167,7 +167,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 80,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -176,7 +176,7 @@
|
||||
"'cuda'"
|
||||
]
|
||||
},
|
||||
"execution_count": 80,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -207,7 +207,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 81,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -223,7 +223,7 @@
|
||||
"PosixPath('data/pizza_steak_sushi_20_percent')"
|
||||
]
|
||||
},
|
||||
"execution_count": 81,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -247,7 +247,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 82,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -312,7 +312,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 83,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -339,7 +339,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 84,
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -351,7 +351,7 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
"execution_count": 84,
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -372,7 +372,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 85,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -398,7 +398,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 86,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -443,7 +443,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 87,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -460,7 +460,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -526,7 +526,7 @@
|
||||
"============================================================================================================================================"
|
||||
]
|
||||
},
|
||||
"execution_count": 88,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -564,7 +564,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 89,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -591,13 +591,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 90,
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "d2cdf62a8776406ba6692154714840fc",
|
||||
"model_id": "3d8c4556b6e3436ebd78c35e465eac52",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@@ -662,7 +662,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 91,
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -712,7 +712,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 92,
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -753,7 +753,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 93,
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -787,7 +787,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 94,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -796,7 +796,7 @@
|
||||
"7705221"
|
||||
]
|
||||
},
|
||||
"execution_count": 94,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -818,7 +818,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 95,
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -830,7 +830,7 @@
|
||||
" 'model_size (MB)': 29}"
|
||||
]
|
||||
},
|
||||
"execution_count": 95,
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -870,7 +870,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 96,
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -881,7 +881,7 @@
|
||||
")"
|
||||
]
|
||||
},
|
||||
"execution_count": 96,
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -901,7 +901,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 97,
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -945,7 +945,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 98,
|
||||
"execution_count": 25,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -965,7 +965,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 99,
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1007,7 +1007,7 @@
|
||||
"======================================================================================================================================================"
|
||||
]
|
||||
},
|
||||
"execution_count": 99,
|
||||
"execution_count": 26,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1047,7 +1047,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 100,
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -1076,13 +1076,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 101,
|
||||
"execution_count": 28,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "5a7951e3d3d44deeb8bd22d60e115dcd",
|
||||
"model_id": "fba79fad2f63484883d79630f6ce3929",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@@ -1143,7 +1143,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 102,
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1189,7 +1189,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1222,7 +1222,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"execution_count": 31,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1263,7 +1263,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1272,7 +1272,7 @@
|
||||
"85800963"
|
||||
]
|
||||
},
|
||||
"execution_count": 29,
|
||||
"execution_count": 32,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1296,7 +1296,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 105,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1308,7 +1308,7 @@
|
||||
" 'model_size (MB)': 327}"
|
||||
]
|
||||
},
|
||||
"execution_count": 105,
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1361,7 +1361,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 118,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1381,7 +1381,7 @@
|
||||
" PosixPath('data/pizza_steak_sushi_20_percent/test/steak/730464.jpg')]"
|
||||
]
|
||||
},
|
||||
"execution_count": 118,
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1426,10 +1426,11 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 139,
|
||||
"execution_count": 36,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pathlib\n",
|
||||
"import torch\n",
|
||||
"\n",
|
||||
"from PIL import Image\n",
|
||||
@@ -1524,13 +1525,13 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 140,
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "0c33cef111174da589c212fe6dbf1e90",
|
||||
"model_id": "aa20558dda2744519b6c2b0bb41fe10f",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@@ -1562,7 +1563,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 141,
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1572,17 +1573,17 @@
|
||||
" 'class_name': 'steak',\n",
|
||||
" 'pred_prob': 0.9293,\n",
|
||||
" 'pred_class': 'steak',\n",
|
||||
" 'time_for_pred': 0.0387,\n",
|
||||
" 'time_for_pred': 0.0707,\n",
|
||||
" 'correct': True},\n",
|
||||
" {'image_path': PosixPath('data/pizza_steak_sushi_20_percent/test/steak/3100563.jpg'),\n",
|
||||
" 'class_name': 'steak',\n",
|
||||
" 'pred_prob': 0.9534,\n",
|
||||
" 'pred_class': 'steak',\n",
|
||||
" 'time_for_pred': 0.0387,\n",
|
||||
" 'time_for_pred': 0.0366,\n",
|
||||
" 'correct': True}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 141,
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1607,7 +1608,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 142,
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1646,7 +1647,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9293</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0387</td>\n",
|
||||
" <td>0.0707</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1655,7 +1656,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9534</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0387</td>\n",
|
||||
" <td>0.0366</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1664,7 +1665,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.7531</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0309</td>\n",
|
||||
" <td>0.0353</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1673,7 +1674,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.5935</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0313</td>\n",
|
||||
" <td>0.0326</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1682,7 +1683,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.8959</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0318</td>\n",
|
||||
" <td>0.0299</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
@@ -1698,14 +1699,14 @@
|
||||
"4 data/pizza_steak_sushi_20_percent/test/steak/7... steak 0.8959 \n",
|
||||
"\n",
|
||||
" pred_class time_for_pred correct \n",
|
||||
"0 steak 0.0387 True \n",
|
||||
"1 steak 0.0387 True \n",
|
||||
"2 steak 0.0309 True \n",
|
||||
"3 steak 0.0313 True \n",
|
||||
"4 steak 0.0318 True "
|
||||
"0 steak 0.0707 True \n",
|
||||
"1 steak 0.0366 True \n",
|
||||
"2 steak 0.0353 True \n",
|
||||
"3 steak 0.0326 True \n",
|
||||
"4 steak 0.0299 True "
|
||||
]
|
||||
},
|
||||
"execution_count": 142,
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1730,7 +1731,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 143,
|
||||
"execution_count": 40,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1741,7 +1742,7 @@
|
||||
"Name: correct, dtype: int64"
|
||||
]
|
||||
},
|
||||
"execution_count": 143,
|
||||
"execution_count": 40,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1762,14 +1763,14 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 148,
|
||||
"execution_count": 41,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"EffNetB2 average time per prediction: 0.0316 seconds\n"
|
||||
"EffNetB2 average time per prediction: 0.0302 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -1792,7 +1793,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 149,
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1802,10 +1803,10 @@
|
||||
" 'test_acc': 0.96875,\n",
|
||||
" 'number_of_parameters': 7705221,\n",
|
||||
" 'model_size (MB)': 29,\n",
|
||||
" 'time_per_pred_cpu': 0.0316}"
|
||||
" 'time_per_pred_cpu': 0.0302}"
|
||||
]
|
||||
},
|
||||
"execution_count": 149,
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
@@ -1822,18 +1823,22 @@
|
||||
"source": [
|
||||
"### TK - Making and timing predictions with ViT \n",
|
||||
"\n",
|
||||
"UPTOHERE: make predictions with ViT and inspect them in the same way as EffNetB2 "
|
||||
"We've made predictions with our EffNetB2 model, now let's do the same for our ViT model.\n",
|
||||
"\n",
|
||||
"To do so, we can use the `pred_and_store()` function we created above except this time we'll pass in our `vit` model as well as the `vit_transforms`.\n",
|
||||
"\n",
|
||||
"And we'll keep the predictions on the CPU via `device=\"cpu\"` (a natural extension here would be to test the prediction times on CPU and on GPU)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 154,
|
||||
"execution_count": 43,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "a3038b093cf44b43a711de9bce92461b",
|
||||
"model_id": "1b49d08f82a74a65ba3572d10e0ca265",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
@@ -1846,6 +1851,7 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Make list of prediction dictionaries with ViT feature extractor model on test images\n",
|
||||
"vit_test_pred_dicts = pred_and_store(paths=test_data_paths,\n",
|
||||
" model=vit,\n",
|
||||
" transform=vit_transforms,\n",
|
||||
@@ -1853,9 +1859,18 @@
|
||||
" device=\"cpu\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Predictions made!\n",
|
||||
"\n",
|
||||
"Now let's check out the first couple."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 155,
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1865,37 +1880,38 @@
|
||||
" 'class_name': 'steak',\n",
|
||||
" 'pred_prob': 0.9933,\n",
|
||||
" 'pred_class': 'steak',\n",
|
||||
" 'time_for_pred': 0.0663,\n",
|
||||
" 'time_for_pred': 0.1348,\n",
|
||||
" 'correct': True},\n",
|
||||
" {'image_path': PosixPath('data/pizza_steak_sushi_20_percent/test/steak/3100563.jpg'),\n",
|
||||
" 'class_name': 'steak',\n",
|
||||
" 'pred_prob': 0.9893,\n",
|
||||
" 'pred_class': 'steak',\n",
|
||||
" 'time_for_pred': 0.0662,\n",
|
||||
" 'time_for_pred': 0.0684,\n",
|
||||
" 'correct': True}]"
|
||||
]
|
||||
},
|
||||
"execution_count": 155,
|
||||
"execution_count": 44,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Check the first couple of ViT predictions on the test dataset\n",
|
||||
"vit_test_pred_dicts[:2]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 151,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# TK - turn pred dict into pred df (show why list of dictionaries is a good structure for evaluation)"
|
||||
"Wonderful!\n",
|
||||
"\n",
|
||||
"And just like before, since our ViT model's predictions are in the form of a list of dictionaries, we can easily turn them into a pandas DataFrame for further inspection. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 153,
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1934,7 +1950,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9933</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.1021</td>\n",
|
||||
" <td>0.1348</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1943,7 +1959,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9893</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.1015</td>\n",
|
||||
" <td>0.0684</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1952,7 +1968,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9971</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0971</td>\n",
|
||||
" <td>0.0636</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1961,7 +1977,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.7685</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0984</td>\n",
|
||||
" <td>0.0644</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
@@ -1970,7 +1986,7 @@
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.9499</td>\n",
|
||||
" <td>steak</td>\n",
|
||||
" <td>0.0986</td>\n",
|
||||
" <td>0.0649</td>\n",
|
||||
" <td>True</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
@@ -1986,38 +2002,101 @@
|
||||
"4 data/pizza_steak_sushi_20_percent/test/steak/7... steak 0.9499 \n",
|
||||
"\n",
|
||||
" pred_class time_for_pred correct \n",
|
||||
"0 steak 0.1021 True \n",
|
||||
"1 steak 0.1015 True \n",
|
||||
"2 steak 0.0971 True \n",
|
||||
"3 steak 0.0984 True \n",
|
||||
"4 steak 0.0986 True "
|
||||
"0 steak 0.1348 True \n",
|
||||
"1 steak 0.0684 True \n",
|
||||
"2 steak 0.0636 True \n",
|
||||
"3 steak 0.0644 True \n",
|
||||
"4 steak 0.0649 True "
|
||||
]
|
||||
},
|
||||
"execution_count": 153,
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Turn the test_pred_dicts into a DataFrame\n",
|
||||
"# Turn vit_test_pred_dicts into a DataFrame\n",
|
||||
"import pandas as pd\n",
|
||||
"vit_test_pred_df = pd.DataFrame(vit_test_pred_dicts)\n",
|
||||
"vit_test_pred_df.head()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vit_average_time_per_pred = round(vit_test_pred_df.time_for_pred.mean(), 4)\n",
|
||||
"vit_average_time_per_pred"
|
||||
"How many predictions did our ViT model get correct?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 130,
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True 148\n",
|
||||
"False 2\n",
|
||||
"Name: correct, dtype: int64"
|
||||
]
|
||||
},
|
||||
"execution_count": 46,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Count the number of correct predictions\n",
|
||||
"vit_test_pred_df.correct.value_counts()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Woah!\n",
|
||||
"\n",
|
||||
"Our ViT model did a little better than our EffNetB2 model in terms of correct predictions, only two samples wrong across the whole test dataset.\n",
|
||||
"\n",
|
||||
"As an extension you might want to visualize the ViT model's wrong predictions and see if there's any reason why it might've got them wrong.\n",
|
||||
"\n",
|
||||
"How about we calculate how long the ViT model took per prediction?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 49,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ViT average time per prediction: 0.0777 seconds\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Calculate average time per prediction for ViT model\n",
|
||||
"vit_average_time_per_pred = round(vit_test_pred_df.time_for_pred.mean(), 4)\n",
|
||||
"print(f\"ViT average time per prediction: {vit_average_time_per_pred} seconds\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Well, that looks a little slower than our EffNetB2 model's average time per prediction but how does it look in terms of our second criteria: speed?\n",
|
||||
"\n",
|
||||
"For now, let's add the value to our `vit_stats` dictionary so we can compare it to our EffNetB2 model's stats.\n",
|
||||
"\n",
|
||||
"> **Note:** The average time per prediction values will be highly dependent on the hardware you make them on. For example, for the ViT model, my average time per prediction (on the CPU) was 0.0693-0.0777 seconds on my local deep learning PC with an Intel i9 CPU. Where as on Google Colab, my average time per prediction with the ViT model was 0.6766-0.7113 seconds."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 51,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -2027,15 +2106,16 @@
|
||||
" 'test_acc': 0.984659090909091,\n",
|
||||
" 'number_of_parameters': 85800963,\n",
|
||||
" 'model_size (MB)': 327,\n",
|
||||
" 'time_per_pred_cpu': 0.0656}"
|
||||
" 'time_per_pred_cpu': 0.0777}"
|
||||
]
|
||||
},
|
||||
"execution_count": 130,
|
||||
"execution_count": 51,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Add average prediction time for ViT model on CPU\n",
|
||||
"vit_stats[\"time_per_pred_cpu\"] = vit_average_time_per_pred\n",
|
||||
"vit_stats"
|
||||
]
|
||||
@@ -2044,12 +2124,14 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## TK - Comparing model results, prediction times and size"
|
||||
"## TK - Comparing model results, prediction times and size\n",
|
||||
"\n",
|
||||
"UPTOHERE: comparing ViT stats to EffNetB2 stats"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"execution_count": 212,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -2078,58 +2160,51 @@
|
||||
" <th>number_of_parameters</th>\n",
|
||||
" <th>model_size (MB)</th>\n",
|
||||
" <th>time_per_pred_cpu</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>model</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>effnetb2</th>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>0.281287</td>\n",
|
||||
" <td>0.968750</td>\n",
|
||||
" <td>96.88</td>\n",
|
||||
" <td>7705221</td>\n",
|
||||
" <td>29</td>\n",
|
||||
" <td>0.030839</td>\n",
|
||||
" <td>0.0302</td>\n",
|
||||
" <td>EffNetB2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>vit</th>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>0.064182</td>\n",
|
||||
" <td>0.984659</td>\n",
|
||||
" <td>98.47</td>\n",
|
||||
" <td>85800963</td>\n",
|
||||
" <td>327</td>\n",
|
||||
" <td>0.065751</td>\n",
|
||||
" <td>0.0777</td>\n",
|
||||
" <td>ViT</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" test_loss test_acc number_of_parameters model_size (MB) \\\n",
|
||||
"model \n",
|
||||
"effnetb2 0.281287 0.968750 7705221 29 \n",
|
||||
"vit 0.064182 0.984659 85800963 327 \n",
|
||||
" test_loss test_acc number_of_parameters model_size (MB) \\\n",
|
||||
"0 0.281287 96.88 7705221 29 \n",
|
||||
"1 0.064182 98.47 85800963 327 \n",
|
||||
"\n",
|
||||
" time_per_pred_cpu \n",
|
||||
"model \n",
|
||||
"effnetb2 0.030839 \n",
|
||||
"vit 0.065751 "
|
||||
" time_per_pred_cpu model \n",
|
||||
"0 0.0302 EffNetB2 \n",
|
||||
"1 0.0777 ViT "
|
||||
]
|
||||
},
|
||||
"execution_count": 38,
|
||||
"execution_count": 212,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df = pd.DataFrame([effnetb2_stats, vit_stats])\n",
|
||||
"df[\"model\"] = [\"effnetb2\", \"vit\"]\n",
|
||||
"df = df.set_index(\"model\")\n",
|
||||
"df[\"model\"] = [\"EffNetB2\", \"ViT\"]\n",
|
||||
"df[\"test_acc\"] = round(df[\"test_acc\"] * 100, 2)\n",
|
||||
"df"
|
||||
]
|
||||
},
|
||||
@@ -2137,33 +2212,92 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"* TK - plot, accuracy vs time per pred (speed vs accuracy tradeoff graph)\n",
|
||||
"* TK - add in prediction times on Google Colab (could save my prediction times to a CSV and then import them both and compare them)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 39,
|
||||
"execution_count": 253,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"test_loss 0.228173\n",
|
||||
"test_acc 1.016422\n",
|
||||
"test_acc 1.016412\n",
|
||||
"number_of_parameters 11.135432\n",
|
||||
"model_size (MB) 11.275862\n",
|
||||
"time_per_pred_cpu 2.132085\n",
|
||||
"time_per_pred_cpu 2.572848\n",
|
||||
"dtype: float64"
|
||||
]
|
||||
},
|
||||
"execution_count": 39,
|
||||
"execution_count": 253,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df.loc[\"vit\"] / df.loc[\"effnetb2\"]"
|
||||
"# TK compare model sizes, test loss, parameter ratios, model sizes etc \n",
|
||||
"df.set_index(\"model\").loc[\"ViT\"] / df.set_index(\"model\").loc[\"EffNetB2\"]\n",
|
||||
"# df[0] / df[1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"* TK - plot, accuracy vs time per pred (speed vs accuracy tradeoff graph)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 254,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAusAAAH7CAYAAAB1x9E7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABWuklEQVR4nO3dd5xcVfn48c+TRkJCKAaWTui9x04JHaSDIggkIF9R+MlXVGIBxAiIBfyiggUUhEAAEQQERBBhaSpSDEiNlARCLyGySQhJ9vn9cWfjZDO7mSSzs5Ps5/16zWt37j33nOfOmdl95sy5ZyIzkSRJktR4enV3AJIkSZIqM1mXJEmSGpTJuiRJktSgTNYlSZKkBmWyLkmSJDUok3VJkiSpQZmsSzUWEcMjIiPiqO6oIyKaI2LCwrbdCErnfskiHD+6VMfQ2kXVaXtLR8RPI+KFiJi9uD/+S5KI2Coi/hIRk0vPidHdHZPUZlH/1qlnMFnXYqssoe3o9pHujhEgIn5XimerTspERDwfEe9ExIA6htclypLljIhPdlDmwLIyo+scYnkcl5RiGLII1XwdOAH4LXAUcGINQluidPB6bYmIhyLiSxHRuwva7ANcC6wPfAs4Evh9rdtRfUXEDhHxh4iYEBEzIuK1iHgwIn4SEet0d3xSrfXp7gCkGrgS+GOF7c/UO5AOXAR8Ejga+FIHZXYChgIXZOb0iLgbGADMXIj2dgdiIY7rCu9RnPc1FfZ9trS/f4V9A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ldIczFZ15JuQbLBhSmbneybS2a+FxFXAMdHxMeA+ylG2SdRjBJ1KjP/FhHrAntQLPW4E8VKKqdGxHbtEp75xjMfnc1JX5j6Lqb4hz2WIimo5s1JJbWOa2Hbq6attjKjKEZrK3m53f1pndRzOf8dvWxveoVt1cQeVH4OVzrmDSqs3FPmsU72levszXV5THvR8Tm0f+NZ6XHrzMI8Vzpro6M4q32+XkExUnshxbSptymSzk9QTJmq9Cl4I/bvpRTLcO5MkYCPoIhzbHmhzBwZEWdTnN92FFNbTomIE3MBltjM4tqZfwH/ioixwL+BkRFxfM59XU01f6fb7v+IjueST25XtprXZGf/K6SqmKxrSfds6eemFfZtUvr53CKU3bhC2Urb2lwEHE8xur4CxUVP380qL9jMYqm4a0s3IuJ4io/Zj6GY0lLJgpxXl8jMpyLibxRTQ/6a1V8Ytjj7d+nn1AWcotHeMxT/6PstYj2VPE2xhOYWFHN4O/JvYAPg79n1yxX+uxTTC5lZaUS0Fp4F9oyI5Sp8krEJxbz4+U1Lq4mIWI4iUb8sM7/Qbt+ui1h9vfv3Coq/QyMi4j6K75f4c2a+0r5gZj5G8Qbgh6XH4H7g+xHxs/LpPdXKzDci4lmKax6GMPenBJtUOKTt73Tb37621+vsKl5nC/KafJ3iothK/xcqxSXNwznrWtI9THEh6NFRrO0NQBRLiLVdMHnDQpR9iGJE/OjylWhKczDn+odbrjRvcxzFVJAvlur8TTUnUmHFm7aYoUj8O7Ig59WVvkHx8fI369BWI7iV4h/1NyJinv6JiAHRbgm/SjLzLYo57gdFhW/ljcKKCxnjFaWfZ0XEUpXqLv06huL/RaVVSYiI9tNSFsVlZTHN862mUZvl7q6nOJ9vtKt7L2BrimtIWmvQTjXa3qjPNdIbEasw94oxC6Ou/Vuaq38LxVK0h1PMt59r5DkLine truncated
|
||||
"text/plain": [
|
||||
"<Figure size 864x576 with 1 Axes>"
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"needs_background": "light"
|
||||
},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# Create a plot from model comparison DataFrame\n",
|
||||
"fig, ax = plt.subplots(figsize=(12, 8))\n",
|
||||
"scatter = ax.scatter(data=df, \n",
|
||||
" x=\"time_per_pred_cpu\", \n",
|
||||
" y=\"test_acc\", \n",
|
||||
" c=[\"blue\", \"orange\"], # what colours to use?\n",
|
||||
" s=\"model_size (MB)\") # size the dots by the model sizes\n",
|
||||
"\n",
|
||||
"# Add titles, labels and customize fontsize for aesthetics\n",
|
||||
"ax.set_title(\"FoodVision Mini Inference Performance vs Speed\", fontsize=18)\n",
|
||||
"ax.set_xlabel(\"Time per pred (seconds)\", fontsize=14)\n",
|
||||
"ax.set_ylabel(\"Test accuracy (%)\", fontsize=14)\n",
|
||||
"ax.tick_params(axis='both', labelsize=12)\n",
|
||||
"ax.grid(True)\n",
|
||||
"\n",
|
||||
"# Annotate with model names\n",
|
||||
"for index, row in df.iterrows():\n",
|
||||
" ax.annotate(text=row[\"model\"], \n",
|
||||
" xy=(row[\"time_per_pred_cpu\"]+0.0006, row[\"test_acc\"]+0.03),\n",
|
||||
" size=12)\n",
|
||||
"\n",
|
||||
"# Create a legend based on model sizes\n",
|
||||
"handles, labels = scatter.legend_elements(prop=\"sizes\", alpha=0.5)\n",
|
||||
"model_size_legend = ax.legend(handles, \n",
|
||||
" labels, \n",
|
||||
" loc=\"lower right\", \n",
|
||||
" title=\"Model size (MB)\",\n",
|
||||
" fontsize=12)\n",
|
||||
" \n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user