4414 lines
1.1 MiB
Plaintext
Raw Normal View History

2020-08-29 16:11:34 +02:00
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "CNN.ipynb",
"provenance": [],
"collapsed_sections": [],
"toc_visible": true,
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/Andreaierardi/Fruits-Neural-Networks/blob/master/project_code.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HtU6p0pB-N0A",
"colab_type": "text"
},
"source": [
"\n",
"# Image classification with Machine Learning\n",
"---\n",
"\n",
"## University of Milan \n",
"### DataScience and Economics - Machine Learning Module\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LGE0Fo3e-3Wk",
"colab_type": "text"
},
"source": [
"**Authors** : Andrea Ierardi, Emanuele Morales, Gregorio Luigi Saporito\n",
"\n",
"<br>\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F5Ew02Va-6DV",
"colab_type": "text"
},
"source": [
"How to load the dataset: \n",
"\n",
"\n",
"\n",
"```python\n",
"from google.colab import drive\n",
"drive.mount('/content/gdrive')\n",
"\n",
"\n",
"import os\n",
"os.environ['KAGGLE_CONFIG_DIR'] = \"/content/gdrive/My Drive/Kaggle\"\n",
"\n",
"\n",
"%cd /content/gdrive/My Drive/Kaggle\n",
"\n",
"\n",
"!kaggle datasets download --force -d moltean/fruits\n",
"\n",
"!unzip fruits.zip\n",
"```\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "tb4yPcdji5Ai",
"colab_type": "text"
},
"source": [
"# Image classification with Neural Networks\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pcRWLxstjHvN",
"colab_type": "text"
},
"source": [
"## 1. The dataset\n",
"### 1.1 Libraries\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "iXeBOWLtcdMv",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "317f98fa-192a-4556-e97b-9e2d8da88fb0"
},
"source": [
"import tensorflow as tf\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import os\n",
"from tqdm import tqdm\n",
"import random\n",
"import pandas as pd \n",
"\n",
"from plotnine import *\n",
"from sklearn.decomposition import PCA\n",
"\n",
"from sklearn.datasets import load_files\n",
"from keras.preprocessing.image import array_to_img, img_to_array, load_img\n",
"from sklearn import preprocessing\n",
"\n",
"from keras.utils import np_utils\n",
"from sklearn.utils import shuffle\n",
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"from keras.models import Sequential\n",
"from keras.layers import Conv2D,MaxPooling2D\n",
"from keras.layers import Activation, Dense, Flatten, Dropout\n",
"from keras.preprocessing.image import ImageDataGenerator\n",
"from keras.callbacks import ModelCheckpoint\n",
"from keras import backend as K\n",
"\n",
"from keras.applications import MobileNetV2\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Using TensorFlow backend.\n"
],
"name": "stderr"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QXB2MCkujQIi",
"colab_type": "text"
},
"source": [
"# 1.1 Data Loading"
]
},
{
"cell_type": "code",
"metadata": {
"id": "2w9LPk2Tc8Y7",
"colab_type": "code",
"colab": {}
},
"source": [
"DATADIR = \"fruits-360/Training\"\n",
"DATADIR_test = \"fruits-360/Test\"\n",
"\n",
"TYPES = [\"Apple\", \"Banana\", \"Plum\", \"Pepper\", \"Cherry\", \"Grape\", \"Tomato\", \"Potato\", \"Pear\", \"Peach\"]\n",
"fruits = {}\n",
"def load_dataset(dire):\n",
" fruits = {}\n",
" images_as_array = []\n",
" labels =[]\n",
" for category in tqdm(os.listdir(dire)):\n",
" for typ in TYPES:\n",
" if(category.split()[0] == typ):\n",
" fruits[category]= typ\n",
" path = os.path.join(dire,category)\n",
" class_num =TYPES.index(fruits[category])\n",
"\n",
" class_name = fruits[category]\n",
" for img in tqdm(os.listdir(path)):\n",
" file = os.path.join(path,img)\n",
" images_as_array.append(img_to_array(load_img(file,target_size=(32, 32))))\n",
" labels.append(class_num)\n",
" images_as_array = np.array(images_as_array)\n",
" labels = np.array(labels)\n",
" return images_as_array, labels"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "WHUwPqnPjoPp",
"colab_type": "text"
},
"source": [
"### Split in test and training sets\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "qY-O9bmQdDnq",
"colab_type": "code",
"colab": {}
},
"source": [
"train = load_dataset(DATADIR)\n",
"test = load_dataset(DATADIR_test)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "oEFfdWThdNjj",
"colab_type": "code",
"colab": {}
},
"source": [
"x_train, y_train= train"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "3x9fYmsWhoKe",
"colab_type": "code",
"colab": {}
},
"source": [
"x_test, y_test = test"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "oepGscO8jxgv",
"colab_type": "text"
},
"source": [
"### Train and test shape\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "hUqYyOVThpX6",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 124
},
"outputId": "f475c7c4-1acb-4345-ff7a-c5e437a5942d"
},
"source": [
"print('Train shape:')\n",
"print('X: ',x_train.shape)\n",
"print('y: ',y_train.shape)\n",
"\n",
"print('Test shape')\n",
"print('X: ',x_test.shape)\n",
"print('y: ',y_test.shape)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Train shape:\n",
"X: (32607, 32, 32, 3)\n",
"y: (32607,)\n",
"Test shape\n",
"X: (10906, 32, 32, 3)\n",
"y: (10906,)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nNf0OLzBj0Ot",
"colab_type": "text"
},
"source": [
"# 1.2 Pre-processing"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ENOcYiDEj4aD",
"colab_type": "text"
},
"source": [
"### Pre-process the labels and the images\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "JnU3AsJ3hqyw",
"colab_type": "code",
"colab": {}
},
"source": [
"x_train = x_train.astype('float32')/255\n",
"x_test = x_test.astype('float32')/255\n",
"\n",
"no_of_classes = len(np.unique(y_train))\n",
"y_train = np_utils.to_categorical(y_train,no_of_classes)\n",
"y_test = np_utils.to_categorical(y_test,no_of_classes)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "zklIYBIxhtug",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 214
},
"outputId": "c39ab752-199f-4775-c2d2-932e637a6b71"
},
"source": [
"print(y_train[0:10])\n",
"print(\"Number of classes: \",no_of_classes)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"[[1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n",
" [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]\n",
"Number of classes: 10\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "RQiX-6kfkCRl",
"colab_type": "text"
},
"source": [
"### Visualisation of the first 10 images\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "FmmJABIHhwIh",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 324
},
"outputId": "becfb7a0-905a-4795-9ef5-2e373a3e6971"
},
"source": [
"\n",
"fig = plt.figure(figsize =(30,5))\n",
"for i in range(10):\n",
" ax = fig.add_subplot(2,5,i+1,xticks=[],yticks=[])\n",
" ax.imshow(np.squeeze(x_train[i]))\n",
" ax.set_title(\"{}\".format(TYPES[np.argmax(y_train[i])]),color=(\"green\"),fontdict= {'fontsize': '25'})"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABfYAAAE6CAYAAABUGAPxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdeZhkaVnn/fucE1sutVf1Si92tyAwMqO2gPKyKKIoghujoAMNgzBuICL6DooUiSyCgKiMOMhiy9IojOOCo8MILyKISrXgxm7TTTe91JqVS0Sc9Xn/qCLPc/+iK6uyqazK6Pl+rouLePqcOHEiu+OOJ56I87uTEIIBAAAAAAAAAIDpkJ7vEwAAAAAAAAAAAGeOhX0AAAAAAAAAAKYIC/sAAAAAAAAAAEwRFvYBAAAAAAAAAJgiLOwDAAAAAAAAADBFWNgHAAAAAAAAAGCKsLC/iZKF5IPJQhKSheTF5/tcAODeiDoLAJuPWgsAm4s6CwCb695aZzvn+wQ2IllIdpnZ7WY2OPmP7hv2h8+dx1MCgHsV6iwAbD5qLQBsLuosAGwu6uzWMG2/2P8Ra/+DMTP7z+frRADgXoo6CwCbj1oLAJuLOgsAm4s6uwVM28L+M07+/2+e/P/rkoU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1uWn8sSaWFuTUOok8l2yd5zYxZ/XjUqptN/obs3YAnB9XXnmFfezA366Nk9B122upEVlUj6rMb+xM7OzrjV9FNUu0Vup6QLbeDM7fN0ht07WEUh69W+q5yuRdS10879TzOl2Ijexey/OcmD5LHXdOU2crORl9L
"text/plain": [
"<Figure size 2160x360 with 10 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "y_E6_3LzkFsR",
"colab_type": "text"
},
"source": [
"### Suffle of the data\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "tyKinSP8h5KH",
"colab_type": "code",
"colab": {}
},
"source": [
"x_train,y_train = shuffle(x_train, y_train)\n",
"x_test,y_test = shuffle(x_test, y_test)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "NIVoRrD7kHvO",
"colab_type": "text"
},
"source": [
"### Visualisation of the first 10 images shuffled\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "9a4KNtsoh6n7",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 324
},
"outputId": "ae70bb27-0b73-4f45-da52-b4103cdab909"
},
"source": [
"\n",
"fig = plt.figure(figsize =(30,5))\n",
"for i in range(10):\n",
" ax = fig.add_subplot(2,5,i+1,xticks=[],yticks=[])\n",
" ax.imshow(np.squeeze(x_train[i]))\n",
" ax.set_title(\"{}\".format(TYPES[np.argmax(y_train[i])]),color=(\"green\"),fontdict= {'fontsize': '25'})\n",
"\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABfYAAAE6CAYAAABUGAPxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdd5gkV3k9/nOrqrunJ+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zcXHeiqA5wN4OLKvhfTv5X7Hz3PMH+3LA4uIHGz72DsvALCnYX5rnv2/ieyryw9wdVfqTuos9nyGkF0p/1RkuaQrkV1hbx0PYMsiD/8QHKLnISKyn3b5mr9tjm2bCrdHkEUzANmVmvs9zu3a17HqQvt9BNkCvA9xdfcQX/M/L2zbc7X+93zN37yPjyciMp8/QzbW+75d7NDX/Liru68gu3DjxQB+PMcxrvE1P763Db7mb+1+u/N4ZFERe1uI97t7Wzel6wfIcpuj7v1/Pf/TAZBl+wPA2a7u5hv7Vrt/nrQPxxQROeg0T3toHDYT++B/1BaAHci+Bn2Jr/nvAICru2ML++zrb3iKV0IFyP7nK17FGSNbtLHdrVcg+59yYJ5jLvuMJhE5YuxL71xX2OfeeY6156tqEbIrmfY2WTQnV3dnAPg2+A23AWAUQNqt9/Tu+XrsXA7J8xCRI9bOwu1V4An4xZqYZ1txMa/iLz73a5xr7OtYdd79fM1vdHV3JYAnI7tq/y+Ama9hP6e7294iekREFqX7Wf2F3dLG8OzxaWSf5Z/t6u6Vc3wzab4x4p7tx4PHlft0f1/zTVd3O5H16Lnub+3p7X3IJ7/mM1dfF
"text/plain": [
"<Figure size 2160x360 with 10 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aI-v_vkFkK6A",
"colab_type": "text"
},
"source": [
"### Split in validation and test set\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "chR6UKO9h9Az",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 53
},
"outputId": "4ea738a5-6b55-46a7-9d3e-97c6c86c17b9"
},
"source": [
"# Using 80-20 rule\n",
"split = len(x_test)*80//100\n",
"\n",
"print('Test len before split: ',len(x_test))\n",
"print('Validation split len:', split)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Test len before split: 10906\n",
"Validation split len: 8724\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GTktl3TSh-zx",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 142
},
"outputId": "2bd7432b-98b1-4715-f527-f399dda3a2bc"
},
"source": [
"# Now, we have to divide the validation set into test and validation set\n",
"x_test,x_valid = x_test[split:],x_test[:split]\n",
"y_test,y_valid = y_test[split:],y_test[:split]\n",
"print('Train X : ',x_train.shape)\n",
"print('Train y :',y_train.shape)\n",
"\n",
"print('1st training image shape ',x_train[0].shape)\n",
"\n",
"print('Validation X : ',x_valid.shape)\n",
"print('Validation y :',y_valid.shape)\n",
"print('Test X : ',x_test.shape)\n",
"print('Test y : ',y_test.shape)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Train X : (32607, 32, 32, 3)\n",
"Train y : (32607, 10)\n",
"1st training image shape (32, 32, 3)\n",
"Validation X : (8724, 32, 32, 3)\n",
"Validation y : (8724, 10)\n",
"Test X : (2182, 32, 32, 3)\n",
"Test y : (2182, 10)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wtCzXW5-EmnM",
"colab_type": "text"
},
"source": [
"### Definition of zero-one loss function "
]
},
{
"cell_type": "code",
"metadata": {
"id": "atod5RB6ErJA",
"colab_type": "code",
"colab": {}
},
"source": [
"def zero_one(prediz,test):\n",
" y_hat = []\n",
" y_t = []\n",
" for i in range(len(prediz)):\n",
" y_hat.append(np.argmax(prediz[i]))\n",
" y_t.append(np.argmax(test[i]))\n",
"\n",
" \n",
" loss = []\n",
" for i in range(len(prediz)):\n",
" if(y_hat[i] == y_t[i]):\n",
" loss.append(0)\n",
" else:\n",
" loss.append(1)\n",
"\n",
"\n",
" return np.mean(loss)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "W4E_e-iXB-BS",
"colab_type": "text"
},
"source": [
"\n",
"# 1.3 PCA and feed-forward NN\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "hj6pgmhVCH1q",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 284
},
"outputId": "db0fb3e0-bff7-45f5-a7e5-e18e5ff88b0e"
},
"source": [
"plt.imshow(x_train[0])"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f72992944a8>"
]
},
"metadata": {
"tags": []
},
"execution_count": 25
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAX6ElEQVR4nO3de5DdZXkH8O9zbnvNPZsLSSCAVMtYRbtNURm1WB2qTsGxw+BMHZwyxGmlI622pXRGcKbtoKOgpa1tEGpSkYAiJeMwKlKm0VGQBSEEEIG4SEIuu0k2e7+cc57+cU6cBd/vu5s9t4T3+5nJZPf37O/83v2d85zf7u/Z93nN3SEir32ZVg9ARJpDyS6SCCW7SCKU7CKJULKLJELJLpKIXC07m9lFAL4MIAvgq+5+Q+zrV65c6Rs3bqzlkCIS0d/fj8HBQQvFFpzsZpYF8G8A3gtgL4BHzGyHuz/N9tm4cSP6+voWekgRmUNvby+N1fJj/CYAz7v7HnefBrAdwMU1PJ6INFAtyb4OwEuzPt9b3SYiJ6GG36Azs81m1mdmfQMDA40+nIgQtST7PgAbZn2+vrrtFdx9i7v3untvT09PDYcTkVrUkuyPADjHzM40swKAywDsqM+wRKTeFnw33t2LZnYVgO+hUnq7zd2fqtvIRKSuaqqzu/t9AO6r01hEpIH0F3QiiVCyiyRCyS6SCCW7SCKU7CKJULKLJELJLpIIJbtIIpTsIolQsoskQskukgglu0gilOwiiVCyiyRCyS6SCCW7SCKU7CKJULKLJELJLpIIJbtIIpTsIolQsoskQskukgglu0gilOwiiahpRRgz6wcwAqAEoOjufC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needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "8wJ0sLn7CLb_",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 284
},
"outputId": "ea683341-8d6d-4ae7-e06d-30a537c65f5c"
},
"source": [
"x_train[0].shape\n",
"type(x_train[1])\n",
"rgb_weights = [0.2989, 0.5870, 0.1140]\n",
"image_test = x_train[0]\n",
"image_grey = np.dot(image_test[...,:3], rgb_weights)\n",
"plt.imshow(image_grey, cmap=plt.get_cmap(\"gray\"))"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f729920a198>"
]
},
"metadata": {
"tags": []
},
"execution_count": 26
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAATaElEQVR4nO3de4xd1XXH8e/KYBuDDdiegUyM8SQGqUJRA2hEKEXIJAqiKBIgVQgUIf4gcVIFCaL0D0SlxpWqKKkbUP5AVBNAcVAKcZvwEDIpLkKCRImTSQrm1RaDDNj4MQYc2yHB2Kz+cY/VsXXWmutzX+Ps30eyfGfvu+9Zc2bW3HvPuntvc3dE5E/fRwYdgIj0h5JdpBBKdpFCKNlFCqFkFymEkl2kECd0MtjMrgC+CwwB97j7t7L7Dw8P+9jYWCeHFJHEli1b2L17t9X1NU52MxsC7gI+B2wFfm1mj7r7S9GYsbExJicnmx5SRGYwPj4e9nXyMv5CYLO7v+buB4AHgas6eDwR6aFOkn0p8Oa0r7dWbSIyC/X8Ap2ZrTKzSTObnJqa6vXhRCTQSbJvA5ZN+/rMqu0I7j7h7uPuPj4yMtLB4USkE50k+6+Bc8zs42Y2F7g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mN8MxTSdYzXbtPLMfBL7u7ucCFwFfNbNzgduAJ939HODJ6msRmaVmTHZ33+7uv61u7wNeBpYCVwFrq7utBa7uVZAi0rljes9uZmPA+cBG4Ax3P/z6aQetl/kiMku1nexmtgD4MXCrux+xiLe33
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "F7WMKP77CN5l",
"colab_type": "code",
"colab": {}
},
"source": [
"# transform np.ndarray from rgb to grey\n",
"x_train_grey = np.ndarray(shape=(x_train.shape[0], 32, 32))\n",
"for i in range(x_train.shape[0]):\n",
" image_convert = x_train[i]\n",
" x_train_grey[i] = np.dot(image_convert[...,:3], rgb_weights)\n",
"\n",
"x_valid_grey = np.ndarray(shape=(x_valid.shape[0], 32, 32))\n",
"for i in range(x_valid.shape[0]):\n",
" image_convert = x_valid[i]\n",
" x_valid_grey[i] = np.dot(image_convert[...,:3], rgb_weights)\n",
" \n",
"x_test_grey = np.ndarray(shape=(x_test.shape[0], 32, 32))\n",
"for i in range(x_test.shape[0]):\n",
" image_convert = x_test[i]\n",
" x_test_grey[i] = np.dot(image_convert[...,:3], rgb_weights)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "kQp1VlmNCTrg",
"colab_type": "code",
"colab": {}
},
"source": [
"# flatten 32x32 images by concatenating them into a vector, each column of the matrix will be an image\n",
"x_train_flat = np.ndarray(shape=(1024, x_train_grey.shape[0]))\n",
"for i in range(x_train_grey.shape[0]):\n",
" x_train_flat[:,i] = np.concatenate(x_train_grey[i])\n",
" \n",
"x_valid_flat = np.ndarray(shape=(1024, x_valid_grey.shape[0]))\n",
"for i in range(x_valid_grey.shape[0]):\n",
" x_valid_flat[:,i] = np.concatenate(x_valid_grey[i])\n",
" \n",
"x_test_flat = np.ndarray(shape=(1024, x_test_grey.shape[0]))\n",
"for i in range(x_test_grey.shape[0]):\n",
" x_test_flat[:,i] = np.concatenate(x_test_grey[i])"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "EDytYvesCVeH",
"colab_type": "code",
"colab": {}
},
"source": [
"standard_scaler = preprocessing.StandardScaler()\n",
"x_train_flat_T = standard_scaler.fit_transform(x_train_flat.T)\n",
"x_valid_flat_T = standard_scaler.transform(x_valid_flat.T)\n",
"x_test_flat_T = standard_scaler.transform(x_test_flat.T)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ZGtU-XWnCWvV",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "1922c5a6-2567-4bf3-fe73-9b52459a5b41"
},
"source": [
"x_train_flat_T.shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(32607, 1024)"
]
},
"metadata": {
"tags": []
},
"execution_count": 30
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "uP7JKLlfCtyz",
"colab_type": "code",
"colab": {}
},
"source": [
"x_train_flat = x_train_flat_T.T\n",
"x_valid_flat = x_valid_flat_T.T\n",
"x_test_flat = x_test_flat_T.T"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "thz9QZ8vCwqv",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "711ec999-f6f6-43eb-f2a0-27b722610167"
},
"source": [
"x_train_flat.shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(1024, 32607)"
]
},
"metadata": {
"tags": []
},
"execution_count": 32
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GJdRuaA8C6i1",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "49eb7a01-aacf-473f-8535-e3e46f941c4d"
},
"source": [
"a = np.cov(x_train_flat)\n",
"b = np.linalg.eig(a)\n",
"b[0].shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(1024,)"
]
},
"metadata": {
"tags": []
},
"execution_count": 33
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "vlld5mxVC8jK",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 285
},
"outputId": "a4622afa-ad6d-4a8f-c13d-976f75310bbd"
},
"source": [
"b"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(array([384.41591328, 86.57192039, 60.39849467, ..., 0. ,\n",
" 0. , 0. ]),\n",
" array([[-2.77148730e-03, 1.99671963e-02, -7.00245270e-03, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n",
" [ 1.06770166e-04, 5.26867240e-03, -3.60037909e-03, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n",
" [-1.31497722e-04, 4.57673250e-03, -2.40477865e-03, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n",
" ...,\n",
" [ 9.24994377e-04, 3.61739014e-03, 2.95348978e-03, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n",
" [ 1.13335613e-03, 5.13559532e-03, 3.96259018e-03, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],\n",
" [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,\n",
" 0.00000000e+00, 0.00000000e+00, 1.00000000e+00]]))"
]
},
"metadata": {
"tags": []
},
"execution_count": 34
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4h8Gn0NrZMoB",
"colab_type": "text"
},
"source": [
"### PCA explained variance ratio and \"Eigenfruits\""
]
},
{
"cell_type": "code",
"metadata": {
"id": "CLkaQNHKDAAR",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 446
},
"outputId": "74dbcbf3-c122-4bab-e5e3-c59b223a2221"
},
"source": [
"pca = PCA().fit(x_train_flat)\n",
"plt.figure(figsize=(18, 7))\n",
"plt.plot(pca.explained_variance_ratio_.cumsum(), lw=3)"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f72991f9b38>]"
]
},
"metadata": {
"tags": []
},
"execution_count": 35
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABBEAAAGbCAYAAACS6AhyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deZSkV30f/O/tffZFM9JIGkkjyRJCAgRizGoMNosB+wWSYAdOwHiJyebEiZ3kYL9v7Nd2nBw7eePYiUPA2MbxMRBsYyMbYWIIBsJmBAihFW1IGmlGs0izT+/3/aOqq6tn0VTP9Ex1d30+58yp597nqapft0p15n7n3vuUWmsAAAAATqev2wUAAAAAS4MQAQAAAOiIEAEAAADoiBABAAAA6IgQAQAAAOjIQLfeeNOmTXXbtm3densAAADgJL761a/urbVuPtm5roUI27Zty6233tqttwcAAABOopTy8KnOWc4AAAAAdESIAAAAAHREiAAAAAB0RIgAAAAAdESIAAAAAHREiAAAAAB0RIgAAAAAdESIAAAAAHREiAAAAAB0RIgAAAAAdESIAAAAAHREiAAAAAB05LQhQinld0spu0spd5zifCml/GYp5f5Syu2llJsWvkwAAACg2zqZifD+JK99mvOvS3JN8887k7z77MsCAAAAFpuB011Qa/1sKWXb01zyxiT/o9Zak3yplLK+lHJxrXXnAtUIAACwKNVaM12Tqema6VpTazJVG8fT041z7cdTreOTnGv1n3hupr82j0/1OF2TpP05jRrr07Uz2z89XVOT2Xbr2pn3OUk7mVNz6tx2rbO/p+nm9Y33mm13+rMd/35zf5bmz39cu/V+zfecaaftfWf6mr++Oe3a/B01fo7Z/+71hOc3nnz869Wa/PrfvTHfe91F5+dDeY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0Hw8PNadMGCovy9rVwxm7YpGCLCmGQCsGR7M6jlBwGwYsHpkIGtHBrK6ec2qoX4DfwCA80SIALDIHRufyt7DY3nyyHj2HRnL3sPjjePDY9l3eDz7mv0zx+OT53eJwJrhgWYQMJh1zTBgXas9czzQeDzunH/5BwBYWoQIAOfZ5NR0njwynt2HxhoBQDMg2Hu47bit/+j4ud84sK8k61cOZf3KwWxYOZQNKwezfs5j49zcIKAxO6DfrfcAAHqGEAFggYxOTGX3wbHsOTya3QfHsvvQWHYfGs2eQ83jZt+TR8YyXc9dHSODfdm4cqgx+F81GwZsmOlrHc8EBkNZMzKQPmEAAACnIUQAOI3Riak8cXA0Ow+MZteB0ew+NBsS7GkGBbsPjZ2zTQaH+vuycdVQLlg9lAtWD+eCVUONPzPHq+cerxzy1Q4AwLnhb5pATzs8NpldB45l14Gx7DxwLLsOjGbnwUZYsPPAaJ44OJonj4wv+PtuXDWUzauHs2nNUDauagQAm1Y3j1fPPV4zPGDfAAAAFgUhArBsTU5NZ+eB0Ty2/1h2PHUsjz11LI/tP9qaUbDrwGgOLeBdCQb6SjavGc6Fa4azec1I6/jCtcO5cM1Is384m1YPZ2igb8HeFwAAzhchArBkjU1OZef+mZDgaB57qhEW7NjfCAx2HRzN1AJsPtDfV7Jl7UguWjucLetGctHamYBgZE5IsH7FoH0FAABY1oQIwKJVa82eQ2N5+MmjeXjf0Ty870geefJoIyh46mh2HxpLPcuMYGigLxevG8mWtSO5eN1ILlo3kovXjmTLuhW5eF2j74LVw+5AAAAAESIAXTaz5ODhfUfz7WZI8PC+I3l439E88uTRs7694eY1w9m6YUUuXb8iWzeszKUbVuSSdSPZsm4kF69bkQ0rB+03AAAAHRIiAOdcrTW7D43lg
"text/plain": [
"<Figure size 1296x504 with 1 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "oDjU6YEtDCCg",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 300
},
"outputId": "441a7dcc-7cbc-46ce-8a62-e0aefa9a491a"
},
"source": [
"# try to plot some of the eigenvectors, the so called \"eigenfruits\"\n",
"fig = plt.figure(figsize =(30,5))\n",
"for i in range(10):\n",
" ax = fig.add_subplot(2,5,i+1,xticks=[],yticks=[])\n",
" ax.imshow(np.squeeze(b[1][:,i].reshape(32,32)))\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABfYAAAEhCAYAAAA9CfGpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdWawkWX7f9xNbrnerW3vv68z0LBwOR54ZjkaiZQsEaIrwJlgQYOvR9oNhA5QhwYANwzBsw/CT9CDbsGAYAmzJsC2ClG2QFi2TIKmByOHsw+6Znp7unq7qquqqW3XX3CPCD4RunN8vujLrit11O8nv5yn/HXEjI7M6/3HyZObvJHVdBwAAAAAAAAAAsB7S8z4BAAAAAAAAAADw6JjYBwAAAAAAAABgjTCxDwAAAAAAAADAGmFiHwAAAAAAAACANcLEPgAAAAAAAAAAa4SJfQAAAAAAAAAA1kh+lp03d/P68pPd07qfzGV7bfv3k+Shx1rY3nWtdRn0b6e1nmpl2xd1JvUs2n+8KHTfSj/PqGo9Vl0//LxDCCFJ9FyztNI62t7L9DnqpgupB+lU/9ael649h3XrWVZZ9FlNZftO7DneLwdSX8xOTm/fvFGG+/er5U8EgA9cvjWoiys7p3U1y5bsbZa3h9VWveJ9e9rcYZLqnafWF1Prm167Onhf1u1x3y5L+4zaW5f39FJLP5XWJeCP0AmHGxOpR4c9qafv3rhX1/Xlf/Z7AHBW2XBYFzu7zX9Y8RpfOixc2S9WNGZrX2mmvTOPah9TdhJtZmmif+v81HwsPa9sLF01Y+nJwsbh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Wl43sefF8bgDnbtXrWL4G4/HEKzL1OwPtXVsD7cP9XPtVZVnM+/NmDZA37Ps49/INqbuWqe99eGIN6LjUvNJZpb3yeNHkRO/PNE/Uz7Ms9dw8l7WeWG70zDJGF0sG277mwYoM6SVLzwB4nJJg/dNevJYnn46bnYsjy9j3KGh7nXsf7z5Y/n7flxiJj1f62DvX/9Dpaq/t5FoXXT2Z2ULvvCz0sS2i/jm352jRtRPf1z6ezux7mr4kif25r0WwjD+nVcfXLZDVAR79wAAem8TWK6nypikUQx2jejz/haGur/fyzl2pPzG8LbWv3fS3b/9Zqd86aLLs9490XDkfa29LRsunqutcG1RifTe3Ph2vhXJpQ+c4LnR1XvRCRx/3n7r2jtSv9y9LffdQx+OTAx1f1/E1xDLz09nyQWv1iDP2fGMfAAAAAAAAAIA1wsQ+AAAAAAAAAABrhIl9AAAAAAAAAADWyJkz9ntR2Fon0Twgz9h/t2yyOb850Qzj/+XmF6R+89XrUm+9roFw19/RQLjuvmaUJgu972zcZCgl8xVhcolnVlvOkWfy55YjmnmGclN3jvRxDO5a3um2bh/f1TymH97V5+3GiztS33tW85x+cthk7nc6+rifSjQrarAkzolPfIDzE2daJpWHB1sZ5V1WW5old/XavtQvbO9Jfb13IPVGPpXa85jHpdb78yYb79Dzly3kM7UT71mu9DCzDP1Ce/x2rv0rFq8tEkIIF1PNzbuc6+P8dEefhy8Ofij1b2/oGi+/3v+E1D+4deX0dn1LswQ9JzpdeI50APAREMcYe5+tLeNYUoQ9zthe47XVlWXPj2bLF9rIUs0ITaNz8b7qmfjeZ+d2sgsLWz6JxukhhHA81zHo8aypp6X+7eFIe990qo+r8mxUz8kvrVd65n687pMPSj3K2Y/NIBb46IhfzNZrvQ9kk6YudBmoVt57PrL3/jpsbGXozzd9TTz9+zJep8oy9ZNkeZ2lPsbVwd5OT8ewqf39tGz65Whua6FMtC9PC31/P+/o9
"text/plain": [
"<Figure size 2160x360 with 10 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bmppOi2NDOey",
"colab_type": "text"
},
"source": [
"\n",
"### Reduce image noise with PCA\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "oSbd6LrbDNjj",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "c9101411-6870-4b18-a05f-c16d40770250"
},
"source": [
"x_train_flat.shape, x_valid_flat.shape, x_test_flat.shape"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"((1024, 32607), (1024, 8724), (1024, 2182))"
]
},
"metadata": {
"tags": []
},
"execution_count": 37
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "V-msFuA7DWSH",
"colab_type": "code",
"colab": {}
},
"source": [
"\n",
"def PCA_iter(x_all,start, end, step):\n",
" lis =[]\n",
" for i in range(start, end, step):\n",
" print(\"\\n\\n===== Component: \",i,\"=====\\n\")\n",
" \n",
" (train,valid, test) = x_all\n",
" pca = PCA(n_components=i)\n",
" print(\"original shape: \", train.shape)\n",
"\n",
" \n",
" pca.fit_transform(train)\n",
" \n",
" train_PCA = pca.transform(train)\n",
" train_new = pca.inverse_transform(train_PCA)\n",
"\n",
" valid_PCA = pca.transform(valid) \n",
" valid_new = pca.inverse_transform(valid_PCA)\n",
" \n",
" \n",
" test_PCA = pca.transform(test)\n",
" test_new = pca.inverse_transform(test_PCA)\n",
"\n",
" \n",
" print(\"transformed shape:\", train_PCA.shape)\n",
" print(\"final shape:\", train_new.shape)\n",
"\n",
" tupla = (x_train_PCA, x_valid_PCA, x_test_PCA) =train_new,valid_new,test_new\n",
" \n",
" lis.append(tupla)\n",
" return lis"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "CHoTcijWDddc",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "a39f8b54-12c3-4e8a-eaee-e8c8ee2aa339"
},
"source": [
"lis_PCA = PCA_iter((x_train_flat_T,x_valid_flat_T, x_test_flat_T),10,211,20)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"\n",
"\n",
"===== Component: 10 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 10)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 30 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 30)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 50 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 50)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 70 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 70)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 90 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 90)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 110 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 110)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 130 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 130)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 150 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 150)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 170 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 170)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 190 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 190)\n",
"final shape: (32607, 1024)\n",
"\n",
"\n",
"===== Component: 210 =====\n",
"\n",
"original shape: (32607, 1024)\n",
"transformed shape: (32607, 210)\n",
"final shape: (32607, 1024)\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "1W9YHNj7DpS_",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 284
},
"outputId": "4e0f78b6-47ca-4bda-acbd-8eca4b2289bc"
},
"source": [
"# 10 components example of the same image\n",
"tr,va,te = lis_PCA[1] \n",
"plt.imshow(tr[2,:].reshape(32,32), cmap=plt.get_cmap(\"gray\"))"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f7296f20a20>"
]
},
"metadata": {
"tags": []
},
"execution_count": 40
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAWyklEQVR4nO2da4xd1XXH/8uDH4Nn/BgbzPgh7FDEQxExMDJUQRFNlIiiSDxUIfwB8QHFURWkIqUfEJUKlYpEqgLiQ0VlihWnUB4NQVgVakNRJBTxiMcufmFqjGVgzPhtj8dvPLP64R6rY+us/53Z995zHe//T7J8Z6+7z15nn7PuY//vWtvcHUKIi59J7XZACFENCnYhMkHBLkQmKNiFyAQFuxCZoGAXIhMuaaSzmd0B4DkAHQD+xd2fYs/v7Oz0GTNmlDtySezKpEnlr0nTpk0L+5w5cybJxqTIkZGRpo518uTJCY9Vj2geJ0+ePOE+9fpNmTJlwjY2VkdHR2hj83H69OnQNjo6Gtoi2D3Ajsf6mdmEbSl9Dhw4gOHh4VJjcrCbWQeAfwLwQwADANaa2Rp3/yTqM2PGDCxfvrzU1tPTE47V3d1d2n7NNdeEffbv3x/aDh48GNpOnDgR2o4cOVLafuDAgbDPvn37Qttnn30W2oaGhkIbu+Euv/zy0vbe3t6wz5w5c0Lb/Pnzk2yLFy8ubZ89e3bYh9nYfAwMDIS248ePl7azOWQvLNHxAP7izV4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tkcc2weOXbOosCTLvmNZjBF6ZxciExTsQmSCgl2ITFCwC5EJCnYhMqHy1fgTJ06UO0KSUyIb65OaSJKyM
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "v1zpZzo_DgPr",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 284
},
"outputId": "23384fb3-d61f-4670-f741-39e6717355c8"
},
"source": [
"# 210 components example of an image\n",
"tr,va,te = lis_PCA[len(lis_PCA)-1]\n",
"plt.imshow(tr[2,:].reshape(32,32), cmap=plt.get_cmap(\"gray\"))"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<matplotlib.image.AxesImage at 0x7f7296e8c1d0>"
]
},
"metadata": {
"tags": []
},
"execution_count": 41
},
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAAD5CAYAAADhukOtAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAXXElEQVR4nO2dXYhdVZbH/6vyWUlVJalUPsokbWIMiMh0lCI4tDRON904IqgwSHwQH6TTDC2M2PMgDowK82APo+LD4BDH0OnBMTrtV4ihbSe0aCvYKR2NiZmZjiGiManKRyVV+TCaypqHe8JU5Kx/Ve1777np7P8PQm7tdfc56+571v3Y/7vWMneHEOLSp63VDgghqkHBLkQmKNiFyAQFuxCZoGAXIhMU7EJkwtR6JpvZTQCeBDAFwL+6+6Ps/p2dnd7T01Nqa2uLX3ciedDMJupqQ+alHO/EiROh7eTJk0nnmzFjRmibPn166fjUqfFTzfyfNm1aaGPHnDJlSun4uXPnwjmjo6OhjUnEKfIxe8zMRzYv9ZgR0XMJAF9//XXp+ODgI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jNE0hCTflhGVqpkF/meUiusHhvL9osed0pbK4DLiky+imypWYWpz1n03LBrh2XRMXmNtdhK8Z+tb8rxxg12d7+zZPiZSZ9JCNFS9As6ITJBwS5EJijYhcgEBbsQmaBgFyITKi042dbWlpQNFckdTD5JlUFYtlk0L6XwIsBlHFo4MCFrj81JlSmZRBXZmLyWmtnGjhnZUjPK2LnYtZPyfM6aNSuck5KBqXd2ITJBwS5EJijYhcgEBbsQmaBgFyITFOxCZ
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "6-rpOqx0Du8Y",
"colab_type": "text"
},
"source": [
"\n",
"## Train feed-forward NN with reduced images\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "D1mWo4zKDulG",
"colab_type": "code",
"colab": {}
},
"source": [
"def FW_iter(lis_PCA, ep, bs):\n",
" lis_FW = []\n",
" epochs = ep\n",
" batch_size = bs\n",
" for itr in range(len(lis_PCA)):\n",
" x_train_PCA, x_valid_PCA, x_test_PCA = lis_PCA[itr]\n",
" \n",
" \n",
" print(\"FW- components: \",(itr+1)*20-10)\n",
" #feed forward neural network\n",
" model = tf.keras.Sequential([\n",
" tf.keras.layers.Input(shape = (1024)),\n",
" tf.keras.layers.Dense(32, activation = \"relu\"),\n",
" tf.keras.layers.Dense(10, activation='softmax')\n",
" ])\n",
" model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
" \n",
" \n",
" history = model.fit(x_train_PCA, y_train,\n",
" batch_size = bs,\n",
" epochs = epochs,\n",
" validation_data=(x_valid_PCA, y_valid),\n",
" verbose = 2\n",
"\n",
" )\n",
" \n",
" y_pred = model.predict(x_test_PCA).round()\n",
" \n",
" zo_loss = zero_one(y_pred,y_test)\n",
" print(\"Zero-one loss: \",zo_loss)\n",
" tupla = (history, model, zo_loss)\n",
" lis_FW.append(tupla)\n",
" return lis_FW"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "sPVnWMi8Du2S",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "8ab75f95-e34a-4179-bd88-7673124174c1"
},
"source": [
"epochs = 10\n",
"batch_size = 32\n",
"res = FW_iter(lis_PCA, epochs, batch_size)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"FW- components: 10\n",
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.175393). Check your callbacks.\n",
"1019/1019 - 5s - loss: 0.8917 - accuracy: 0.6877 - val_loss: 1.3535 - val_accuracy: 0.5962\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.6398 - accuracy: 0.7802 - val_loss: 1.3279 - val_accuracy: 0.6405\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.5631 - accuracy: 0.8033 - val_loss: 1.2432 - val_accuracy: 0.6723\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.5202 - accuracy: 0.8203 - val_loss: 1.2590 - val_accuracy: 0.6750\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.4846 - accuracy: 0.8326 - val_loss: 1.3413 - val_accuracy: 0.6714\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.4573 - accuracy: 0.8445 - val_loss: 1.2513 - val_accuracy: 0.6985\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.4322 - accuracy: 0.8521 - val_loss: 1.2741 - val_accuracy: 0.6983\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.4193 - accuracy: 0.8566 - val_loss: 1.3041 - val_accuracy: 0.7063\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.4008 - accuracy: 0.8640 - val_loss: 1.3032 - val_accuracy: 0.7003\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.3982 - accuracy: 0.8641 - val_loss: 1.3579 - val_accuracy: 0.6978\n",
"Zero-one loss: 0.28689275893675525\n",
"FW- components: 30\n",
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.261349). Check your callbacks.\n",
"1019/1019 - 6s - loss: 0.6436 - accuracy: 0.7845 - val_loss: 1.0769 - val_accuracy: 0.6961\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.3235 - accuracy: 0.8948 - val_loss: 1.0283 - val_accuracy: 0.7299\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.2424 - accuracy: 0.9211 - val_loss: 1.0095 - val_accuracy: 0.7387\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.1909 - accuracy: 0.9384 - val_loss: 0.9939 - val_accuracy: 0.7633\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.1558 - accuracy: 0.9502 - val_loss: 1.1439 - val_accuracy: 0.7466\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.1404 - accuracy: 0.9538 - val_loss: 1.0946 - val_accuracy: 0.7713\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.1227 - accuracy: 0.9603 - val_loss: 1.1294 - val_accuracy: 0.7809\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.1098 - accuracy: 0.9649 - val_loss: 1.1915 - val_accuracy: 0.7785\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.1003 - accuracy: 0.9675 - val_loss: 1.1726 - val_accuracy: 0.7894\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0947 - accuracy: 0.9702 - val_loss: 1.2234 - val_accuracy: 0.7822\n",
"Zero-one loss: 0.19798350137488543\n",
"FW- components: 50\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.5459 - accuracy: 0.8254 - val_loss: 0.8101 - val_accuracy: 0.7436\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.2140 - accuracy: 0.9335 - val_loss: 0.8365 - val_accuracy: 0.7656\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.1433 - accuracy: 0.9549 - val_loss: 0.8540 - val_accuracy: 0.7918\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.1039 - accuracy: 0.9682 - val_loss: 0.8805 - val_accuracy: 0.7915\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0848 - accuracy: 0.9738 - val_loss: 0.9716 - val_accuracy: 0.8034\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0715 - accuracy: 0.9778 - val_loss: 0.9149 - val_accuracy: 0.8155\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0664 - accuracy: 0.9790 - val_loss: 1.1081 - val_accuracy: 0.8093\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0539 - accuracy: 0.9832 - val_loss: 1.1118 - val_accuracy: 0.7929\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0512 - accuracy: 0.9835 - val_loss: 1.0935 - val_accuracy: 0.8323\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0465 - accuracy: 0.9845 - val_loss: 1.0836 - val_accuracy: 0.8343\n",
"Zero-one loss: 0.15902841429880843\n",
"FW- components: 70\n",
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.200094). Check your callbacks.\n",
"1019/1019 - 5s - loss: 0.4945 - accuracy: 0.8395 - val_loss: 0.8700 - val_accuracy: 0.7372\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1802 - accuracy: 0.9462 - val_loss: 0.7953 - val_accuracy: 0.7839\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.1150 - accuracy: 0.9651 - val_loss: 0.8178 - val_accuracy: 0.8015\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0828 - accuracy: 0.9752 - val_loss: 0.8297 - val_accuracy: 0.7953\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0659 - accuracy: 0.9796 - val_loss: 0.7400 - val_accuracy: 0.8329\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0544 - accuracy: 0.9829 - val_loss: 0.8350 - val_accuracy: 0.8300\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0438 - accuracy: 0.9867 - val_loss: 0.8506 - val_accuracy: 0.8344\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0406 - accuracy: 0.9879 - val_loss: 0.8914 - val_accuracy: 0.8357\n",
"Epoch 9/10\n",
"1019/1019 - 6s - loss: 0.0387 - accuracy: 0.9884 - val_loss: 0.8949 - val_accuracy: 0.8410\n",
"Epoch 10/10\n",
"1019/1019 - 6s - loss: 0.0312 - accuracy: 0.9904 - val_loss: 0.9068 - val_accuracy: 0.8454\n",
"Zero-one loss: 0.1457378551787351\n",
"FW- components: 90\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.5080 - accuracy: 0.8416 - val_loss: 0.7913 - val_accuracy: 0.7591\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1627 - accuracy: 0.9520 - val_loss: 0.7948 - val_accuracy: 0.7869\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0948 - accuracy: 0.9742 - val_loss: 0.7662 - val_accuracy: 0.8137\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0640 - accuracy: 0.9823 - val_loss: 0.7883 - val_accuracy: 0.8290\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0502 - accuracy: 0.9860 - val_loss: 0.7893 - val_accuracy: 0.8356\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0395 - accuracy: 0.9891 - val_loss: 0.8706 - val_accuracy: 0.8399\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0400 - accuracy: 0.9881 - val_loss: 1.0676 - val_accuracy: 0.8155\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0282 - accuracy: 0.9915 - val_loss: 1.0146 - val_accuracy: 0.8299\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0238 - accuracy: 0.9928 - val_loss: 0.9587 - val_accuracy: 0.8548\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0224 - accuracy: 0.9929 - val_loss: 1.0540 - val_accuracy: 0.8471\n",
"Zero-one loss: 0.15627864344637946\n",
"FW- components: 110\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.4724 - accuracy: 0.8546 - val_loss: 0.8186 - val_accuracy: 0.7603\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1382 - accuracy: 0.9634 - val_loss: 0.7725 - val_accuracy: 0.8089\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0794 - accuracy: 0.9783 - val_loss: 0.8203 - val_accuracy: 0.8191\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0528 - accuracy: 0.9850 - val_loss: 0.9337 - val_accuracy: 0.8204\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0417 - accuracy: 0.9879 - val_loss: 0.9542 - val_accuracy: 0.8313\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0369 - accuracy: 0.9895 - val_loss: 0.9346 - val_accuracy: 0.8412\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0267 - accuracy: 0.9927 - val_loss: 1.0282 - val_accuracy: 0.8474\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0211 - accuracy: 0.9939 - val_loss: 1.1628 - val_accuracy: 0.8286\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0264 - accuracy: 0.9914 - val_loss: 1.1593 - val_accuracy: 0.8408\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0205 - accuracy: 0.9938 - val_loss: 1.2966 - val_accuracy: 0.8436\n",
"Zero-one loss: 0.14848762603116408\n",
"FW- components: 130\n",
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.148986). Check your callbacks.\n",
"1019/1019 - 5s - loss: 0.5150 - accuracy: 0.8395 - val_loss: 0.7711 - val_accuracy: 0.7811\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1556 - accuracy: 0.9550 - val_loss: 0.7043 - val_accuracy: 0.8064\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0860 - accuracy: 0.9749 - val_loss: 0.7319 - val_accuracy: 0.8285\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0547 - accuracy: 0.9850 - val_loss: 0.8580 - val_accuracy: 0.8292\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0448 - accuracy: 0.9874 - val_loss: 0.9114 - val_accuracy: 0.8353\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0326 - accuracy: 0.9913 - val_loss: 0.9489 - val_accuracy: 0.8368\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0302 - accuracy: 0.9910 - val_loss: 0.8936 - val_accuracy: 0.8608\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0265 - accuracy: 0.9921 - val_loss: 0.9696 - val_accuracy: 0.8584\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0264 - accuracy: 0.9920 - val_loss: 1.0818 - val_accuracy: 0.8422\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0166 - accuracy: 0.9955 - val_loss: 1.1559 - val_accuracy: 0.8453\n",
"Zero-one loss: 0.152153987167736\n",
"FW- components: 150\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.4667 - accuracy: 0.8549 - val_loss: 0.7300 - val_accuracy: 0.7691\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1365 - accuracy: 0.9635 - val_loss: 0.6678 - val_accuracy: 0.8116\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0762 - accuracy: 0.9800 - val_loss: 0.6308 - val_accuracy: 0.8370\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0458 - accuracy: 0.9884 - val_loss: 0.6961 - val_accuracy: 0.8396\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0426 - accuracy: 0.9883 - val_loss: 0.8004 - val_accuracy: 0.8357\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0267 - accuracy: 0.9929 - val_loss: 0.7318 - val_accuracy: 0.8495\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0267 - accuracy: 0.9921 - val_loss: 0.7954 - val_accuracy: 0.8433\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0232 - accuracy: 0.9931 - val_loss: 1.0402 - val_accuracy: 0.8232\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0190 - accuracy: 0.9945 - val_loss: 0.9076 - val_accuracy: 0.8549\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0184 - accuracy: 0.9949 - val_loss: 0.9122 - val_accuracy: 0.8505\n",
"Zero-one loss: 0.14115490375802017\n",
"FW- components: 170\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.5013 - accuracy: 0.8487 - val_loss: 0.7488 - val_accuracy: 0.7780\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1291 - accuracy: 0.9651 - val_loss: 0.7400 - val_accuracy: 0.8058\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0664 - accuracy: 0.9830 - val_loss: 0.6988 - val_accuracy: 0.8416\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0447 - accuracy: 0.9883 - val_loss: 0.7572 - val_accuracy: 0.8386\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0339 - accuracy: 0.9907 - val_loss: 0.8077 - val_accuracy: 0.8454\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0254 - accuracy: 0.9930 - val_loss: 0.7187 - val_accuracy: 0.8663\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0213 - accuracy: 0.9939 - val_loss: 0.7830 - val_accuracy: 0.8504\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0189 - accuracy: 0.9946 - val_loss: 0.7266 - val_accuracy: 0.8778\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0124 - accuracy: 0.9968 - val_loss: 0.8611 - val_accuracy: 0.8610\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0178 - accuracy: 0.9946 - val_loss: 0.8310 - val_accuracy: 0.8737\n",
"Zero-one loss: 0.12465627864344637\n",
"FW- components: 190\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.4545 - accuracy: 0.8607 - val_loss: 0.7529 - val_accuracy: 0.7865\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1264 - accuracy: 0.9652 - val_loss: 0.7090 - val_accuracy: 0.8212\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0705 - accuracy: 0.9815 - val_loss: 0.6724 - val_accuracy: 0.8435\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0461 - accuracy: 0.9876 - val_loss: 0.7778 - val_accuracy: 0.8344\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0383 - accuracy: 0.9895 - val_loss: 0.7378 - val_accuracy: 0.8549\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0264 - accuracy: 0.9932 - val_loss: 0.9976 - val_accuracy: 0.8267\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0244 - accuracy: 0.9929 - val_loss: 0.9187 - val_accuracy: 0.8483\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0181 - accuracy: 0.9950 - val_loss: 0.9842 - val_accuracy: 0.8478\n",
"Epoch 9/10\n",
"1019/1019 - 6s - loss: 0.0234 - accuracy: 0.9936 - val_loss: 0.9568 - val_accuracy: 0.8530\n",
"Epoch 10/10\n",
"1019/1019 - 6s - loss: 0.0140 - accuracy: 0.9960 - val_loss: 0.9279 - val_accuracy: 0.8657\n",
"Zero-one loss: 0.12557286892758937\n",
"FW- components: 210\n",
"Epoch 1/10\n",
"1019/1019 - 5s - loss: 0.4542 - accuracy: 0.8597 - val_loss: 0.7646 - val_accuracy: 0.7775\n",
"Epoch 2/10\n",
"1019/1019 - 5s - loss: 0.1189 - accuracy: 0.9685 - val_loss: 0.7023 - val_accuracy: 0.8039\n",
"Epoch 3/10\n",
"1019/1019 - 5s - loss: 0.0641 - accuracy: 0.9839 - val_loss: 0.7556 - val_accuracy: 0.8193\n",
"Epoch 4/10\n",
"1019/1019 - 5s - loss: 0.0412 - accuracy: 0.9896 - val_loss: 0.8243 - val_accuracy: 0.8222\n",
"Epoch 5/10\n",
"1019/1019 - 5s - loss: 0.0262 - accuracy: 0.9936 - val_loss: 0.7042 - val_accuracy: 0.8571\n",
"Epoch 6/10\n",
"1019/1019 - 5s - loss: 0.0262 - accuracy: 0.9922 - val_loss: 0.7838 - val_accuracy: 0.8453\n",
"Epoch 7/10\n",
"1019/1019 - 5s - loss: 0.0157 - accuracy: 0.9956 - val_loss: 0.8158 - val_accuracy: 0.8592\n",
"Epoch 8/10\n",
"1019/1019 - 5s - loss: 0.0245 - accuracy: 0.9926 - val_loss: 0.9040 - val_accuracy: 0.8639\n",
"Epoch 9/10\n",
"1019/1019 - 5s - loss: 0.0147 - accuracy: 0.9961 - val_loss: 0.9469 - val_accuracy: 0.8372\n",
"Epoch 10/10\n",
"1019/1019 - 5s - loss: 0.0174 - accuracy: 0.9947 - val_loss: 1.0241 - val_accuracy: 0.8486\n",
"Zero-one loss: 0.1457378551787351\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "kZIGTbP0EUl-",
"colab_type": "code",
"colab": {}
},
"source": [
"df = pd.DataFrame(\n",
"columns = ['epochs', 'valid', 'components', 'accuracy', 'value']\n",
")\n",
"\n",
"for itr in range(len(res)):\n",
" \n",
" time = [i for i in range(1,epochs+1)]\n",
" valids = [0 for i in range(1,epochs+1)]\n",
" components = [(itr+1)*20-10 for i in range(1,epochs+1)]\n",
" \n",
"\n",
" accur = [1 for i in range(1,epochs+1)]\n",
" acc = res[itr][0].history['accuracy']\n",
" \n",
" df1= pd.DataFrame(data= np.vstack((time,valids,components,accur,acc)).T, columns = ['epochs', 'valid', 'components', 'accuracy', 'value'])\n",
"\n",
" loss= res[itr][0].history['loss']\n",
" accur = [0 for i in range(1,epochs+1)]\n",
" df2= pd.DataFrame(data= np.vstack((time,valids,components,accur,loss)).T, columns = ['epochs', 'valid', 'components', 'accuracy', 'value'])\n",
"\n",
" valids = [1 for i in range(1,epochs+1)]\n",
" accur = [1 for i in range(1,epochs+1)]\n",
" val_acc = res[itr][0].history['val_accuracy']\n",
" \n",
" df3= pd.DataFrame(data= np.vstack((time,valids,components,accur,val_acc)).T, columns = ['epochs', 'valid', 'components', 'accuracy', 'value'])\n",
"\n",
" accur = [0 for i in range(1,epochs+1)]\n",
"\n",
" val_loss = res[itr][0].history['val_loss']\n",
" df4= pd.DataFrame(data= np.vstack((time,valids,components,accur,val_loss)).T, columns = ['epochs', 'valid', 'components', 'accuracy', 'value'])\n",
" \n",
" df = df.append(df1.append(df2).append(df3).append(df4))"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "ekgc7EAAEUwF",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "14e77fc7-eca6-48b8-8e6a-71ca0e4d1728"
},
"source": [
"df['components'] = df['components'].astype('category')\n",
"df = df.assign(accuracy = ['accuracy' if accuracy == 1. else 'loss' for accuracy in df['accuracy']])\n",
"df = df.assign(valid = ['validation' if valid == 1. else 'training' for valid in df['valid']])\n",
"df['accuracy'].unique()"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array(['accuracy', 'loss'], dtype=object)"
]
},
"metadata": {
"tags": []
},
"execution_count": 45
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "FSQbrnQMEUy0",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 504
},
"outputId": "0a9a0092-d80b-4d54-e785-aa24a661d724"
},
"source": [
"ggplot(df, aes(x='epochs', y='value',color='components')) + \\\n",
" geom_line() + \\\n",
" facet_wrap(['accuracy','valid'],scales='free') + theme_bw(base_size=12)"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAswAAAHVCAYAAADl4K3UAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAPYQAAD2EBqD+naQAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdd7gc1WH///ecmdm+e3tXu6DeEB0VhEQHmWYRxXEwdhIZ2ziuIcHG+ZJgkvixHSfGjgv8sE0I3WCaASEsEBJImKKCCur99rZ3++6U8/tj967uRQU1dIV0XnrmmbKzM2dWO3c/e+bMWU1KKVEURVEURVEUZb/EYBdAURRFURRFUU5kKjAriqIoiqIoykGowKwoiqIoiqIoB6ECs6IoiqIoiqIchArMiqIoiqIoinIQKjAriqIoiqIoykGowKwoiqIoiqIoB2EMdgEGWzQaJZVKDXYxFEU5BgKBAKWlpft9TJ3rinJyOdj5rijH2ikdmKPRKP/zP/+DbduDXRRFUY4BwzD4+7//+30+RNW5rignnwOd74rycTilA3MqlcK2bc4880xCodBgF0dRlKOQSCRYuXIlqVRqnw9Qda4rysnlYOe7onwcTunA3CcUCqkTTlFOAepcVxRFUY6EuulPURRFURRFUQ5CBWZFURRFURRFOQgVmBVFURRFURTlIFRgVhRFURRFUZSDUIFZOWU5joPruoNdDEVRjgN1viuKcjRULxnKcffCCy/w0ksv0dHRgdfrZcqUKcyfP59IJALAokWLeO6552hra8M0TWbOnMkXv/hFAHbv3s3//u//smnTJnK5HEOGDOH222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YVkWuVyO1atXFx/3+/3MmjWLe++9l6amJi6++OJj8VIpyieeOt8VRTlZqCYZynE1ZMgQbr75Zn7605+SyWQYPnw4s2bNYvPmzQBceeWVCCG4//77aW9vx+v1MnPmTCZOnEhZWRk/+MEPeOCBB/jiF7+I67rFu+YBbrrpJu655x7+7u/+jtLSUr7whS/w2muvHbQ8fr+fr33tazz66KPcf//91NbWct111/Huu+8W1znzzDO57bbbeOKJJ/jZz36GrutMnjy52K4R9l6mnT17NuFw+GN45RTlk0ed74qinCw02Xcd6hTU3NzMfffdx4UXXqjucFaOSiKR4POf/zx3330348ePH+zinJKi0ShLly7llltuob6+fsBj6lxXjiV1vg++g53vivJxUE0yFOUoOY7DU089RWNjo/rwVJSTnDrfFeXUpAKzohyFHTt28JnPfIbly5fz1a9+dbCLoyjKx0id74py6lKBWTlpPPHEE9x5552HvP66deuYN28ejuMc8T5HjBjB73//e37961/T2Nh4xNtRFCXvpz/9KT/5yU+K81/96ldZtGjRAddfuHAh8+fPP+r9zps3jzVr1hx0HXW+K8qpS930pwy6O+64g/Hjx3PTTTcd1XbmzZvHvHnzDnn9CRMm8MQTTxzVPhVF+Xj94he/OKbbW7RoEQ899BC/+93vBixXfwsURTkYVcOsnPAsyxrsIiiKoiiKcgpTNczKoPrlL3/J+vXr2bBhA8899xwAX/rSl3jooYe48cYbefrpp4nH4zz++OO88MILvPTSS3R0dOD1epkyZQrz588v/lTuI488wurVq/nhD38I5GuuGxsb6e3t5d133yUQCHDjjTdy9dVXA7BmzRq+973v8fTTT6PrevH5U6ZMYcGCBViWxfTp0/nyl7+MrusAbNq0iV//+tc0NTXR0NDAzJkz+e1vf1ssu6Kc6hYsWMAf/vAH7r33XjRNA/Jfev/mb/6GW2+9le3bt7N06VJ6enoIBoOcf/75fOELX8Dr9e53e/Pnz2fevHlcfvnlAKxYsYLf/e53tLW1MWrUKCZMmDBg/TfeeIOnnnqK1tZWhBCMGzeO+fPnU1tby7p16/jlL3+JbdvFq1G33nors2bN4tprr+X73/8+U6ZMAeCdd97hkUceoaWlhdLSUq644gquu+664g+hXHvttdxyyy0sWbKEHTt2UFNTw1e+8hV1I6CinKRUDbMyqG699VbGjx/Ppz/9aZ544oniZdGenh62b9/Oz3/+8+IPEpSVlfHd736XRx99lP/8z/+kubmZe++996DbX7RoEZdddhmPPPII8+fP57777jvor4dt2rQJn8/H/fffz49//GPefPPNYt+uiUSCu+66i/POO4+HHnqIb3/72yxYsOAYvRKKcnKYOXMm0Wi0+AMkAG+99RZCCM477zzq6+u5++67eeyxx/jXf/1X3nvvPR577LFD2nZrayv/9m//xpw5c3jkkUe46aabePHFFwes4/f7+frXv85DDz3Er371K6SUxTbREyZM4NZbb6W8vLz492bWrFn77Gfz5s384Ac/YO7cuTz88MPcdtttPPvsszz//PMD1lu4cCHf/OY3efTRR5k8efKAtteKopxcVGBWTlhf/OIX8fv9xZqnadOm0dDQgBCC6upq5s6dy6pVqw66jalTp3LGGWcghGDatGmEQiG2bt16wPUrKyu54YYbME2ThoYGJk+ezKZNm4B8jZOu68ybNw/TNBkyZAif+tSnjt0BK8pJIBAIMH36dBYuXFhctnDhQmbPno1hGMyePZuqqio0TWPYsGHMmTPnI8/jPkuWLGH48OFceeWVGIbBuHHjmD179oB1zj77bBobG9F1nUgkwmc/+1k2btxIKpU65GNYuHAh55xzDjNmzEDXdUaOHMkNN9ywzxfk66+/nvr6enRd54orrqCjo4Oenp5D3o+iKJ8cqkmGckIqLS3d5xLtsmXLeOaZZ2hpaSGXyyGlJJPJ4DhOscnEh1VUVAyY9/l8pNPpA+63vLz8gOt3d3dTWVlZvCQLUFNTc1jHpSingssvv5z/9//+H4lEgmQyyZo1a/jyl78M5JtsLFiwgI6ODhzHw
"text/plain": [
"<Figure size 640x480 with 4 Axes>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<ggplot: (8758028328796)>"
]
},
"metadata": {
"tags": []
},
"execution_count": 46
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "E7xC_l3SEU8I",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 504
},
"outputId": "43050193-0c47-4bbc-9709-8f42376f48fd"
},
"source": [
"ggplot(df, aes(x='epochs', y='value',color='components')) + \\\n",
" geom_line() + \\\n",
" facet_wrap(['accuracy','valid']) + \\\n",
" theme_bw(base_size=12)"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAswAAAHVCAYAAADl4K3UAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAPYQAAD2EBqD+naQAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdeZwcVb3//9c5VdXb9PTMJJlkshNkS4AYQIlhDYuEGNnEmyv8FOEaIvsFxS+IyiJeuYDcC6JieKCgsgsCIkuCLAICahS4gEJCIBBmskyS2Xup5ZzfH93TM5NlMiGTTJL5PHk0VXWquqpOZU7Pe06frlbWWosQQgghhBBig/RAn4AQQgghhBDbMwnMQgghhBBC9EICsxBCCCGEEL2QwCyEEEIIIUQvJDALIYQQQgjRCwnMQgghhBBC9EICsxBCCCGEEL1wB/oEBlJzczPZbHagT0MI0U9SqRTV1dUbXCftXYidR29tXYitYdAG5ubmZn7yk58QhuFAn4oQop+4rst555233i9Sae9C7Fw21taF2FoGbWDOZrOEYch+++1HOp0e6NMRQmyh9vZ2Xn31VbLZ7Hq/RKW9C7Hz6K2tC7G1DNrA3CmdTkuDE2KQkPYuhBDi45AP/QkhhBBCCNELCcxCCCGEEEL0QgKzEEIIIYQQvZDALIQQQgghRC8kMItBK4oijDEDfRpCiG1A2rsQYksM+rtkiG3vscce44knnqCxsZF4PM6UKVOYM2cOmUwGgKeffprf//73rFy5Es/zOOywwzjzzDMBWLZsGb/61a9YtGgRvu8zZswYLrnkEmpra5kzZw6zZ8/mmGOOKR/r+OOP5/vf/z5TpkzhjTfe4Dvf+Q4XX3wxd999N6tWreIXv/gFb731Fg8++CArVqxAa83EiROZM2cOdXV15f387W9/47777qO+vh6tNfvuuy+XXnop//M//4PjOPznf/5nedvFixdzySWX8Mtf/lLuyCAGPWnvQoidgQRmsc3V1NTw7W9/m5EjR7J69Wquu+465s2bx7e+9S0WLFjAr3/9ay6++GL23XdfCoUC7733HgBNTU1ceumlzJgxg2984xvE43Hee+894vH4Zh3/xRdf5LrrriOZTKK1JplMcsEFFzBu3Dg6Ojq46aabuOGGG7j++usBePXVV7n22mu58MILmTp1KtZa/vWvfwEwc+ZMLr/8cubMmUNFRQUA8+fPZ9q0afLLUwikvQshdg4yJENscwcddBCjR49Ga83w4cM5+eSTee211wD4/e9/z8knn8yUKVNwHIdUKsU+++wDwHPPPUdNTQ2nnXYaqVQKx3HYfffdyz1VfXXaaaeRyWTwPA/HcTjggAOYMGECjuOQyWQ49dRTeeedd8pfo/zoo49y9NFHc8ghh+B5HrFYjE9+8pMATJw4kVGjRvHcc88BxS/IeP755zn22GP76WoJsWOT9i6E2BlID7PY5l566SUefvhhli9fju/7WGvJ5/NEUcTKlSsZPXr0Bp/X27rNMWLEiB7Lb775Jvfeey/Lli0jn8+Xy1taWkilUqxcuZL9999/o/ubOXMmjz/+OLNmzeK5555j6NCh7Lvvvlt8nkLsDKS9CyF2BtLDLLapzrdkZ82axS9+8Qvuu+8+LrroovL64cOHU19fv8HnDh8+nIaGho3uO5lM9vgFuGbNmg1up3XXj30QBFx99dXsv//+3HLLLdx333388Ic/BMBaCxR/4W7snAAOP/xwVq1axdtvv838+fOlt0mIEmnvQoidhQRmsU3l83mMMWQyGWKxGA0NDTzwwAPl9ccddxy/+93veP3114miiGw2y5tvvgnAEUccwZo1a7jzzjvJZrNEUcTixYtpbW0FYLfdduP555+nvb2dbDbLr3/9602eTxiGFAoF0uk0qVSKNWvWcNddd/XY5rjjjuOpp57ipZdeIggCfN/n9ddfL69PJpNMnz6defPmUV9fz5FHHtkfl0qIHZ60dyHEzkKGZIhtasyYMZx22mnceOON5PN5xo8fz/Tp01m8eDEAxx57LFprbrvtNlatWkU8Huewww5jn332oaamhmuuuYY77riDM888E2NM+VPzAF/+8pe56aab+NrXvkZ1dTWnn346zz77bK/nk0wmOf/887nnnnu47bbbqKur44QTTmDhwoXlbfbbbz8uvvhi7r//fn784x/jOA6TJ08uj2uErrdpjzjiCCorK7fClRNixyPtXQixs1C2832oQaahoYFbb72VQw89VD7dLLZYe3s7X/3qV7n66quZNGnSQJ/OoNTc3MwLL7zA3LlzGTVqVI910t5Ff5L2PrB6a+tCbC0yJEOILRRFEQ8++CATJkyQX55C7OSkvQsxOElgFmILLF26lC996Uu8/PLLnHvuuQN9OkKIrUjauxCDlwRmsdO4//77ufzyy/u8/VtvvcXs2bOJouhjH3OXXXbht7/9LT//+c+ZMGHCx96PEAJuvPFGbrjhhvLyueeey9NPP73R7RcsWMCcOXO2+LizZ8/mjTfe2OR20t6FGLzkQ39iwF122WVMmjSJL3/5y1u0n9mzZzN79uw+b7/33ntz//33b9ExhRBbz09/+tN+3d/TTz/NnXfeye23396jXF4HhBCbIj3MYrsXBMFAn4IQQgghBjHpYRYD6mc/+xn//Oc/efvtt/n9738PwNe//nXuvPNOvvjFL/LQQw/R1tbGfffdx2OPPcYTTzxBY2Mj8XicKVOmMGfOnPJX5d599928/vrrXHvttUCx53rChAm0tLSwcOFCUqkUX/ziF/nc5z4HwBtvvMF3vvMdHnroIRzHKT9/ypQpPPnkkwRBwMEHH8xZZ52F4zgALFq0iJ///OfU19czevRoDjvsMH75y1+Wz12IwezJJ5/kd7/7HfPmzUMpBRT/4D3jjDM455xzeP/993nhhRdoamqioqKCqVOncvrppxOPxze4vzlz5jB79myOOeYYAP7xj39w++23s3LlSnbffXf23nvvHtu/+OKLPPjgg6xYsQKtNRMnTmTOnDnU1dXx1ltv8bOf/YwwDMvvRJ1zzjlMnz6d448/nu9///tMmTIFgL/97W/cfffdLF++nOrqambMmMEJJ5xQ/hKU448/nrlz5/L888+zdOlSRowYwdlnny0fAhRiJyY9zGJAnXPOOUyaNIkvfOEL3H///eW3Rpuamnj//fe5+eaby19IUFNTw7e//W3uuecefvSjH9HQ0MC8efN63f/TTz/NZz/7We6++27mzJnDrbfe2uu3hy1atIhEIsFtt93G9ddfz5///OfyvV3b29u56qqrOPDAA7nzzjv5xje+wZNPPtlPV0KIHd9hhx1Gc3Nz+ctHAF555RW01hx44IGMGjWKq6++mnvvvZcrr7ySv//979x777192veKFSv4wQ9+wKxZs7j77rv58pe/zOOPP95jm2QyyQUXXMCdd97JLbfcgrW2PCZ677335pxzzmHIkCHl15rp06evd5zFixdzzTXXcPLJJ3PXXXdx8cUX88gjj/Doo4/22G7BggVceOGF3HPPPUyePLnH2GshxM5HArPYbp155pkkk8ly79NBBx3E6NGj0VozfPhwTj75ZF577bVe9zFt2jQ++clPorXmoIMOIp1Os2TJko1uP2zYME466SQ8z2P06NFMnjyZRYsWAcVeJ8dxmD17Np7nMWbMGD7/+c/3X4WF2MGlUikOPvhgFixYUC5bsGABRxxxBK7rcsQRR1BbW4tSinHjxjFr1qxNtuFOzz//POPHj+fYY4/FdV0mTpzIEUcc0WObAw44gAkTJuA4DplMhlNPPZV33nmHbDbb5zosWLCAT33qUxxyyCE4jsNuu+3GSSedtN4fxyeeeCKjRo3CcRxmzJhBY2MjTU1NfT6OEGLHIkMyxHapurp6vbdpX3rpJR5++GGWL1+O7/tYa8nn80RRVB4ysa6hQ4f2WE4kEuRyuY0ed8iQIRvdfu3atQwbNqz8tizAiBEjNqteQuzsjjnmGL73ve/R3t5OR0cHb7zxBmeddRZQHLLx5JNP0tjYSBRFhGFYH
"text/plain": [
"<Figure size 640x480 with 4 Axes>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<ggplot: (-9223363278826112789)>"
]
},
"metadata": {
"tags": []
},
"execution_count": 47
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LyBlhJEEmfq_",
"colab_type": "text"
},
"source": [
"## Feed-Forward Zero-One Loss"
]
},
{
"cell_type": "code",
"metadata": {
"id": "yY9zTezLFQjo",
"colab_type": "code",
"colab": {}
},
"source": [
"df_loss = pd.DataFrame(\n",
"columns = ['components', 'zero_one']\n",
")\n",
"\n",
"losses =[]\n",
"\n",
"for i in range(len(res)):\n",
" losses.append(res[i][2])\n",
"components = [i for i in range(10,211,20)]"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "UMZyeh0zFR8n",
"colab_type": "code",
"colab": {}
},
"source": [
"df_loss = pd.DataFrame( data = [components,losses], index = ['components', 'zero_one']).T"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "rPvWBDt4FTWN",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 394
},
"outputId": "ba5c37bf-cc8e-4d08-f35a-16970c011046"
},
"source": [
"df_loss"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>components</th>\n",
" <th>zero_one</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>10.0</td>\n",
" <td>0.286893</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>30.0</td>\n",
" <td>0.197984</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>50.0</td>\n",
" <td>0.159028</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>70.0</td>\n",
" <td>0.145738</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>90.0</td>\n",
" <td>0.156279</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>110.0</td>\n",
" <td>0.148488</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>130.0</td>\n",
" <td>0.152154</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>150.0</td>\n",
" <td>0.141155</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>170.0</td>\n",
" <td>0.124656</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>190.0</td>\n",
" <td>0.125573</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>210.0</td>\n",
" <td>0.145738</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" components zero_one\n",
"0 10.0 0.286893\n",
"1 30.0 0.197984\n",
"2 50.0 0.159028\n",
"3 70.0 0.145738\n",
"4 90.0 0.156279\n",
"5 110.0 0.148488\n",
"6 130.0 0.152154\n",
"7 150.0 0.141155\n",
"8 170.0 0.124656\n",
"9 190.0 0.125573\n",
"10 210.0 0.145738"
]
},
"metadata": {
"tags": []
},
"execution_count": 50
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "rGwbQWP6FUOw",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 498
},
"outputId": "9f216196-38eb-4a5f-dc50-aca3fba25438"
},
"source": [
"ggplot(df_loss, aes(x='components', y='zero_one')) + \\\n",
" geom_line() + \\\n",
" geom_point() + \\\n",
" theme_bw(base_size=12) + ggtitle(\"Zero-one loss FW\") + ylab(\"loss\")"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkIAAAHPCAYAAAC/YbWbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAPYQAAD2EBqD+na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6Snp79U5hd59qhQ3tGedu3a6R+vX78+nJ2dERMTg7S0NCQkJKB27drw9PQslzxEUmIRIjIQmzZtwqxZs+Do6IjIyEhYW1s/d31vb2/Y2dnh6NGjhRaXl+Hn5wedTlfolYNjY2Oh1WrRpEmTEm0PQKGnbO7cuYMzZ87A0tIS9evXf+nMrVq1AgAcOHDgpbfxPM/bBwD6a+4U9e/i6emJoUOHYv/+/ahSpQp++eWXQtezs7NDUFAQvv76awwaNAi3b98utys4P/sx+piYGNjb26Nx48b51mnbti0OHDiAqKiofM8hkhsWISIDcPz4cQwePBgWFhbYvn073NzcXvgclUqFUaNGISUlBR999BEePnxYYJ2UlBT88ccfxc4xZMgQAMDkyZORnZ2tX56dnY1JkyYBAIYOHVrs7fXv3x/m5uZYunQp/vzzz3yPTZs2Dffu3UP//v0Lna9UXIMHD4adnR1mzJiB48ePF3hcp9MVa+5MUfz9/eHl5YWDBw9i69at+R7bunUrDhw4gHr16iEgIAAAkJycjKSkpALbyczMxOPHj2FlZaVftnfvXgghCqybd/qxcuXKL537efKOCEVHR2P//v3QaDRQKvP/OWjXrh3u37+PBQsWAGARIvniHCEiid2/fx/du3fHo0eP0Lx5c+zevRu7d+8ucv1nJyNPmzYNZ8+ex
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<ggplot: (-9223363278721333202)>"
]
},
"metadata": {
"tags": []
},
"execution_count": 51
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4DJIeuMIkUON",
"colab_type": "text"
},
"source": [
"# 1.4 Convolutional Neural Newtworks"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "XPAm0p36kVVh",
"colab_type": "text"
},
"source": [
"## One VGG block CNN\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "CHXZ0nRciBW2",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 732
},
"outputId": "d10bce0d-8fa6-4f43-c97a-6f6728eaa7e0"
},
"source": [
"\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu', input_shape = (32, 32, 3)),\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(128, activation = 'relu'),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
"\n",
"model.summary()"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_11\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d (Conv2D) (None, 32, 32, 32) 896 \n",
"_________________________________________________________________\n",
"conv2d_1 (Conv2D) (None, 32, 32, 32) 9248 \n",
"_________________________________________________________________\n",
"max_pooling2d (MaxPooling2D) (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"flatten (Flatten) (None, 8192) 0 \n",
"_________________________________________________________________\n",
"dense_22 (Dense) (None, 128) 1048704 \n",
"_________________________________________________________________\n",
"dense_23 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 1,060,138\n",
"Trainable params: 1,060,138\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n",
"Model: \"sequential_11\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d (Conv2D) (None, 32, 32, 32) 896 \n",
"_________________________________________________________________\n",
"conv2d_1 (Conv2D) (None, 32, 32, 32) 9248 \n",
"_________________________________________________________________\n",
"max_pooling2d (MaxPooling2D) (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"flatten (Flatten) (None, 8192) 0 \n",
"_________________________________________________________________\n",
"dense_22 (Dense) (None, 128) 1048704 \n",
"_________________________________________________________________\n",
"dense_23 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 1,060,138\n",
"Trainable params: 1,060,138\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "cwz11kP4iEnV",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 374
},
"outputId": "0a397b6b-86af-4ae0-f32b-8d0e6941d4c3"
},
"source": [
"history = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"1019/1019 - 12s - loss: 0.2258 - accuracy: 0.9251 - val_loss: 0.1457 - val_accuracy: 0.9591\n",
"Epoch 2/10\n",
"1019/1019 - 11s - loss: 0.0122 - accuracy: 0.9964 - val_loss: 0.1096 - val_accuracy: 0.9716\n",
"Epoch 3/10\n",
"1019/1019 - 11s - loss: 0.0083 - accuracy: 0.9981 - val_loss: 0.0620 - val_accuracy: 0.9841\n",
"Epoch 4/10\n",
"1019/1019 - 11s - loss: 0.0058 - accuracy: 0.9989 - val_loss: 0.1105 - val_accuracy: 0.9822\n",
"Epoch 5/10\n",
"1019/1019 - 11s - loss: 0.0071 - accuracy: 0.9986 - val_loss: 0.1179 - val_accuracy: 0.9836\n",
"Epoch 6/10\n",
"1019/1019 - 11s - loss: 0.0080 - accuracy: 0.9989 - val_loss: 0.1146 - val_accuracy: 0.9782\n",
"Epoch 7/10\n",
"1019/1019 - 11s - loss: 0.0039 - accuracy: 0.9994 - val_loss: 0.1395 - val_accuracy: 0.9790\n",
"Epoch 8/10\n",
"1019/1019 - 11s - loss: 0.0020 - accuracy: 0.9995 - val_loss: 0.1240 - val_accuracy: 0.9827\n",
"Epoch 9/10\n",
"1019/1019 - 11s - loss: 0.0045 - accuracy: 0.9995 - val_loss: 0.1455 - val_accuracy: 0.9733\n",
"Epoch 10/10\n",
"1019/1019 - 11s - loss: 0.0029 - accuracy: 0.9994 - val_loss: 0.1433 - val_accuracy: 0.9771\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "wva4Qa2uiGZH",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "90606185-813d-40de-81dc-058250c8da2f"
},
"source": [
"y_pred = model.predict(x_test)\n",
"\n",
"cnn_loss = [] \n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"cnn_loss.append(zol)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.02153987167736022\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "GG5q04ECiIUc",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 540
},
"outputId": "e4785a50-1e97-4640-c27d-d599680e60c2"
},
"source": [
"# plot a random sample of test images, their predicted labels, and ground truth\n",
"fig = plt.figure(figsize=(16, 9))\n",
"for i, idx in enumerate(np.random.choice(x_test.shape[0], size=16, replace=False)):\n",
" ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])\n",
" ax.imshow(np.squeeze(x_test[idx]))\n",
" pred_idx = np.argmax(y_pred[idx])\n",
" true_idx = np.argmax(y_test[idx])\n",
" ax.set_title(\"{} ({})\".format(TYPES[pred_idx], TYPES[true_idx]),\n",
" color=(\"green\" if pred_idx == true_idx else \"red\"))\n",
"\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzYAAAILCAYAAAA63AmGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOydd7gl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b9m3Ac9kLkJwMdN2ew80tR6E5YiGZW/bxibEZ8BiX76AVM2ByGZXrzGO75vakPIM2U0ZXaBSO+C5G3xOvH9AiSLbweOD2jxlwL4L1uyt/kXFG9/h/KHAe5DIi0d6WXJwL1Gqj+y50in3HcWeVXHMfg5zrAle8Yw1x7qOeinZLysQNIReDD9LMvjWPk/AIsAnGRLtjtde/KWUdwbAGDKphOJmmH5ELaPAzCmbOZbHYRnqGsOdNRgysYg8bfhzmnG25DIYY5BMtCahqTzZtLjvi+uALDAlE0gBje7AHhM2OyLRH5DyHhgOzrEcWzHdnRCBja2ZDebsvkKgB+Ysmkg0bPWkVQ+L7cl+9kRLnEHgG5TNp9Doj2sIXmgdluyd44xOxciWbtTt8OHmb4OyTTfGekz3GTK5kYko+NTkFR07Uim5mu2ZM8f4b4XAbgz1SPehGREfjiAx8cyULIlu8yUzZ1IpHpXyWk5UzZtSHTU7x7t9QgZhtGU2XeYJODHEiQBQq60JRuZ8kA/Al9OFxvvhmTt2UC41x8COMOUzbttyT6V6o1fbEv216PJWOoHjyNZX/C3EcxHU38cYsrmTUjW9n0MyYuYf4hrfNiUzbVIZmFPQ
"text/plain": [
"<Figure size 1152x648 with 16 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "kajPVWLGiKXn",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "6bbc10dd-f36a-4412-c125-612eecd03838"
},
"source": [
"#Loss and accuracy visualisation\n",
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history.history['accuracy']) \n",
"plt.plot(history.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history.history['loss']) \n",
"plt.plot(history.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzdeXxU1d348c93lqwEAmEnbCqguLELVdzQCrjbFtFqaze02l/tU+ujdtG2z2P1edrHWltra93a2oK70hZ3sdq6QEBUEAVUIGENSyALWWbm+/vj3EkmIcskzGQmyff9es1r7nLuvWduJvc755x7zhVVxRhjjImXL9UZMMYY07VY4DDGGNMuFjiMMca0iwUOY4wx7WKBwxhjTLtY4DDGGNMuFjiMaYWIPCQi/x1n2o0ickay82RMqlngMMYY0y4WOIzpAUQkkOo8mO7DAofp8rwqoutF5D0RqRSR+0VkkIg8KyLlIvKSiPSNSX+eiKwRkTIReVVEjopZN1FEVnrbPQJkNTnWOSKyytv2DRE5Ls48ni0i74jIfhEpFpEfN1l/kre/Mm/9Fd7ybBH5PxHZJCL7RORf3rJTRaSkmfNwhjf9YxF5XEQeFpH9wBUiMk1E3vSOsU1EfiMiGTHbHy0iL4rIHhHZISLfF5HBIlIlIgUx6SaJSKmIBOP57Kb7scBhuovPAWcCY4FzgWeB7wMDcN/zbwOIyFhgIfAdb90S4G8ikuFdRJ8G/gz0Ax7z9ou37UTgAeBKoAD4PbBYRDLjyF8l8CUgHzgb+KaIXODtd6SX3197eZoArPK2+wUwGfiMl6f/BCJxnpPzgce9Y/4FCAP/AfQHZgCzgKu9POQBLwHPAUOBI4CXVXU78CowL2a/lwOLVLUuznyYbsYCh+kufq2qO1R1C/A68LaqvqOq1cBTwEQv3cXAP1T1Re/C9wsgG3dh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SOeL9uY37RakMVQewv2rB3kXPVCgG279jLgj+sbXH/PoFemQF6ZwfJywrSOytAYd8cemdFlwXonRWkV1aA7KC/4aIfPPgCn9lMcAj4rbuQMd1Jsm/HXYgrOfT3no98C+4Ja6jq73C3087FjTJaBXzFW7dHRP6Lhqev/VRVo43sV9NwO+6z3quj+evopp1GVVm/o4KaULjFNL4mv0QDPh9+v/ul6/cJ1dlB/uv8o+uDgAsOXkDIDpKb4e8S58IYkx6SGjhU9ZI21itwTQvrHsA9i6Dp8iLgoD4h3VVFTYiaUJgBeZnkZATqqy18MYHC18ZFvywryOUTR3VOho0x3Z7VIaRIWVkZv/3tb9tMt6eyloDPx6DeWfTJDjLvovOpqaogM+An4Pe1GTSMMSbRLHCkSEuBIxQK1U/XhSPsrw6RnxOsDxBLliwhPz+/0/JpjDFNpbpxvMe68cYb+fjjj5kwYQLBYJCsrCz69u3Lhx9+yLp167jgggv4dNNmKqoO8N3vXMs137wKaBg+paKigjlz5nDSSSfxxhtvMGzYMJ555hmys7NT/MmMMd2dBQ7gJ39bwwdb9yd0n+OH9uaWc49ucf3tt9/O6tWrWbVqFa+++ipnn302q1evZvTo0QDcf//97KrLIFRTzcVnn8b8eV+goKCg0T7Wr1/PwoUL+cMf/sC8efN44oknuOyyyxL6OYwxpikLHGli2rRp9UED4P9++SueePJJgn4fxcXFrF+//qDAMXr0aCZMmADA5MmT2bhxY2dm2RjTQ1nggFZLBp0lNze3fvrVV1/lxZde4i+LX2TSYYM5/fTTmu3hnpmZWT/t9/s5cOBAp+TVGNOzWeN4iuTl5VFe3vxTOPfs3UtuXm+GFPRh3bqPeOuttzo5d8YY0zIrcaRIQUEBJ554IscccwzZ2dkMGjSoft0JJ88id
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "BoQoU4BZ6tUW",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "NPxdIIMiFuNo",
"colab_type": "text"
},
"source": [
"\n",
"## Two VGG blocks\n",
"\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "Eg1bEN-WFz8b",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 482
},
"outputId": "747bb61a-0bcf-48e9-817f-a0655534e483"
},
"source": [
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu', input_shape = (32, 32, 3)),\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(128, activation = 'relu'),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
"\n",
"model.summary()\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_12\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d_2 (Conv2D) (None, 32, 32, 32) 896 \n",
"_________________________________________________________________\n",
"conv2d_3 (Conv2D) (None, 32, 32, 32) 9248 \n",
"_________________________________________________________________\n",
"max_pooling2d_1 (MaxPooling2 (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"conv2d_4 (Conv2D) (None, 16, 16, 64) 18496 \n",
"_________________________________________________________________\n",
"conv2d_5 (Conv2D) (None, 16, 16, 64) 36928 \n",
"_________________________________________________________________\n",
"max_pooling2d_2 (MaxPooling2 (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"flatten_1 (Flatten) (None, 4096) 0 \n",
"_________________________________________________________________\n",
"dense_24 (Dense) (None, 128) 524416 \n",
"_________________________________________________________________\n",
"dense_25 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 591,274\n",
"Trainable params: 591,274\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "vDTNqcq_t43S",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 392
},
"outputId": "1e99e209-4b95-4b30-f1b6-9e180972565b"
},
"source": [
"history2 = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2\n",
"\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.210605). Check your callbacks.\n",
"1019/1019 - 14s - loss: 0.2516 - accuracy: 0.9158 - val_loss: 0.1399 - val_accuracy: 0.9559\n",
"Epoch 2/10\n",
"1019/1019 - 13s - loss: 0.0240 - accuracy: 0.9931 - val_loss: 0.0467 - val_accuracy: 0.9812\n",
"Epoch 3/10\n",
"1019/1019 - 13s - loss: 0.0077 - accuracy: 0.9973 - val_loss: 0.0338 - val_accuracy: 0.9900\n",
"Epoch 4/10\n",
"1019/1019 - 13s - loss: 3.4333e-05 - accuracy: 1.0000 - val_loss: 0.0311 - val_accuracy: 0.9900\n",
"Epoch 5/10\n",
"1019/1019 - 13s - loss: 1.1592e-05 - accuracy: 1.0000 - val_loss: 0.0367 - val_accuracy: 0.9900\n",
"Epoch 6/10\n",
"1019/1019 - 13s - loss: 5.8665e-06 - accuracy: 1.0000 - val_loss: 0.0342 - val_accuracy: 0.9903\n",
"Epoch 7/10\n",
"1019/1019 - 13s - loss: 2.9794e-06 - accuracy: 1.0000 - val_loss: 0.0304 - val_accuracy: 0.9903\n",
"Epoch 8/10\n",
"1019/1019 - 13s - loss: 1.6845e-06 - accuracy: 1.0000 - val_loss: 0.0328 - val_accuracy: 0.9906\n",
"Epoch 9/10\n",
"1019/1019 - 13s - loss: 9.3372e-07 - accuracy: 1.0000 - val_loss: 0.0308 - val_accuracy: 0.9905\n",
"Epoch 10/10\n",
"1019/1019 - 14s - loss: 5.2326e-07 - accuracy: 1.0000 - val_loss: 0.0337 - val_accuracy: 0.9907\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "tQgAdE38uDae",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "614a589a-a58d-4df1-8e8c-9593c4c7789f"
},
"source": [
"# evaluate zero-one loss\n",
"y_pred = model.predict(x_test)\n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"\n",
"cnn_loss.append(zol)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.00916590284142988\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "8yLD8Y1wF8KK",
"colab_type": "text"
},
"source": [
"## Three VGG blocks"
]
},
{
"cell_type": "code",
"metadata": {
"id": "wEwt6F37F4_D",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 589
},
"outputId": "5860601b-ab4d-43ab-8a5a-5dfb6ece43ad"
},
"source": [
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu', input_shape = (32, 32, 3)),\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(128, activation = 'relu'),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
"\n",
"model.summary()\n",
"\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_13\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d_6 (Conv2D) (None, 32, 32, 32) 896 \n",
"_________________________________________________________________\n",
"conv2d_7 (Conv2D) (None, 32, 32, 32) 9248 \n",
"_________________________________________________________________\n",
"max_pooling2d_3 (MaxPooling2 (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"conv2d_8 (Conv2D) (None, 16, 16, 64) 18496 \n",
"_________________________________________________________________\n",
"conv2d_9 (Conv2D) (None, 16, 16, 64) 36928 \n",
"_________________________________________________________________\n",
"max_pooling2d_4 (MaxPooling2 (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_10 (Conv2D) (None, 8, 8, 128) 73856 \n",
"_________________________________________________________________\n",
"conv2d_11 (Conv2D) (None, 8, 8, 128) 147584 \n",
"_________________________________________________________________\n",
"max_pooling2d_5 (MaxPooling2 (None, 4, 4, 128) 0 \n",
"_________________________________________________________________\n",
"flatten_2 (Flatten) (None, 2048) 0 \n",
"_________________________________________________________________\n",
"dense_26 (Dense) (None, 128) 262272 \n",
"_________________________________________________________________\n",
"dense_27 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 550,570\n",
"Trainable params: 550,570\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "OAywgc-Gt7EC",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 374
},
"outputId": "d7593dd0-543e-4417-e0e4-1e0be19ba341"
},
"source": [
"history3 = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2 \n",
"\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"1019/1019 - 19s - loss: 0.3207 - accuracy: 0.8886 - val_loss: 0.0736 - val_accuracy: 0.9760\n",
"Epoch 2/10\n",
"1019/1019 - 18s - loss: 0.0340 - accuracy: 0.9895 - val_loss: 0.2608 - val_accuracy: 0.9379\n",
"Epoch 3/10\n",
"1019/1019 - 18s - loss: 0.0234 - accuracy: 0.9932 - val_loss: 0.0518 - val_accuracy: 0.9861\n",
"Epoch 4/10\n",
"1019/1019 - 18s - loss: 8.6958e-05 - accuracy: 1.0000 - val_loss: 0.0193 - val_accuracy: 0.9917\n",
"Epoch 5/10\n",
"1019/1019 - 18s - loss: 9.9077e-06 - accuracy: 1.0000 - val_loss: 0.0171 - val_accuracy: 0.9928\n",
"Epoch 6/10\n",
"1019/1019 - 18s - loss: 4.4342e-06 - accuracy: 1.0000 - val_loss: 0.0164 - val_accuracy: 0.9925\n",
"Epoch 7/10\n",
"1019/1019 - 18s - loss: 2.2970e-06 - accuracy: 1.0000 - val_loss: 0.0168 - val_accuracy: 0.9925\n",
"Epoch 8/10\n",
"1019/1019 - 18s - loss: 1.2628e-06 - accuracy: 1.0000 - val_loss: 0.0164 - val_accuracy: 0.9932\n",
"Epoch 9/10\n",
"1019/1019 - 18s - loss: 6.9922e-07 - accuracy: 1.0000 - val_loss: 0.0156 - val_accuracy: 0.9940\n",
"Epoch 10/10\n",
"1019/1019 - 18s - loss: 3.8787e-07 - accuracy: 1.0000 - val_loss: 0.0166 - val_accuracy: 0.9938\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "I8inLgtsuGdz",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "83821c38-f6d0-4bb9-eaa8-53df6ae416b8"
},
"source": [
"# evaluate zero-one loss\n",
"y_pred = model.predict(x_test)\n",
"\n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"\n",
"cnn_loss.append(zol)\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.00916590284142988\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "pRX7_710GB43",
"colab_type": "text"
},
"source": [
"## Three VGG blocks with Dropout\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "78uoa45HGGHK",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 732
},
"outputId": "b292579e-dfa9-4d19-8787-2a25edd23832"
},
"source": [
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu', input_shape = (32, 32, 3)),\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.2),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.2),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", activation='relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.2),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(128, activation = 'relu'),\n",
" tf.keras.layers.Dropout(0.2),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
"\n",
"\n",
"model.summary()\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_14\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d_12 (Conv2D) (None, 32, 32, 32) 896 \n",
"_________________________________________________________________\n",
"conv2d_13 (Conv2D) (None, 32, 32, 32) 9248 \n",
"_________________________________________________________________\n",
"max_pooling2d_6 (MaxPooling2 (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"dropout (Dropout) (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"conv2d_14 (Conv2D) (None, 16, 16, 64) 18496 \n",
"_________________________________________________________________\n",
"conv2d_15 (Conv2D) (None, 16, 16, 64) 36928 \n",
"_________________________________________________________________\n",
"max_pooling2d_7 (MaxPooling2 (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"dropout_1 (Dropout) (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_16 (Conv2D) (None, 8, 8, 128) 73856 \n",
"_________________________________________________________________\n",
"conv2d_17 (Conv2D) (None, 8, 8, 128) 147584 \n",
"_________________________________________________________________\n",
"max_pooling2d_8 (MaxPooling2 (None, 4, 4, 128) 0 \n",
"_________________________________________________________________\n",
"dropout_2 (Dropout) (None, 4, 4, 128) 0 \n",
"_________________________________________________________________\n",
"flatten_3 (Flatten) (None, 2048) 0 \n",
"_________________________________________________________________\n",
"dense_28 (Dense) (None, 128) 262272 \n",
"_________________________________________________________________\n",
"dropout_3 (Dropout) (None, 128) 0 \n",
"_________________________________________________________________\n",
"dense_29 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 550,570\n",
"Trainable params: 550,570\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "TEQPF4Hmt9JA",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 392
},
"outputId": "ccd411fe-3171-43d6-9d56-8eeb97a599ec"
},
"source": [
"history4 = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.151422). Check your callbacks.\n",
"1019/1019 - 20s - loss: 0.4977 - accuracy: 0.8243 - val_loss: 0.1280 - val_accuracy: 0.9546\n",
"Epoch 2/10\n",
"1019/1019 - 19s - loss: 0.0688 - accuracy: 0.9775 - val_loss: 0.1614 - val_accuracy: 0.9452\n",
"Epoch 3/10\n",
"1019/1019 - 19s - loss: 0.0458 - accuracy: 0.9857 - val_loss: 0.0644 - val_accuracy: 0.9795\n",
"Epoch 4/10\n",
"1019/1019 - 19s - loss: 0.0364 - accuracy: 0.9886 - val_loss: 0.0873 - val_accuracy: 0.9727\n",
"Epoch 5/10\n",
"1019/1019 - 19s - loss: 0.0243 - accuracy: 0.9931 - val_loss: 0.1079 - val_accuracy: 0.9783\n",
"Epoch 6/10\n",
"1019/1019 - 19s - loss: 0.0328 - accuracy: 0.9902 - val_loss: 0.0799 - val_accuracy: 0.9782\n",
"Epoch 7/10\n",
"1019/1019 - 20s - loss: 0.0262 - accuracy: 0.9922 - val_loss: 0.2361 - val_accuracy: 0.9506\n",
"Epoch 8/10\n",
"1019/1019 - 19s - loss: 0.0189 - accuracy: 0.9949 - val_loss: 0.1377 - val_accuracy: 0.9713\n",
"Epoch 9/10\n",
"1019/1019 - 19s - loss: 0.0246 - accuracy: 0.9928 - val_loss: 0.0759 - val_accuracy: 0.9793\n",
"Epoch 10/10\n",
"1019/1019 - 19s - loss: 0.0190 - accuracy: 0.9952 - val_loss: 0.3236 - val_accuracy: 0.9211\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "hq0aCW3iuIJV",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "44cd30ee-ed2c-44ed-d3b0-7a31cb5de5b8"
},
"source": [
"# evaluate zero-one loss\n",
"y_pred = model.predict(x_test)\n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"\n",
"cnn_loss.append(zol)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.07561869844179651\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zKK0HS_eGLZy",
"colab_type": "text"
},
"source": [
"## Three VGG blocks with Dropout and Batch Normalization\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "fpUsbm4dGLmF",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "1a2d68e2-2727-4805-fdd7-96b2aa58957c"
},
"source": [
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", use_bias=False, input_shape = (32, 32, 3)),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.Conv2D(32, (3, 3), padding = \"same\", use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.2),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.Conv2D(64, (3, 3), padding = \"same\", use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.3),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.Conv2D(128, (3, 3), padding = \"same\", use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.MaxPooling2D(pool_size = (2, 2)),\n",
" tf.keras.layers.Dropout(0.4),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(128, use_bias=False),\n",
" tf.keras.layers.BatchNormalization(),\n",
" tf.keras.layers.Activation('relu'),\n",
" tf.keras.layers.Dropout(0.5),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = \"adam\", loss='categorical_crossentropy', metrics=['accuracy'])\n",
"\n",
"model.summary()\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_15\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d_18 (Conv2D) (None, 32, 32, 32) 864 \n",
"_________________________________________________________________\n",
"batch_normalization (BatchNo (None, 32, 32, 32) 128 \n",
"_________________________________________________________________\n",
"activation (Activation) (None, 32, 32, 32) 0 \n",
"_________________________________________________________________\n",
"conv2d_19 (Conv2D) (None, 32, 32, 32) 9216 \n",
"_________________________________________________________________\n",
"batch_normalization_1 (Batch (None, 32, 32, 32) 128 \n",
"_________________________________________________________________\n",
"activation_1 (Activation) (None, 32, 32, 32) 0 \n",
"_________________________________________________________________\n",
"max_pooling2d_9 (MaxPooling2 (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"dropout_4 (Dropout) (None, 16, 16, 32) 0 \n",
"_________________________________________________________________\n",
"conv2d_20 (Conv2D) (None, 16, 16, 64) 18432 \n",
"_________________________________________________________________\n",
"batch_normalization_2 (Batch (None, 16, 16, 64) 256 \n",
"_________________________________________________________________\n",
"activation_2 (Activation) (None, 16, 16, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_21 (Conv2D) (None, 16, 16, 64) 36864 \n",
"_________________________________________________________________\n",
"batch_normalization_3 (Batch (None, 16, 16, 64) 256 \n",
"_________________________________________________________________\n",
"activation_3 (Activation) (None, 16, 16, 64) 0 \n",
"_________________________________________________________________\n",
"max_pooling2d_10 (MaxPooling (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"dropout_5 (Dropout) (None, 8, 8, 64) 0 \n",
"_________________________________________________________________\n",
"conv2d_22 (Conv2D) (None, 8, 8, 128) 73728 \n",
"_________________________________________________________________\n",
"batch_normalization_4 (Batch (None, 8, 8, 128) 512 \n",
"_________________________________________________________________\n",
"activation_4 (Activation) (None, 8, 8, 128) 0 \n",
"_________________________________________________________________\n",
"conv2d_23 (Conv2D) (None, 8, 8, 128) 147456 \n",
"_________________________________________________________________\n",
"batch_normalization_5 (Batch (None, 8, 8, 128) 512 \n",
"_________________________________________________________________\n",
"activation_5 (Activation) (None, 8, 8, 128) 0 \n",
"_________________________________________________________________\n",
"max_pooling2d_11 (MaxPooling (None, 4, 4, 128) 0 \n",
"_________________________________________________________________\n",
"dropout_6 (Dropout) (None, 4, 4, 128) 0 \n",
"_________________________________________________________________\n",
"flatten_4 (Flatten) (None, 2048) 0 \n",
"_________________________________________________________________\n",
"dense_30 (Dense) (None, 128) 262144 \n",
"_________________________________________________________________\n",
"batch_normalization_6 (Batch (None, 128) 512 \n",
"_________________________________________________________________\n",
"activation_6 (Activation) (None, 128) 0 \n",
"_________________________________________________________________\n",
"dropout_7 (Dropout) (None, 128) 0 \n",
"_________________________________________________________________\n",
"dense_31 (Dense) (None, 10) 1290 \n",
"=================================================================\n",
"Total params: 552,298\n",
"Trainable params: 551,146\n",
"Non-trainable params: 1,152\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "5fCia4UgWeLD",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "L99mDAP9t-T1",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 374
},
"outputId": "f75668b9-9120-4db3-aa16-b9b8cdadf17a"
},
"source": [
"history5 = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"1019/1019 - 22s - loss: 0.3911 - accuracy: 0.8740 - val_loss: 0.1592 - val_accuracy: 0.9462\n",
"Epoch 2/10\n",
"1019/1019 - 21s - loss: 0.0870 - accuracy: 0.9735 - val_loss: 0.0608 - val_accuracy: 0.9725\n",
"Epoch 3/10\n",
"1019/1019 - 21s - loss: 0.0421 - accuracy: 0.9875 - val_loss: 0.0188 - val_accuracy: 0.9944\n",
"Epoch 4/10\n",
"1019/1019 - 21s - loss: 0.0428 - accuracy: 0.9876 - val_loss: 0.0137 - val_accuracy: 0.9958\n",
"Epoch 5/10\n",
"1019/1019 - 21s - loss: 0.0259 - accuracy: 0.9927 - val_loss: 0.0061 - val_accuracy: 0.9978\n",
"Epoch 6/10\n",
"1019/1019 - 22s - loss: 0.0252 - accuracy: 0.9924 - val_loss: 0.0168 - val_accuracy: 0.9929\n",
"Epoch 7/10\n",
"1019/1019 - 21s - loss: 0.0234 - accuracy: 0.9928 - val_loss: 0.0430 - val_accuracy: 0.9826\n",
"Epoch 8/10\n",
"1019/1019 - 21s - loss: 0.0239 - accuracy: 0.9925 - val_loss: 0.0387 - val_accuracy: 0.9829\n",
"Epoch 9/10\n",
"1019/1019 - 21s - loss: 0.0169 - accuracy: 0.9948 - val_loss: 0.0207 - val_accuracy: 0.9916\n",
"Epoch 10/10\n",
"1019/1019 - 21s - loss: 0.0140 - accuracy: 0.9956 - val_loss: 0.0163 - val_accuracy: 0.9936\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "MqZKRNxuuKbI",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "7440c448-0d61-4b33-e3fa-a089164dd253"
},
"source": [
"# evaluate zero-one loss\n",
"y_pred = model.predict(x_test)\n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"\n",
"cnn_loss.append(zol)\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.005957836846929423\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Gp8Gq3QYl2--",
"colab_type": "text"
},
"source": [
"## VGG CNN results"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "nasekeAkl8Lw",
"colab_type": "text"
},
"source": [
"**One VGG block**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "u4nDL4ikucM0",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "fdffd0b1-f5e9-4b69-f75b-00b4e0a7116a"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history.history['accuracy']) \n",
"plt.plot(history.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history.history['loss']) \n",
"plt.plot(history.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()\n",
"\n",
"\n",
"\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/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v/ul6/cJ1dlB/uv8o+uDgAsOXkDIDpKb4e8S58IYkx6SGjhU9ZI21itwTQvrHsA9i6Dp8iLgoD4h3VVFTYiaUJgBeZnkZATqqy18MYHC18ZFvywryOUTR3VOho0x3Z7VIaRIWVkZv/3tb9tMt6eyloDPx6DeWfTJDjLvovOpqaogM+An4Pe1GTSMMSbRLHCkSEuBIxQK1U/XhSPsrw6RnxOsDxBLliwhPz+/0/JpjDFNpbpxvMe68cYb+fjjj5kwYQLBYJCsrCz69u3Lhx9+yLp167jgggv4dNNmKqoO8N3vXMs137wKaBg+paKigjlz5nDSSSfxxhtvMGzYMJ555hmys7NT/MmMMd2dBQ7gJ39bwwdb9yd0n+OH9uaWc49ucf3tt9/O6tWrWbVqFa+++ipnn302q1evZvTo0QDcf//97KrLIFRTzcVnn8b8eV+goKCg0T7Wr1/PwoUL+cMf/sC8efN44oknuOyyyxL6OYwxpikLHGli2rRp9UED4P9++SueePJJgn4fxcXFrF+//qDAMXr0aCZMmADA5MmT2bhxY2dm2RjTQ1nggFZLBp0lNze3fvrVV1/lxZde4i+LX2TSYYM5/fTTmu3hnpmZWT/t9/s5cOBAp+TVGNOzWeN4iuTl5VFe3vxTOPfs3UtuXm+GFPRh3bqPeOuttzo5d8YY0zIrcaRIQUEBJ554IscccwzZ2dkMGjSoft0JJ88id
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "Exhe_XRUmHOZ",
"colab_type": "text"
},
"source": [
"**Two VGG block**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "7o6favwguecD",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "880218d6-c9e9-4826-afd0-a687cd27416e"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history2.history['accuracy']) \n",
"plt.plot(history2.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history2.history['loss']) \n",
"plt.plot(history2.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEWCAYAAABxMXBSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de3gU5dn48e+9m92cISQBFAKEIqKoCAU5eKqIVjxrPSse2r7FvtXW9lWqtmpbf6+tfdtaa6tWq9QDilo80YqKKB5aRQREBTmqQBLOCYEcSDbZ3L8/ZhI2IYdN2M1skvtzXXtldmaemXsnydw7zzPzPKKqGGOMMdHyeR2AMcaYrsUShzHGmHaxxGGMMaZdLHEYY4xpF0scxhhj2sUShzHGmHaxxGFMK0TkMRH53yjX3SAip8Q7JmO8ZonDGGNMu1jiMKYHEJEkr2Mw3YclDtPluVVEM0TkUxGpEJFHRaS/iLwqImUiskBE+kSsf46IrBSRUhF5W0QOj1g2RkSWueWeBVKa7OssEVnuln1fREZFGeOZIvKxiOwRkQIR+WWT5ce72yt1l1/jzk8VkT+IyEYR2S0i/3bnnSQihc0ch1Pc6V+KyBwRmSUie4BrRGS8iHzg7mOLiPxFRIIR5Y8QkTdEpEREtonIz0TkIBGpFJGciPW+LiI7RCQQzWc33Y8lDtNdXACcChwKnA28CvwM6Ivzd/4jABE5FJgN/NhdNg/4p4gE3ZPoS8CTQDbwD3e7uGXHADOBa4Ec4CFgrogkRxFfBX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"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "uO42DrCnmJ7o",
"colab_type": "text"
},
"source": [
"**Three VGG block**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "ENoCopkvufEv",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "d5b9cb2e-7217-43eb-8636-908d0dd3e692"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history3.history['accuracy']) \n",
"plt.plot(history3.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history3.history['loss']) \n",
"plt.plot(history3.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deXhU5dn48e89k8keQkgATQIEERVEBUUEl4prwQ211qVCtfYt7U9t9a21amu1te1b+7b1dWlrtZW64oZaqaIiCtZWRAFRQVAWWcIaAtn35P79cU6SSZgkk2QmJ8ncn+uaa86c7blzkpx7zvOc8zyiqhhjjDGt+bwOwBhjTO9kCcIYY0xIliCMMcaEZAnCGGNMSJYgjDHGhGQJwhhjTEiWIIwBRORREflVmOtuFpEzox2TMV6zBGGM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Pie7BRuLYKira2TALBiaCuMmhlgQE5kJEHh54Jg/IgYySkDoG4xDZO5PEQ5777AuCzdg5jIi1mEsQv/rmGz3aURHSfY7MHcOf5R7a7zt13383q1atZtWoVS5Ys4dxzz2X16tVNt6POmTOHQYMGsa2giNNOnsIJp59DVlYmAPF+ITUhjq1fbuSRx55gwvi/cs2sb7DmP28ya9ZM/D5pUd1TvTeeO84fE9GfsU2qThXQ/s2hk0DpjpbrB5Kdk/6gQ2DU6TBopJMQMvJg4HDnW7sxpleJmQTRW0yaNKnFswr3338/L730EtV1DezeuYO4st0cMW4kcT5heGYKZWXKyJEjOe3ESQCcMOl4tudv7Zk7g+pq3KuAzQcmgf2boaas5
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "aVPavynHmM_q",
"colab_type": "text"
},
"source": [
"**Three VGG block with Dropout**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "XQGGTd7nufZ5",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "27cc9afc-37bb-4681-e535-4d33400d0a52"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history4.history['accuracy']) \n",
"plt.plot(history4.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history4.history['loss']) \n",
"plt.plot(history4.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICA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aEqJbDpJCfjokxpoapLZ2TqtpyOPmpOTfDsU6IlQkEXy+8SLLd6RdH89/gbnifTDjaVYfc76hnBTwRZ5BN1YmFc1FnZeYd9mAVnfXCA2FpC7OoJvrU8wiey05Kaj+iF90yIK94Bb5r1uLPCzUgMxbdYREa/Q9JOd1v76u6Mu1Jh4Qs3fdW0Dfp+0auKImE7ykeRP7GYs0/30+ARh2lYXCrOhpJrC7dUUbK+iYFtV0/SWslpXONXuXnuxTyDdayuObC7JTg0wKCvY1D7fsonFm9dG80tGShJ9UgP4Y3DSMJEle0fqWWl2PsnElyWIGCspKeGZZ57hhz/84W5td/rpp/PMM8+QnZ29R+8bagizqayGgm3VFG6vomC7ey7c5pLAprIaIi+i9/uEQdlBhuSkcfjefclISXKFt9cO3Fzgt5yXGtF2nmhNDcaYzrEEEWMlJSXcf//9OySIUChEUtLOv/6ZM2fucr+qSqjBtYPXNbjeHNur6rj0kbkUbK9iY0lNi7ZsERjYJ0h+ThpH7JPLkJw08nNSGdLXPe/VJ2hNFMaYFixBxNitt97KmjVrGDt2LIFAgGAwSE5ODitWrGDlypWcc845FBQUUFNTww033MDUqVMBN3TInHmfUlJaxjmTz+SwiUcyf+5c+u81kHsfexZfcgqtx9Fq7CM9bkgOkw9OJT8njSE5aQzpm8rArNT22+RVYfUsWPk2pOdB5kDoM6j5OTXHZZreRBU0spnN+/zS6tn0DrUVUFoAJevdIzUHDpjSY38HvSZB/Pr1p
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "7R_fSnGNmUqm",
"colab_type": "text"
},
"source": [
"**Three VGG block with Dropout and Batch Normalization**"
]
},
{
"cell_type": "code",
"metadata": {
"id": "-7wTMgylufmv",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "a25c02ff-7370-41e2-c141-d544d53d3a72"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history5.history['accuracy']) \n",
"plt.plot(history5.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history5.history['loss']) \n",
"plt.plot(history5.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzde3xU9Zn48c8zl8zknpBAIAQhICp4KSjeirQoXvBee9HW2q22W2y1W7vbutXdXrbd7a77a9dtbSveSq9W29Xa2lYrqKBWRA2Iyk25CCQBkhBIyG2SzMzz++OcJJMwIRMyw+TyvF+vec2Zc5tnDuE85/v9nvP9iqpijDHG9OVJdwDGGGOGJ0sQxhhj4rIEYYwxJi5LEMYYY+KyBGGMMSYuSxDGGGPisgRhDCAiPxeR/0hw3Z0icmGqYzIm3SxBGGOMicsShDGjiIj40h2DGT0sQZgRw63auV1E3hKRFhH5qYiUiMjTItIkIs+KSGHM+leJyEYRaRCRVSIyK2bZXBFZ5273WyDY57uuEJH17rarReS0BGO8XETeEJFDIlIpIv/WZ/l57v4a3OU3uvMzReR/RGSXiDSKyN/ceQtFpCrOcbjQnf43EXlMRH4tIoeAG0XkLBF5xf2OvSLyYxHJiNn+ZBFZISIHRKRGRP5FRCaKSKuIFMWsd7qI1ImIP5HfbkYfSxBmpPkIc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C5AUTCcPGJ5wSQ+1GyCuDxf8Np3/K+YMc5iJRpb65nb3uFX7Nodj3tu4SQKgz2ms7ESjOCTApP8jUoizOnj6OiflBJroJYFJ+J
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ACRJH30KmYcR",
"colab_type": "text"
},
"source": [
"## VGG Zero-One Loss"
]
},
{
"cell_type": "code",
"metadata": {
"id": "BXTkF0GpY-tS",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 106
},
"outputId": "93c29f81-f9c2-49ae-ebc5-4ee5bcddd79d"
},
"source": [
"cnn_loss"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[0.02153987167736022,\n",
" 0.00916590284142988,\n",
" 0.00916590284142988,\n",
" 0.07561869844179651,\n",
" 0.005957836846929423]"
]
},
"metadata": {
"tags": []
},
"execution_count": 75
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "pyTo4qloNAnp",
"colab_type": "code",
"colab": {}
},
"source": [
"df_cnn_loss = pd.DataFrame(\n",
"columns = ['type', 'zero_one']\n",
")\n",
"\n",
"types = [\"1VGG\",\"2VGG\",\"3VGG\",\"3VGG-drop\", \"3VGG-drop-norm\"]\n",
"df_cnn_loss = pd.DataFrame( data = [types,cnn_loss], index = ['types', 'zero_one']).T"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "DCVd9nicVyDy",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"outputId": "baee1afb-af6a-476c-d35a-4e49f3e513a1"
},
"source": [
"df_cnn_loss"
],
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>types</th>\n",
" <th>zero_one</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1VGG</td>\n",
" <td>0.0215399</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2VGG</td>\n",
" <td>0.0091659</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3VGG</td>\n",
" <td>0.0091659</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>3VGG-drop</td>\n",
" <td>0.0756187</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>3VGG-drop-norm</td>\n",
" <td>0.00595784</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" types zero_one\n",
"0 1VGG 0.0215399\n",
"1 2VGG 0.0091659\n",
"2 3VGG 0.0091659\n",
"3 3VGG-drop 0.0756187\n",
"4 3VGG-drop-norm 0.00595784"
]
},
"metadata": {
"tags": []
},
"execution_count": 77
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "7W7HR2H_Vz9u",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 498
},
"outputId": "ba53bf43-4ce4-44df-8db0-efbabf8f7124"
},
"source": [
"ggplot(df_cnn_loss, aes(x='types', y='zero_one',group=1)) + \\\n",
" geom_point() + \\\n",
" geom_line() + \\\n",
" theme_bw(base_size=12) + ggtitle(\"Zero-one loss CNN\") + ylab(\"loss\")\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsoAAAHPCAYAAABKs/xuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAPYQAAD2EBqD+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HkymjZtqrZu4cKFMDMzw44dO5CZmamx7dKlS1GlShW1DJ6enlAqlbh69apq+fbt2/HixQvMnTsXzZs3V9tHixYt8Omnn+LGjRu4c+dOvnO/6eLFi7h37x46dOgAT09PtXXu7u7o1KkT7t+/rzFG18jISGNfOjo6qFy5stoyXV1d6OnpabStVq3ae7MlJSWphqLUqlXrve3fJTAwEObm5pg3b57WITHFtS1RacWb+YiISqH09HS4uLjg6dOnmDFjhkZxluevv/5CUlISGjVqhAULFmhtY2RkhLt372os//jjj7V+DX/9+nXo6OigW7duGuu6du0KqVSKGzduqJadPn1aNbY5T7169VRT2OUNeXByctLYX+XKldGqVSucPXsW9+7dw8cff6y2vm3bthrb1K5dGwCQnJysWpY3lOHmzZta5z/Ou4Ht7t27GoV0frzrHPKWnz9/Hjdu3ECXLl3QvHlzfPLJJ9i1axcePXoEFxcXdOrUCW3btoW+vr7atp6enpg2bRqaN2+OESNGoGvXrnB0dET16tULnLOwqlevDn9/f8ycORMLFy7EsmXLSmRbotKKhTIRUSkjCAK8vLxw/fp1uLq6YuHChW9tm5iYCCD3JrO5c+e+tV1aWprGMisrK61tX758iSpVqmgUdEDulc9q1aohPj5etez06dMax+7atauqUM67umhtba31eHnLtY1TtrCw0JoBABQKhWpZXj9s3LhR6zHyaOuH/CjoOUilUpw8eRLz5s1DWFgY/Pz8AABmZmbw8vLC4sWLVVfrv/rqK1SrVg3BwcH47rvv8O2330IikaBr165Yvny51g8Lb8r7WWVlZSE2Nha2trYfdI55vvzyS6xduxbfffcdJk2aVGLbEpVGHHpBRFTKBAYGIiwsDC1btkRISIjGDBdvqlSpEgBg8ODBEAThrf/FxMRobPu2/VaqVAlJSUlab8rKycnB8+fPVTf9AUBQUJDG8d68wpyXMS4uTuvxnj59qtbuQ+Rte/PmzXf2w9tubMzv/gtyDpUrV8Y333yDx48fIyoqCps2bULTpk2xZs0a+Pj4qG0/atQoXL58GYmJiTh8+DDGjRuHs2fPok+fPkhISHhnNl1dXdX8xRERER90fm8yNDTEggULkJmZiZkzZ5bYtkSlEQtlIqJSZPfu3Zg/fz4sLS1x6NCh985g0LRpU1hYWODy5ctFNttAq1atoFQqcfbsWY11Z8+ehUKhQOvWrQu0PwAawzOA3Cuwv//+OwwNDdGsWbMPzpxXKJ47d+6D9/Eu7zoHADh16hQAvLVfGjZsiHHjxuHMmTMwNTXFwYMHtbazsLBAv379sHHjRowePRpJSUlafw7/5e3tDQBYsWIF0tPT39lW21jw/5LL5WjVqhV27dqlNhY8PwqzLVFpw0KZiKiUuHLlCsaMGQN9fX3s378fdevWfe82urq6+Pzzz/H06VNMmTIFGRkZGm2ePn1aoJvYxo4dCwCYMWOGWtGVnp4Of39/AMC4cePyvT+ZTAY9PT2sXr0af//9t9q6gIAApKSkQCaTvXXasvwYM2YMLCwsMHfuXFy5ckVjvVKpfGuRmx+Ojo5o0qQJzp8/j7CwMLV1YWFhOHfuHBo3bqx6VHNMTAyio6M19pOcnIzMzEy1m/xOnToFQRA02uYNb/nvdIDajBw5En369EFUVJRqbPt/ZWVl4fvvv8/Xw2okEglWrFgBQRAwY8aM97Yvqm2JShuOUSYiKgVSU1NVM1zY29vj+PHjOH78+
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {
"tags": []
}
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<ggplot: (8757990059065)>"
]
},
"metadata": {
"tags": []
},
"execution_count": 78
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3_kbZU_nNC_i",
"colab_type": "text"
},
"source": [
"# 1.5 LeNet Neural Networks\n"
]
},
{
"cell_type": "code",
"metadata": {
"id": "rpN3eUW2NFME",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 446
},
"outputId": "7118b9e2-674a-4061-d739-3c7d70a696d4"
},
"source": [
"\n",
"input_shape = (32,32,3)\n",
"num_classes = 10\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Conv2D(6, kernel_size=(5, 5), strides=(1, 1), activation='tanh', input_shape=input_shape, padding=\"same\"),\n",
" tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(2, 2), padding='valid'),\n",
" tf.keras.layers.Conv2D(16, kernel_size=(5, 5), strides=(1, 1), activation='tanh', padding='valid'),\n",
" tf.keras.layers.AveragePooling2D(pool_size=(2, 2), strides=(2, 2), padding='valid'),\n",
" tf.keras.layers.Flatten(),\n",
" tf.keras.layers.Dense(120, activation = 'tanh'),\n",
" tf.keras.layers.Dense(84, activation = 'tanh'),\n",
" tf.keras.layers.Dense(10, activation = 'softmax')\n",
"])\n",
"\n",
"model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])\n",
"\n",
"model.summary()\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"sequential_16\"\n",
"_________________________________________________________________\n",
"Layer (type) Output Shape Param # \n",
"=================================================================\n",
"conv2d_24 (Conv2D) (None, 32, 32, 6) 456 \n",
"_________________________________________________________________\n",
"average_pooling2d (AveragePo (None, 16, 16, 6) 0 \n",
"_________________________________________________________________\n",
"conv2d_25 (Conv2D) (None, 12, 12, 16) 2416 \n",
"_________________________________________________________________\n",
"average_pooling2d_1 (Average (None, 6, 6, 16) 0 \n",
"_________________________________________________________________\n",
"flatten_5 (Flatten) (None, 576) 0 \n",
"_________________________________________________________________\n",
"dense_32 (Dense) (None, 120) 69240 \n",
"_________________________________________________________________\n",
"dense_33 (Dense) (None, 84) 10164 \n",
"_________________________________________________________________\n",
"dense_34 (Dense) (None, 10) 850 \n",
"=================================================================\n",
"Total params: 83,126\n",
"Trainable params: 83,126\n",
"Non-trainable params: 0\n",
"_________________________________________________________________\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "9-1JbKMPNK8V",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 392
},
"outputId": "25e7c6af-33c0-4469-ed1f-960b015c7db8"
},
"source": [
"history = model.fit(x_train, y_train,\n",
" batch_size = 32,\n",
" epochs = 10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose = 2\n",
"\n",
" )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Epoch 1/10\n",
"WARNING:tensorflow:Method (on_train_batch_end) is slow compared to the batch update (0.219765). Check your callbacks.\n",
"1019/1019 - 8s - loss: 0.3274 - accuracy: 0.9028 - val_loss: 0.1608 - val_accuracy: 0.9496\n",
"Epoch 2/10\n",
"1019/1019 - 7s - loss: 0.0138 - accuracy: 0.9977 - val_loss: 0.0819 - val_accuracy: 0.9768\n",
"Epoch 3/10\n",
"1019/1019 - 9s - loss: 0.0014 - accuracy: 1.0000 - val_loss: 0.0839 - val_accuracy: 0.9735\n",
"Epoch 4/10\n",
"1019/1019 - 7s - loss: 6.4137e-04 - accuracy: 1.0000 - val_loss: 0.0796 - val_accuracy: 0.9779\n",
"Epoch 5/10\n",
"1019/1019 - 7s - loss: 3.2755e-04 - accuracy: 1.0000 - val_loss: 0.0749 - val_accuracy: 0.9799\n",
"Epoch 6/10\n",
"1019/1019 - 7s - loss: 1.7176e-04 - accuracy: 1.0000 - val_loss: 0.0822 - val_accuracy: 0.9790\n",
"Epoch 7/10\n",
"1019/1019 - 7s - loss: 9.9440e-05 - accuracy: 1.0000 - val_loss: 0.0775 - val_accuracy: 0.9815\n",
"Epoch 8/10\n",
"1019/1019 - 8s - loss: 5.2685e-05 - accuracy: 1.0000 - val_loss: 0.0819 - val_accuracy: 0.9813\n",
"Epoch 9/10\n",
"1019/1019 - 7s - loss: 2.9746e-05 - accuracy: 1.0000 - val_loss: 0.0737 - val_accuracy: 0.9812\n",
"Epoch 10/10\n",
"1019/1019 - 7s - loss: 1.6986e-05 - accuracy: 1.0000 - val_loss: 0.0801 - val_accuracy: 0.9822\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "brru_mIGNPQs",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 540
},
"outputId": "6cd8216f-5c82-4dea-cf91-06a13d35e9ab"
},
"source": [
"y_pred = model.predict(x_test)\n",
"\n",
"# plot a random sample of test images, their predicted labels, and ground truth\n",
"fig = plt.figure(figsize=(16, 9))\n",
"for i, idx in enumerate(np.random.choice(x_test.shape[0], size=16, replace=False)):\n",
" ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])\n",
" ax.imshow(np.squeeze(x_test[idx]))\n",
" pred_idx = np.argmax(y_pred[idx])\n",
" true_idx = np.argmax(y_test[idx])\n",
" ax.set_title(\"{} ({})\".format(TYPES[pred_idx], TYPES[true_idx]),\n",
" color=(\"green\" if pred_idx == true_idx else \"red\"))"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzYAAAILCAYAAAA63AmGAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOydd5wlRbXHf9V906Td2cgGYJecJEkQnwqK6SGu4DMDIhgI7yEqBgzg5aIg+uApBtRnxAAiogiCTwEBQZAsOcMCu8DGyXNDh3p/dE+fc2rmzs4syy6XOd/Phw91b59bXT1bp6ur63dOGWstFEVRFEVRFEVRWhlvUzdAURRFURRFURTlhaITG0VRFEVRFEVRWh6d2CiKoiiKoiiK0vLoxEZRFEVRFEVRlJZHJzaKoiiKoiiKorQ8OrFRFEVRFEVRFKXlmdITG1Mxc0zFPGQqpm0jn3czUzEPmoopbszzKkqrYSrmH6Zi9tzU7VgfTMWcYyrm+E3dDkV5MVEfVRTCVMxppmJ+tanbwTEVc6ypmG9Nwv46UzEffTHbtI7z32oqZpf1/X1uQzZmfTAVsxTAZgAiAEMA/gzgBFu2gxvh9J8H8HNbttW0LdcB2A9ACKAG4O8A/suW7XMb8qS2bFeYirkWwDEAvrMh61YUADAV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SQuSIObr0Yim7nAPc74LYDPm4p5I5L07J9AMvDctJ7XU0fyRqs9bR9n5HpGuAXJm6zPmYo5B8BrkMQH7MNsDgAgVoAVZR2oj45/PeqjyibBlm2fqZgvA/heGj7xVyTS0DcBeIMt28+to4pbAQyYijkZSaxMA8kDfJst29sm2ZxfIHmhHtjx00xfi
"text/plain": [
"<Figure size 1152x648 with 16 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "iNZWDHS1NQ8e",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "aef36399-f0b9-49f2-bf8c-c602f9260e37"
},
"source": [
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history.history['accuracy']) \n",
"plt.plot(history.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history.history['loss']) \n",
"plt.plot(history.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()\n",
"\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deXxU9bn48c8zk0kmCdkIi5KAoKIFUUECYl2qohXcl6po9afe3qLV3trWetVel9Ze7/W2va21Wq1bq1VRxKXU4i5ovW4ERAVRQYsmYTUh+555fn+cEzJJJmGSzOQkM8/79ZrXnPme7clJ8n3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wCVRAB8TkvxP3ctcwXm+UIm9epTMLecaeJUBZpub6U0fNyGoqyEu9a8YeVadvAf4/jDrEEkQhq3I758jLsSeghJRSC5lpoqoamGmh035uqnUrAHwB/mvOekgb+1LCyVEhJdcvCX4GwiiWOVKG5LroKfleZ+7m5+x12naRlQ3ouBHMhPQ9GjQHxO8cEdfatoY532j93LXOnQ6HdLBcCpWMeXbbfdbn2UVNUO/bT77J+bA9x/h5S0py/hZRU9z2t4+8kI7N7Wad1eisLhm3T/dxpP+1l8bkaYQlikO2saybQpWM+MwCq0NLQpWKvjlzRRyyr6Xh1GqIpRvypHYmlUyLpKdn0UOZPhZb6zpV+eMUf6mWYWF/AqdzT85zKPnscjD2go9JvL0/P61wWzAG//Z0mM/vtDyKnY74WRmelWeN0JC2NUFUKVSXOq3Z750q8a2Xf/jmaU/RAhvNtOC0Lgu571h5OWfvntKwuy7jTvpSOSwJtLc4lgrZm9zJCl9eus
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "IEEV1PwvbP2i",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "f2af12fd-f064-4a64-80e6-02ebbf67629d"
},
"source": [
"y_pred = model.predict(x_test)\n",
"zol = zero_one(y_pred, y_test)\n",
"\n",
"print(\"Zero-one Loss: \", zol)\n",
"\n",
"cnn_loss.append(zol)"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.016498625114573784\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "0q1HqrTfODxB",
"colab_type": "text"
},
"source": [
"# 1.6 MobileNetV2"
]
},
{
"cell_type": "code",
"metadata": {
"id": "FfRYQkCGODjZ",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"outputId": "f6f4805e-9e5f-4ce3-b879-5999cc961a7c"
},
"source": [
"\n",
"model = MobileNetV2(input_shape=(32, 32, 3), alpha=1, weights=None,classes=10)\n",
"model.compile(loss='categorical_crossentropy', \n",
" optimizer='adam',\n",
" metrics=['accuracy'])\n",
"print(model.summary())\n",
"print('Compiled!')\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Model: \"mobilenetv2_1.00_32\"\n",
"__________________________________________________________________________________________________\n",
"Layer (type) Output Shape Param # Connected to \n",
"==================================================================================================\n",
"input_12 (InputLayer) (None, 32, 32, 3) 0 \n",
"__________________________________________________________________________________________________\n",
"Conv1_pad (ZeroPadding2D) (None, 33, 33, 3) 0 input_12[0][0] \n",
"__________________________________________________________________________________________________\n",
"Conv1 (Conv2D) (None, 16, 16, 32) 864 Conv1_pad[0][0] \n",
"__________________________________________________________________________________________________\n",
"bn_Conv1 (BatchNormalization) (None, 16, 16, 32) 128 Conv1[0][0] \n",
"__________________________________________________________________________________________________\n",
"Conv1_relu (ReLU) (None, 16, 16, 32) 0 bn_Conv1[0][0] \n",
"__________________________________________________________________________________________________\n",
"expanded_conv_depthwise (Depthw (None, 16, 16, 32) 288 Conv1_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"expanded_conv_depthwise_BN (Bat (None, 16, 16, 32) 128 expanded_conv_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"expanded_conv_depthwise_relu (R (None, 16, 16, 32) 0 expanded_conv_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"expanded_conv_project (Conv2D) (None, 16, 16, 16) 512 expanded_conv_depthwise_relu[0][0\n",
"__________________________________________________________________________________________________\n",
"expanded_conv_project_BN (Batch (None, 16, 16, 16) 64 expanded_conv_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_expand (Conv2D) (None, 16, 16, 96) 1536 expanded_conv_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_expand_BN (BatchNormali (None, 16, 16, 96) 384 block_1_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_expand_relu (ReLU) (None, 16, 16, 96) 0 block_1_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_pad (ZeroPadding2D) (None, 17, 17, 96) 0 block_1_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_depthwise (DepthwiseCon (None, 8, 8, 96) 864 block_1_pad[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_depthwise_BN (BatchNorm (None, 8, 8, 96) 384 block_1_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_depthwise_relu (ReLU) (None, 8, 8, 96) 0 block_1_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_project (Conv2D) (None, 8, 8, 24) 2304 block_1_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_1_project_BN (BatchNormal (None, 8, 8, 24) 96 block_1_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_expand (Conv2D) (None, 8, 8, 144) 3456 block_1_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_expand_BN (BatchNormali (None, 8, 8, 144) 576 block_2_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_expand_relu (ReLU) (None, 8, 8, 144) 0 block_2_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_depthwise (DepthwiseCon (None, 8, 8, 144) 1296 block_2_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_depthwise_BN (BatchNorm (None, 8, 8, 144) 576 block_2_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_depthwise_relu (ReLU) (None, 8, 8, 144) 0 block_2_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_project (Conv2D) (None, 8, 8, 24) 3456 block_2_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_project_BN (BatchNormal (None, 8, 8, 24) 96 block_2_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_2_add (Add) (None, 8, 8, 24) 0 block_1_project_BN[0][0] \n",
" block_2_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_expand (Conv2D) (None, 8, 8, 144) 3456 block_2_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_expand_BN (BatchNormali (None, 8, 8, 144) 576 block_3_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_expand_relu (ReLU) (None, 8, 8, 144) 0 block_3_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_pad (ZeroPadding2D) (None, 9, 9, 144) 0 block_3_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_depthwise (DepthwiseCon (None, 4, 4, 144) 1296 block_3_pad[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_depthwise_BN (BatchNorm (None, 4, 4, 144) 576 block_3_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_depthwise_relu (ReLU) (None, 4, 4, 144) 0 block_3_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_project (Conv2D) (None, 4, 4, 32) 4608 block_3_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_3_project_BN (BatchNormal (None, 4, 4, 32) 128 block_3_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_expand (Conv2D) (None, 4, 4, 192) 6144 block_3_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_expand_BN (BatchNormali (None, 4, 4, 192) 768 block_4_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_expand_relu (ReLU) (None, 4, 4, 192) 0 block_4_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_depthwise (DepthwiseCon (None, 4, 4, 192) 1728 block_4_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_depthwise_BN (BatchNorm (None, 4, 4, 192) 768 block_4_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_depthwise_relu (ReLU) (None, 4, 4, 192) 0 block_4_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_project (Conv2D) (None, 4, 4, 32) 6144 block_4_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_project_BN (BatchNormal (None, 4, 4, 32) 128 block_4_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_4_add (Add) (None, 4, 4, 32) 0 block_3_project_BN[0][0] \n",
" block_4_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_expand (Conv2D) (None, 4, 4, 192) 6144 block_4_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_expand_BN (BatchNormali (None, 4, 4, 192) 768 block_5_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_expand_relu (ReLU) (None, 4, 4, 192) 0 block_5_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_depthwise (DepthwiseCon (None, 4, 4, 192) 1728 block_5_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_depthwise_BN (BatchNorm (None, 4, 4, 192) 768 block_5_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_depthwise_relu (ReLU) (None, 4, 4, 192) 0 block_5_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_project (Conv2D) (None, 4, 4, 32) 6144 block_5_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_project_BN (BatchNormal (None, 4, 4, 32) 128 block_5_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_5_add (Add) (None, 4, 4, 32) 0 block_4_add[0][0] \n",
" block_5_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_expand (Conv2D) (None, 4, 4, 192) 6144 block_5_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_expand_BN (BatchNormali (None, 4, 4, 192) 768 block_6_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_expand_relu (ReLU) (None, 4, 4, 192) 0 block_6_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_pad (ZeroPadding2D) (None, 5, 5, 192) 0 block_6_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_depthwise (DepthwiseCon (None, 2, 2, 192) 1728 block_6_pad[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_depthwise_BN (BatchNorm (None, 2, 2, 192) 768 block_6_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_depthwise_relu (ReLU) (None, 2, 2, 192) 0 block_6_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_project (Conv2D) (None, 2, 2, 64) 12288 block_6_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_6_project_BN (BatchNormal (None, 2, 2, 64) 256 block_6_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_expand (Conv2D) (None, 2, 2, 384) 24576 block_6_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_expand_BN (BatchNormali (None, 2, 2, 384) 1536 block_7_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_expand_relu (ReLU) (None, 2, 2, 384) 0 block_7_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_depthwise (DepthwiseCon (None, 2, 2, 384) 3456 block_7_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_depthwise_BN (BatchNorm (None, 2, 2, 384) 1536 block_7_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_depthwise_relu (ReLU) (None, 2, 2, 384) 0 block_7_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_project (Conv2D) (None, 2, 2, 64) 24576 block_7_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_project_BN (BatchNormal (None, 2, 2, 64) 256 block_7_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_7_add (Add) (None, 2, 2, 64) 0 block_6_project_BN[0][0] \n",
" block_7_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_expand (Conv2D) (None, 2, 2, 384) 24576 block_7_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_expand_BN (BatchNormali (None, 2, 2, 384) 1536 block_8_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_expand_relu (ReLU) (None, 2, 2, 384) 0 block_8_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_depthwise (DepthwiseCon (None, 2, 2, 384) 3456 block_8_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_depthwise_BN (BatchNorm (None, 2, 2, 384) 1536 block_8_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_depthwise_relu (ReLU) (None, 2, 2, 384) 0 block_8_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_project (Conv2D) (None, 2, 2, 64) 24576 block_8_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_project_BN (BatchNormal (None, 2, 2, 64) 256 block_8_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_8_add (Add) (None, 2, 2, 64) 0 block_7_add[0][0] \n",
" block_8_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_expand (Conv2D) (None, 2, 2, 384) 24576 block_8_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_expand_BN (BatchNormali (None, 2, 2, 384) 1536 block_9_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_expand_relu (ReLU) (None, 2, 2, 384) 0 block_9_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_depthwise (DepthwiseCon (None, 2, 2, 384) 3456 block_9_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_depthwise_BN (BatchNorm (None, 2, 2, 384) 1536 block_9_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_depthwise_relu (ReLU) (None, 2, 2, 384) 0 block_9_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_project (Conv2D) (None, 2, 2, 64) 24576 block_9_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_project_BN (BatchNormal (None, 2, 2, 64) 256 block_9_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_9_add (Add) (None, 2, 2, 64) 0 block_8_add[0][0] \n",
" block_9_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_expand (Conv2D) (None, 2, 2, 384) 24576 block_9_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_expand_BN (BatchNormal (None, 2, 2, 384) 1536 block_10_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_expand_relu (ReLU) (None, 2, 2, 384) 0 block_10_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_depthwise (DepthwiseCo (None, 2, 2, 384) 3456 block_10_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_depthwise_BN (BatchNor (None, 2, 2, 384) 1536 block_10_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_depthwise_relu (ReLU) (None, 2, 2, 384) 0 block_10_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_project (Conv2D) (None, 2, 2, 96) 36864 block_10_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_10_project_BN (BatchNorma (None, 2, 2, 96) 384 block_10_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_expand (Conv2D) (None, 2, 2, 576) 55296 block_10_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_expand_BN (BatchNormal (None, 2, 2, 576) 2304 block_11_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_expand_relu (ReLU) (None, 2, 2, 576) 0 block_11_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_depthwise (DepthwiseCo (None, 2, 2, 576) 5184 block_11_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_depthwise_BN (BatchNor (None, 2, 2, 576) 2304 block_11_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_depthwise_relu (ReLU) (None, 2, 2, 576) 0 block_11_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_project (Conv2D) (None, 2, 2, 96) 55296 block_11_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_project_BN (BatchNorma (None, 2, 2, 96) 384 block_11_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_11_add (Add) (None, 2, 2, 96) 0 block_10_project_BN[0][0] \n",
" block_11_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_expand (Conv2D) (None, 2, 2, 576) 55296 block_11_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_expand_BN (BatchNormal (None, 2, 2, 576) 2304 block_12_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_expand_relu (ReLU) (None, 2, 2, 576) 0 block_12_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_depthwise (DepthwiseCo (None, 2, 2, 576) 5184 block_12_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_depthwise_BN (BatchNor (None, 2, 2, 576) 2304 block_12_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_depthwise_relu (ReLU) (None, 2, 2, 576) 0 block_12_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_project (Conv2D) (None, 2, 2, 96) 55296 block_12_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_project_BN (BatchNorma (None, 2, 2, 96) 384 block_12_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_12_add (Add) (None, 2, 2, 96) 0 block_11_add[0][0] \n",
" block_12_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_expand (Conv2D) (None, 2, 2, 576) 55296 block_12_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_expand_BN (BatchNormal (None, 2, 2, 576) 2304 block_13_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_expand_relu (ReLU) (None, 2, 2, 576) 0 block_13_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_pad (ZeroPadding2D) (None, 3, 3, 576) 0 block_13_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_depthwise (DepthwiseCo (None, 1, 1, 576) 5184 block_13_pad[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_depthwise_BN (BatchNor (None, 1, 1, 576) 2304 block_13_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_depthwise_relu (ReLU) (None, 1, 1, 576) 0 block_13_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_project (Conv2D) (None, 1, 1, 160) 92160 block_13_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_13_project_BN (BatchNorma (None, 1, 1, 160) 640 block_13_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_expand (Conv2D) (None, 1, 1, 960) 153600 block_13_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_expand_BN (BatchNormal (None, 1, 1, 960) 3840 block_14_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_expand_relu (ReLU) (None, 1, 1, 960) 0 block_14_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_depthwise (DepthwiseCo (None, 1, 1, 960) 8640 block_14_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_depthwise_BN (BatchNor (None, 1, 1, 960) 3840 block_14_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_depthwise_relu (ReLU) (None, 1, 1, 960) 0 block_14_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_project (Conv2D) (None, 1, 1, 160) 153600 block_14_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_project_BN (BatchNorma (None, 1, 1, 160) 640 block_14_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_14_add (Add) (None, 1, 1, 160) 0 block_13_project_BN[0][0] \n",
" block_14_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_expand (Conv2D) (None, 1, 1, 960) 153600 block_14_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_expand_BN (BatchNormal (None, 1, 1, 960) 3840 block_15_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_expand_relu (ReLU) (None, 1, 1, 960) 0 block_15_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_depthwise (DepthwiseCo (None, 1, 1, 960) 8640 block_15_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_depthwise_BN (BatchNor (None, 1, 1, 960) 3840 block_15_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_depthwise_relu (ReLU) (None, 1, 1, 960) 0 block_15_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_project (Conv2D) (None, 1, 1, 160) 153600 block_15_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_project_BN (BatchNorma (None, 1, 1, 160) 640 block_15_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_15_add (Add) (None, 1, 1, 160) 0 block_14_add[0][0] \n",
" block_15_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_expand (Conv2D) (None, 1, 1, 960) 153600 block_15_add[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_expand_BN (BatchNormal (None, 1, 1, 960) 3840 block_16_expand[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_expand_relu (ReLU) (None, 1, 1, 960) 0 block_16_expand_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_depthwise (DepthwiseCo (None, 1, 1, 960) 8640 block_16_expand_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_depthwise_BN (BatchNor (None, 1, 1, 960) 3840 block_16_depthwise[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_depthwise_relu (ReLU) (None, 1, 1, 960) 0 block_16_depthwise_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_project (Conv2D) (None, 1, 1, 320) 307200 block_16_depthwise_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"block_16_project_BN (BatchNorma (None, 1, 1, 320) 1280 block_16_project[0][0] \n",
"__________________________________________________________________________________________________\n",
"Conv_1 (Conv2D) (None, 1, 1, 1280) 409600 block_16_project_BN[0][0] \n",
"__________________________________________________________________________________________________\n",
"Conv_1_bn (BatchNormalization) (None, 1, 1, 1280) 5120 Conv_1[0][0] \n",
"__________________________________________________________________________________________________\n",
"out_relu (ReLU) (None, 1, 1, 1280) 0 Conv_1_bn[0][0] \n",
"__________________________________________________________________________________________________\n",
"global_average_pooling2d_1 (Glo (None, 1280) 0 out_relu[0][0] \n",
"__________________________________________________________________________________________________\n",
"Logits (Dense) (None, 10) 12810 global_average_pooling2d_1[0][0] \n",
"==================================================================================================\n",
"Total params: 2,270,794\n",
"Trainable params: 2,236,682\n",
"Non-trainable params: 34,112\n",
"__________________________________________________________________________________________________\n",
"None\n",
"Compiled!\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "nh3LDJGzOJiG",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 392
},
"outputId": "8f23828f-5230-40f5-9df6-0dff6163bb94"
},
"source": [
"history = model.fit(x_train,y_train,\n",
" batch_size = 32,\n",
" epochs=10,\n",
" validation_data=(x_valid, y_valid),\n",
" verbose=2 )"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Train on 32607 samples, validate on 8724 samples\n",
"Epoch 1/10\n",
" - 152s - loss: 0.6746 - accuracy: 0.7860 - val_loss: 2.2316 - val_accuracy: 0.1977\n",
"Epoch 2/10\n",
" - 148s - loss: 0.1768 - accuracy: 0.9496 - val_loss: 2.2468 - val_accuracy: 0.1977\n",
"Epoch 3/10\n",
" - 148s - loss: 0.1177 - accuracy: 0.9681 - val_loss: 2.2137 - val_accuracy: 0.1977\n",
"Epoch 4/10\n",
" - 147s - loss: 0.1166 - accuracy: 0.9705 - val_loss: 2.1745 - val_accuracy: 0.1977\n",
"Epoch 5/10\n",
" - 147s - loss: 0.0993 - accuracy: 0.9756 - val_loss: 0.8243 - val_accuracy: 0.7942\n",
"Epoch 6/10\n",
" - 149s - loss: 0.0763 - accuracy: 0.9815 - val_loss: 0.9804 - val_accuracy: 0.7658\n",
"Epoch 7/10\n",
" - 146s - loss: 0.0685 - accuracy: 0.9836 - val_loss: 2.2230 - val_accuracy: 0.6530\n",
"Epoch 8/10\n",
" - 149s - loss: 0.0582 - accuracy: 0.9859 - val_loss: 9.0434 - val_accuracy: 0.4411\n",
"Epoch 9/10\n",
" - 148s - loss: 0.0601 - accuracy: 0.9856 - val_loss: 4.6619 - val_accuracy: 0.6551\n",
"Epoch 10/10\n",
" - 149s - loss: 0.0429 - accuracy: 0.9905 - val_loss: 2.4783 - val_accuracy: 0.7839\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "WMvIAWyKOPKS",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 540
},
"outputId": "81814288-ac21-44b5-8545-29a594fb3b0c"
},
"source": [
"y_pred = model.predict(x_test)\n",
"\n",
"# plot a random sample of test images, their predicted labels, and ground truth\n",
"fig = plt.figure(figsize=(16, 9))\n",
"for i, idx in enumerate(np.random.choice(x_test.shape[0], size=16, replace=False)):\n",
" ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[])\n",
" ax.imshow(np.squeeze(x_test[idx]))\n",
" pred_idx = np.argmax(y_pred[idx])\n",
" true_idx = np.argmax(y_test[idx])\n",
" ax.set_title(\"{} ({})\".format(TYPES[pred_idx], TYPES[true_idx]),\n",
" color=(\"green\" if pred_idx == true_idx else \"red\"))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5h3ibwXPlv5HdiUvhfX0/MYsB3AijJG7HnkkEq0Wfv/PIxln2l1/UlpeDuB/YIwcc5pIkhhM9l6fyfz1ZUh2Ua5OX38bwC9gzCJYuyn92xpYa702ST/b3udptT0PYB2Maf0t8N7baht9ljxSONfdi+e6O3vHZi2SB0yLA9K/zYQvAfgTkmwQc5BseZkp7NW9U9nLAiR6PZ+/ATCmbJZOcm2qOg2AZW3q3B6vQSLReR6AASS6fcB9JuvZrwWwzJSN/Dc6wLv3E5DoFwmZEaZsupHsWBxryma9KZv1SLbFDzdlI7d+l4n39CGRwayd7Dra+/3DAG6wJTtX/NdnS7ZdKse7kGx7t+77TCTb2x8SbT0KwGtMWf2qPFVb5qXPhum09RyvrT22ZL8jbOh/ZHfzMJIdjLniv15Y+0lh4/f/BoDNU1xv9f+HARzv1d0Fq5J3+OOU5C4Aj/F2eE5FMuF5CMasRxK7l4feEV6aJhiYrE3T+TytttcALBRtnwNrZUr2JwBYBWuHp/gMhEwHznXbs8fnujt7YfMdAP9pymaRKZuFSLSFl82wrn4AwwBG04Bjf/KzAUmgorz3G0zZPCXVwZ+LZKtslV+xTVLG/QJTb/cBiSb4BFM2z011gO9F8vD8vxl+nhqALUhW5ed61/3PczOAcQAfMGWTTwPSVkJrKY9FomUkZKa8FMmvsoci0Qs/BclD5DfQkpEXmrI5JtXcfgzATbZk5a+h7zdlMy+Vp70LwGRnRvwUwCGmbF6X9um8KZt/SAMHJ+NqaB89FUmMjmzrE5Fsmcs0lW8zZbO/KZv5SGRzflvKpmwKpmz+EYk8brIMcBcBON2UzVGmbIwpm15TNieYsukHAFM2XUj00te1aTshu4LLAKyEMS+AM
"text/plain": [
"<Figure size 1152x648 with 16 Axes>"
]
},
"metadata": {
"tags": []
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "nUUJ3woiOQ_B",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "4a38780d-6bbd-47af-f1b2-fe561f69bf4c"
},
"source": [
"\n",
"plt.figure(1) \n",
" \n",
" \n",
"plt.subplot(211) \n",
"plt.plot(history.history['accuracy']) \n",
"plt.plot(history.history['val_accuracy']) \n",
"plt.title('model accuracy') \n",
"plt.ylabel('accuracy') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
" \n",
" \n",
"plt.subplot(212) \n",
"plt.plot(history.history['loss']) \n",
"plt.plot(history.history['val_loss']) \n",
"plt.title('model loss') \n",
"plt.ylabel('loss') \n",
"plt.xlabel('epoch') \n",
"plt.legend(['train', 'test'], loc='upper left') \n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deXxU5fX48c+ZJJAEAoGAIHu0qCgqKIKKKNYNFMUVN9wtbnXp11q1X5dq2++P1ta6L7ivuIAoLiiiqFgVDZuCqICghH2HBBKSzPn98dxJJmEShmQmNzNz3q/XvDJztzkzSe655z73Po+oKsYYY0xNAb8DMMYY0zRZgjDGGBORJQhjjDERWYIwxhgTkSUIY4wxEVmCMMYYE5ElCGMAEXlWRP4W5bJLROTYeMdkjN8sQRhjjInIEoQxSURE0v2OwSQPSxAmYXindm4SkW9FpFhEnhKRDiIySUS2iMgUEWkTtvwpIjJPRDaKyCci0itsXl8Rmemt9yqQWeO9honIbG/dL0TkgChjPElEZonIZhFZKiJ/qTH/CG97G735F3vTs0Tk3yLyi4hsEpHPvWmDRaQwwvdwrPf8LyIyTkReFJHNwMUi0l9EvvTeY4WIPCQizcLW309EPhSR9SKySkT+LCIdRWSriOSFLXeQiKwRkYxoPrtJPpYgTKI5AzgO2As4GZgE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Zt2pCdnc0PP/zAV1995UPExhgTmSWIGCmrCLJqcwkbircTCAgdW2fSrkVzAoFWDBw4kN69e5OVlUWHDh0q1xkyZAiPPfYYvXr1Yu+99+bQQ
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"tags": [],
"needs_background": "light"
}
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "mmG4dhPEbR5j",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 35
},
"outputId": "6490987f-0866-4d50-e9af-ea06296ff522"
},
"source": [
"y_pred = model.predict(x_test)\n",
"zol = zero_one(y_pred, y_test)\n",
"cnn_loss.append(zol)\n",
"print(\"Zero-one Loss: \", zol)\n"
],
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"text": [
"Zero-one Loss: 0.18973418881759854\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "YLIwv_usqLED",
"colab_type": "text"
},
"source": [
"# 1.7 Summary results"
]
},
{
"cell_type": "code",
"metadata": {
"id": "cuFIMRMarrOd",
"colab_type": "code",
"colab": {}
},
"source": [
"df_cnn_loss = pd.DataFrame(\n",
"columns = ['type', 'zero_one']\n",
")\n",
"\n",
"types = [\"1VGG\",\"2VGG\",\"3VGG\",\"3VGG-drop\", \"3VGG-drop-norm\",\"LeNet\",\"MobileNetV2\"]\n",
"df_cnn_loss = pd.DataFrame( data = [types,cnn_loss], index = ['types', 'zero_one']).T\n",
"\n",
"\n",
"\n",
"df_new = df_loss.rename(columns={'components': 'types'})\n",
"df_new['types'] = df_new['types'].astype(str)\n",
"\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "lkmFEyZ6v4A6",
"colab_type": "code",
"colab": {}
},
"source": [
"frames = [df_new, df_cnn_loss]\n",
"result = pd.concat(frames)\n",
"result = result.sort_values(by=['zero_one'])\n",
"\n",
"result = result.reset_index(drop=True)\n",
"\n"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "17oa_fAY1P_l",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 295
},
"outputId": "8ca06857-dad7-4701-e1b6-2f537c622d81"
},
"source": [
"\n",
"plt.barh( result['types'].values,result['zero_one'].values , align='center', alpha=0.5)\n",
"plt.xlabel('Loss')\n",
"plt.ylabel(\"Loss\")\n",
"plt.title('Model Loss summary')\n",
"\n",
"plt.show()"
],
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAdAAAAEWCAYAAADW7MapAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3de5hddX32//dNQMIpnIKRk4ZDUAEhQIpQVBDlUFSQghhEBR7QHy3F8tDHKsWroECVaoFiVYqARIUAovggqJgqD2iLQIAQEg5NOAcop4RziAL374/1HVnZzCR775k9e2Zzv65rrqy91net9f3O5JrPrNO9ZJuIiIhozQrd7kBERMRolAIaERHRhhTQiIiINqSARkREtCEFNCIiog0poBEREW1IAY0YhSRNlGRJKzbR9jBJvxuOfkW8kaSARnSYpPsl/UHS+Ib5t5YiOLE7PWutEEfE0lJAI4bHfcDBfR8kvQtYtXvdicHKHx2RAhoxPH4AfLr2+VDg+/UGktaU9H1JT0h6QNKXJK1Qlo2R9A1JT0q6F/hQP+ueJ+lRSQ9LOkXSmMF0WNIGkq6QtFDSfEmfqS3bUdJMSc9KekzS6WX+WEk/lPSUpKcl3SRpwgDb/0Lp63OS7pb0gTL/Akmn1NrtJmlB7fP9kj4vabakF8q4J0j6RdnWf0hau7TtO8I+XNJDkhZJOkrSn5X1n5b0b7VtbybpN6X/T0q6UNJaDfv+gqTZwAulHz9uGNdZkv51MN/7GB1SQCOGx++BcZLeWQrbVOCHDW2+C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