DIGITS-CNN/cars/architecture-investigations/architecture.ipynb

193 lines
96 KiB
Plaintext
Raw Normal View History

2021-04-10 12:20:26 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "e156c77a",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib as mpl\n",
"from matplotlib import pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "0456f690",
"metadata": {},
"source": [
"# Dense Layers\n",
"\n",
"Exponential LR Decay: 0.98\n",
"\n",
"100 Epochs\n",
"\n",
"## Index\n",
"0. fc layers\n",
"1. nodes per layer\n",
"2. top-1 accuracy\n",
"3. top-5 accuracy\n",
"4. last val loss\n",
"5. last val accuracy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "da786662",
"metadata": {},
"outputs": [],
"source": [
"fc_results = np.array([\n",
" [1, 512, 49.29, 73.93, 2.95, 53.25],\n",
" [1, 1024, 40.7, 68.38, 3.66, 45.22],\n",
" [1, 2048, 32.12, 58.93, 4.66, 35.72],\n",
" [1, 4096, 24.03, 46.76, 5.61, 27.94],\n",
" [1, 8192, 19.70, 41.01, 6.42, 23.96],\n",
" \n",
" [2, 512, 56.64, 82.46, 1.94, 60.23],\n",
" [2, 1024, 56.39, 81.53, 2.08, 60.91],\n",
" [2, 2048, 51.39, 79.00, 2.38, 56.74],\n",
" [2, 4096, 44.41, 71.83, 3.04, 47.61], # DEFAULT ALEXNET\n",
" [2, 8192, 37.74, 64.36, 3.60, 42.40],\n",
" \n",
" [3, 512, 30.7, 65.16, 2.57, 30.82],\n",
" [3, 1024, 48.36, 76.65, 2.30, 49.88],\n",
" [3, 2048, 54.11, 80.48, 2.38, 58.21],\n",
" [3, 4096, 54.48, 82.09, 2.39, 57.17],\n",
" [3, 8192, 50.71, 78.57, 2.55, 55.88],\n",
" \n",
" [4, 512, 0.8, 2.1, 5.29, 0.55],\n",
" [4, 1024, 0.8, 2.1, 5.29, 0.55],\n",
" [4, 2048, 25.45, 60.9, 2.84, 28.55],\n",
" [4, 4096, 41.14, 73.81, 2.81, 46.32],\n",
" [4, 8192, 49.85, 77.58, 2.97, 53.92]\n",
"])\n",
"\n",
"fc_0_results = [0, 196, 28.91, 54.05, 6.52, 33.21]\n",
"\n",
"layers = [1, 2, 3, 4]\n",
"nodes = [512, 1024, 2048, 4096, 8192]\n",
"\n",
"fc_matrix = np.zeros((4, 5))\n",
"for i in fc_results:\n",
" fc_matrix[layers.index(i[0]), nodes.index(i[1])] = i[2]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c0064d43",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWIAAAEtCAYAAAAyUmrDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAACrXElEQVR4nOydd5xjZfX/30/aZHrvM5nZ2d4ru4IogiBNQQUBvyiIWL6CKCDWrwL6syAqICoiRUEsC0gVcKW3Zdtsn9npvfdeUp/fHzc3ZGaSTNrMZHfzfr3y2k1y89znZm7OPfc853yOkFISJUqUKFEWDs1CTyBKlChRTnaihjhKlChRFpioIY4SJUqUBSZqiKNEiRJlgYka4ihRokRZYKKGOEqUKFEWmKghPs4QQlwphHjZx/sfEUK0hnmfPxBCPOT2/FNCiBYhxKgQYqMQYrkQ4pAQYkQI8Y1w7jvKVIQQ2UKIt53f9W+m/20WGiHE/UKIHy30PI47pJTHxQN4ExgAYhZ6LpH0ACSwxO35R4DWAL/XSWAEGAb2A9/z9T0DdcDFbs8fBu5eoOO/HfjbLNs0AhYgY9rrB53fX7Hz+SPAT318z2PAKNAG3AVovWwrgG8AZc7PtAJPAmvDcLw/Ap4GRASce18A3l3oeZwIj+PCIxZCFAMfQvkxXDTP+9bN5/4WiK9LKROBXOBbwBXAS0II4WX7IqDcx3O/mcfvtwH4rNt+1wJxAY6xXkqZA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SqxWK2azGavVSjQzJ0oU30Q94ih+43A4GB0ddRldu90+YxvVA1YNsuola7VadDodQoiolxwlyjSiHnEUv5B
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"X, Y = np.meshgrid(layers, nodes)\n",
"\n",
"# fig = plt.figure(figsize=(8, 5))\n",
"fig = plt.figure()\n",
"ax = plt.axes(projection='3d')\n",
"\n",
"surf = ax.plot_surface(X, Y, fc_matrix.T, cmap='viridis')\n",
"\n",
"ax.set_title('Accuracy with Different MLP Configurations')\n",
"ax.set_xlabel('Fully Connected Layers')\n",
"ax.set_ylabel('Nodes Per Layer')\n",
"ax.set_zlabel('Top-1 % Test Accuracy')\n",
"\n",
"ax.view_init(50, -150)\n",
"fig.colorbar(surf, shrink=0.3, aspect=6)\n",
"\n",
"plt.tight_layout()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "72a7412c",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEWCAYAAABhffzLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAABmxElEQVR4nO2dd3gV1daH35V6UkgnIfQOoTfpQlAsFxFEbKBeEBH02q/eq167F3tBvXaKWEHhEwsoCkhEKdJLpJfQEkoq6eVkf3/MJKTnJDnJOUn2+zzzZGbPzJ7fnHOy9szaa68tSik0Go1G03hwcbQAjUaj0dQt2vBrNBpNI0Mbfo1Go2lkaMOv0Wg0jQxt+DUajaaRoQ2/RqPRNDK04dc4LSJyl4icEZE0EQl2tJ6SmLraV/NcJSId7a1Jo7EFbfjrKSISJSJJIuLpaC21gYi4A28AlyulfJVSCTWsb4WIPFdG+XgROS0iblWt09R1pCa6ysL8brNEJFVEzovIVhF51Nm+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h/+QOmydiOq/7RvNiTJx/Iv1FXQkExbYfz98wPYPA/+/BC6/A0G3WkcJ1Ldu9BoNJpaoWE+8dub4Q+UbjTajbjQwLToB9d+BA9Gw4h/wYk/4dNx8P4w2PYZ5GbVtWJNNZgfPZ9NcZuKlW2K28T86PkOUqTR1A7a8NuTJs3gksfhwT0w/l3jaf/7e2B2N/h1lhFOWkvMj57PgawDxcq00aoaPYJ78PBvDxca/01xm3j4t4fpEdzDwco0GvvSMF09jsbdYnT29rkZYn6HjR/A2teMAV/dJ8Dgu6o/mKwcegT34P7t99Mnrg8DwwcWGq3XRr5m1+uURCmFVVmNJd9
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# plt.plot([196], fc_0_results[2], 'x-', label=f'0 Layers')\n",
"\n",
"for i in layers:\n",
" plt.plot(nodes, fc_matrix[i-1, :], 'x-', label=f'{i} Layers')\n",
"\n",
"plt.annotate('Standard\\nAlexNet', \n",
" (4096, fc_matrix[layers.index(2), nodes.index(4096)]),\n",
" textcoords=\"offset points\",\n",
" xytext=(40, 10),\n",
" ha='center',\n",
" arrowprops={\n",
" 'arrowstyle': 'simple'\n",
" }\n",
" )\n",
" \n",
"plt.title('Accuracy for Varied Dense Layers')\n",
"plt.xlabel('Nodes Per Layer')\n",
"plt.ylabel('Top-1 % Test Accuracy')\n",
"\n",
"plt.grid()\n",
"plt.legend()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6e359c36",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}