{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "source": [ "# Description: This program use Convolutional Neural Networks(CNN)\n", "# classify handwritten digits as number 0-9" ], "metadata": { "id": "aG9gtI4ILjw7" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "#importing the libraries\n", "from keras.models import Sequential\n", "from keras.layers import Dense, Conv2D, Flatten, MaxPool2D\n", "from keras.datasets import mnist\n", "from keras.utils import to_categorical\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ], "metadata": { "id": "88xMcxjMLrhq" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "# Importing necessary libraries\n", "from keras.datasets import mnist # Ensure this import is present\n", "\n", "# Load the data and split it into train and test\n", "(X_train, y_train), (X_test, y_test) = mnist.load_data()\n", "\n", "# Print the shape of the data to confirm it is loaded correctly\n", "print(X_train.shape)\n", "print(X_test.shape)\n" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "NWxxlIBWLwnS", "outputId": "8d4d841a-da0c-450a-ba2a-eedb569143eb" }, "execution_count": 2, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n", "\u001b[1m11490434/11490434\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m1s\u001b[0m 0us/step\n", "(60000, 28, 28)\n", "(10000, 28, 28)\n" ] } ] }, { "cell_type": "code", "source": [ "import matplotlib.pyplot as plt\n", "plt.imshow(X_train[2])" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 448 }, "id": "E9KENPZLMPic", "outputId": "1270dab9-963a-4c5a-c341-a6c9c953aaf7" }, "execution_count": 4, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "" ] }, "metadata": {}, "execution_count": 4 }, { "output_type": "display_data", "data": { "text/plain": [ "
" ], "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAa3UlEQVR4nO3df3BU9b3/8dcmJAtosmkIyWZLwIACrUj8lkKai1IsGUI6l+HX7fVX54Lj4EiDt0CtTjoKop1JxRnr6E3xj6tQZ0SUGYEro8yFYMLYBiwIXy7faobkm0q4kKDcm2wIECL53D+4bruSiCfs5p0Nz8fMmSG755Pz9rjDk8NuDj7nnBMAAP0syXoAAMD1iQABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATQ6wH+Kru7m6dPHlSaWlp8vl81uMAADxyzqm9vV2hUEhJSb1f5wy4AJ08eVJ5eXnWYwAArlFTU5NGjRrV6/MDLkBpaWmSpDv0Yw1RivE0AACvvlCXPtC7kd/PexO3AFVWVuq5555Tc3OzCgoK9NJLL2natGlXXfflX7sNUYqG+AgQACSc/73D6NXeRonLhxDefPNNrVq1SmvWrNFHH32kgoIClZSU6PTp0/E4HAAgAcUlQM8//7yWLl2qBx54QN/97nf18ssva/jw4Xr11VfjcTgAQAKKeYAuXryogwcPqri4+K8HSUpScXGxamtrr9i/s7NT4XA4agMADH4xD9Dnn3+uS5cuKScnJ+rxnJwcNTc3X7F/RUWFAoFAZOMTcABwfTD/QdTy8nK1tbVFtqamJuuRAAD9IOafgsvKylJycrJaWlqiHm9paVEwGLxif7/fL7/fH+sxAAADXMyvgFJTUzVlyhRVVVVFHuvu7lZVVZWKiopifTgAQIKKy88BrVq1SosXL9b3v/99TZs2TS+88II6Ojr0wAMPxONwAIAEFJcA3X333frss8+0evVqNTc36/bbb9fOnTuv+GACAOD65XPOOesh/lY4HFYgENBMzeNOCACQgL5wXarWdrW1tSk9Pb3X/cw/BQcAuD4RIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJoZYDwAAXnT8Q6HnNc+uW9+nYz3zj//keY07cLRPx7oecQUEADBBgAAAJmIeoKeeeko+ny9qmzhxYqwPAwBIcHF5D+jWW2/V7t27/3qQIbzVBACIFpcyDBkyRMFgMB7fGgAwSMTlPaBjx44pFApp7Nixuv/++3X8+PFe9+3s7FQ4HI7aAACDX8wDVFhYqI0bN2rnzp1av369Ghsbdeedd6q9vb3H/SsqKhQIBCJbXl5erEcCAAxAMQ9QaWmpfvKTn2jy5MkqKSnRu+++q9bWVr311ls97l9eXq62trbI1tTUFOuRAAADUNw/HZCRkaHx48ervr6+x+f9fr/8fn+8xwAADDBx/zmgs2fPqqGhQbm5ufE+FAAggcQ8QI8++qhqamr0l7/8RX/84x+1YMECJScn69577431oQAACSzmfwV34sQJ3XvvvTpz5oxGjhypO+64Q/v27dPIkSNjfSgAQAKLeYA2b94c6285KJyfN837mhHJntdkvlrreQ2QSE5/3/tf3Dzzl7lxmATXinvBAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAm4v4P0uGykzO8t374uFbvB3rV+xLATJL3G+660ec9r5mV/YnnNZJU5fu7Pq3DN8MVEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAExwN+x+svbvt3he8+zHs+MwCTBwJI8b43nNJz/0fsv32z/8qec1khT603/0aR2+Ga6AAAAmCBAAwAQ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t3r3bfe9733O33HKLu3DhgvXoMbNs2TIXCARcdXW1O3XqVGQ7d+5cZJ+HH37YjR492u3Zs8cdOHDAFRUVuaKiIsOpY+9q56G+vt49/fTT7sCBA66xsdFt377djR071s2YMcN48mgJESDnnHvppZfc6NGjXWpqqps2bZrbt2+f9Uj97u6773a5ubkuNTXVffvb33Z33323q6+vtx4r7t5//30n6Ypt8eLFzrnLH8V+8sknXU5OjvP7/W7WrFmurq7Odug4+LrzcO7cOTd79mw3cuRIl5KS4saMGeOWLl066P6Q1tN/vyS3YcOGyD7nz593P/vZz9y3vvUtN3z4cLdgwQJ36tQpu6Hj4Grn4fjx427GjBkuMzPT+f1+d/PNN7tf/vKXrq2tzXbwr+CfYwAAmBjw7wEBAAYnAgQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMDE/wB3z3opkp0DGwAAAABJRU5ErkJggg==\n" }, "metadata": {} } ] }, { "cell_type": "code", "source": [ "# Reshaping the data to fit the model\n", "X_train = X_train.reshape(60000, 28, 28, 1)\n", "X_test = X_test.reshape(10000, 28, 28, 1)\n", "" ], "metadata": { "id": "T9QNOCA-MUza" }, "execution_count": 5, "outputs": [] }, { "cell_type": "code", "source": [ "from keras.utils import to_categorical\n", "# One-Hot Encoding:\n", "y_train_one_hot = to_categorical(y_train)\n", "y_test_one_hot = to_categorical(y_test)\n", "\n", "# Print the new label\n", "print(y_train_one_hot[0])\n", "" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "_dz47ah6Mbxb", "outputId": "07e352a8-70e8-4ade-9276-d25590d644ec" }, "execution_count": 7, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "[0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]\n" ] } ] }, { "cell_type": "code", "source": [ "from keras.models import Sequential\n", "from keras.layers import Dense, Conv2D, Flatten, MaxPool2D\n", "# Build the CNN model\n", "model = Sequential()\n", "# Add model layers\n", "model.add(Conv2D(64, kernel_size=3, activation = 'relu', input_shape=(28,28,1)))\n", "model.add(Conv2D(32, kernel_size=3, activation='relu'))\n", "model.add(MaxPool2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None))\n", "model.add(Flatten())\n", "model.add(Dense(10,activation='softmax'))" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "2IMtu7wBMl1y", "outputId": "ae139133-66e6-410c-f683-15dbb934435b" }, "execution_count": 10, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/keras/src/layers/convolutional/base_conv.py:107: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n", " super().__init__(activity_regularizer=activity_regularizer, **kwargs)\n" ] } ] }, { "cell_type": "code", "source": [ "model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])" ], "metadata": { "id": "McSShYa9Mxoq" }, "execution_count": 11, "outputs": [] }, { "cell_type": "code", "source": [ "#Train the model\n", "hist = model.fit(X_train,y_train_one_hot, validation_data=(X_test,y_test_one_hot), epochs=3)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "VIpA9GLFNvwS", "outputId": "64c9c7d0-2466-4017-bb9c-b1b2c754ea55" }, "execution_count": 14, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Epoch 1/3\n", "\u001b[1m1875/1875\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m150s\u001b[0m 80ms/step - accuracy: 0.9793 - loss: 0.0654 - val_accuracy: 0.9801 - val_loss: 0.0650\n", "Epoch 2/3\n", "\u001b[1m1875/1875\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m157s\u001b[0m 84ms/step - accuracy: 0.9851 - loss: 0.0480 - val_accuracy: 0.9798 - val_loss: 0.0742\n", "Epoch 3/3\n", "\u001b[1m1875/1875\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m198s\u001b[0m 81ms/step - accuracy: 0.9885 - loss: 0.0370 - val_accuracy: 0.9814 - val_loss: 0.0669\n" ] } ] } ] }