{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3649,"databundleVersionId":46718,"sourceType":"competition"}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# cifar10 with ANN ","metadata":{}},{"cell_type":"markdown","source":"**1. Introduction.¶**","metadata":{}},{"cell_type":"markdown","source":"The CIFAR-10 dataset contains **60,000** color images of **32 x 32** pixels in **3** channels(**RGB**) divided into 10 classes. Each class contains **6,000** images. The training set contains **50,000** images, while the test sets provides **10,000** images.\nThis image taken from the CIFAR repository This is a classification problem with **10** classes(muti-label classification).","metadata":{}},{"cell_type":"markdown","source":"Here we will load dataset using keras datasets","metadata":{}},{"cell_type":"markdown","source":"importing libraries","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport keras\nfrom keras.datasets import cifar10\nfrom keras.models import Sequential\nfrom keras.layers import Activation, Dense, Dropout, Flatten \nfrom keras.callbacks import EarlyStopping\nfrom keras.optimizers import Adam","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:34:09.068295Z","iopub.status.idle":"2024-05-11T10:34:09.068694Z","shell.execute_reply.started":"2024-05-11T10:34:09.068521Z","shell.execute_reply":"2024-05-11T10:34:09.068537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Load dataset and split in train and test.","metadata":{}},{"cell_type":"code","source":"(x_train, y_train), (x_test, y_test) = cifar10.load_data()","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:29.773888Z","iopub.execute_input":"2024-05-11T10:28:29.774533Z","iopub.status.idle":"2024-05-11T10:28:44.549659Z","shell.execute_reply.started":"2024-05-11T10:28:29.774502Z","shell.execute_reply":"2024-05-11T10:28:44.548626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'x_train shape: {x_train.shape}')\nprint(f'y_train shape: {y_train.shape}')\nprint(f'x_test shape: {x_test.shape}')\nprint(f'y_test shape: {y_test.shape}')\nprint(f'No of x_train sample: {x_train.shape[0]}')\nprint(f'No of y_train sample: {y_train.shape[0]}')\n","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.551028Z","iopub.execute_input":"2024-05-11T10:28:44.551362Z","iopub.status.idle":"2024-05-11T10:28:44.557341Z","shell.execute_reply.started":"2024-05-11T10:28:44.551334Z","shell.execute_reply":"2024-05-11T10:28:44.556202Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"basically we have x_train in 4D ndarray","metadata":{}},{"cell_type":"code","source":"print(type(x_train)) ","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.560322Z","iopub.execute_input":"2024-05-11T10:28:44.561113Z","iopub.status.idle":"2024-05-11T10:28:44.568472Z","shell.execute_reply.started":"2024-05-11T10:28:44.561055Z","shell.execute_reply":"2024-05-11T10:28:44.567458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Count plot for training dataset**","metadata":{}},{"cell_type":"code","source":"df = pd.DataFrame(y_train, columns=['classes'])\ndf.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.569650Z","iopub.execute_input":"2024-05-11T10:28:44.570074Z","iopub.status.idle":"2024-05-11T10:28:44.600008Z","shell.execute_reply.started":"2024-05-11T10:28:44.570047Z","shell.execute_reply":"2024-05-11T10:28:44.598747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axs = plt.subplots()\nsns.countplot(x = 'classes', data = df, palette='cool')\nplt.xlabel(\"Class Label\")\nplt.ylabel(\"Number of Samples\")\nplt.title(\"Number of Samples per Class Distribution\")","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.601444Z","iopub.execute_input":"2024-05-11T10:28:44.601835Z","iopub.status.idle":"2024-05-11T10:28:44.905493Z","shell.execute_reply.started":"2024-05-11T10:28:44.601797Z","shell.execute_reply":"2024-05-11T10:28:44.904446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**count plot for testing dataset**","metadata":{}},{"cell_type":"code","source":"df = pd.DataFrame(y_test, columns=['classes'])\nprint(df.value_counts())","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.906983Z","iopub.execute_input":"2024-05-11T10:28:44.907404Z","iopub.status.idle":"2024-05-11T10:28:44.917152Z","shell.execute_reply.started":"2024-05-11T10:28:44.907365Z","shell.execute_reply":"2024-05-11T10:28:44.916017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfig, axs = plt.subplots()\nsns.countplot(x = 'classes', data = df, palette='cool')\nplt.xlabel(\"Class Label\")\nplt.ylabel(\"Number of Samples\")\nplt.title(\"Number of Samples per Class Distribution\")","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:44.918277Z","iopub.execute_input":"2024-05-11T10:28:44.918715Z","iopub.status.idle":"2024-05-11T10:28:45.223374Z","shell.execute_reply.started":"2024-05-11T10:28:44.918686Z","shell.execute_reply":"2024-05-11T10:28:45.222353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we can see, each classe contain exacly 6000 examples( 5000 for training and 1000 for test).\n\nThe graph above shows us that data is balanced and for example if we had just 1000 samples of label 1 that will be a problem , the model will find difficulties to detect label 1\"less accuracy \", so that's not going to happend everything look fine. It's important to know the distribution of dataset behind different classes because the goodness of our model depend on it.\n\nNow let's doing some preprocessing.\n\nThe output variable have 10 posible values. This is a multiclass classification problem. We need to encode these lables to one hot vectors (ex : \"bird\" -> [0,0,1,0,0,0,0,0,0,0]).As we can see, each classe contain exacly 6000 examples( 5000 for training and 1000 for test).","metadata":{}},{"cell_type":"markdown","source":"# Normalizing\nWe have to normalize the data in order to reduce the pixel values. Currently, all the image pixels are in a range from 0–255, and we want the values in the range of 0 and 1. So we can either divide all the pixel values by 255.0 or use the ‘normalize’ command from keras library.","metadata":{}},{"cell_type":"markdown","source":"**key benefits of normalizing:**\n\n1. Improved Model Convergence:\n2. Fairer Treatment of Features:\n3. Enhanced Interpretability:\n4. Optimized Algorithm Performance:\n5. Reduced Risk of Vanishing:","metadata":{}},{"cell_type":"code","source":"# before scaling\nprint(x_train[0].shape)\nprint(x_train[0])","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:45.224852Z","iopub.execute_input":"2024-05-11T10:28:45.225284Z","iopub.status.idle":"2024-05-11T10:28:45.231941Z","shell.execute_reply.started":"2024-05-11T10:28:45.225246Z","shell.execute_reply":"2024-05-11T10:28:45.230897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train/255\nx_test = x_test/255","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:45.235145Z","iopub.execute_input":"2024-05-11T10:28:45.235475Z","iopub.status.idle":"2024-05-11T10:28:45.895932Z","shell.execute_reply.started":"2024-05-11T10:28:45.235448Z","shell.execute_reply":"2024-05-11T10:28:45.894856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# after scaling\nprint(x_train[0].shape)","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:45.897051Z","iopub.execute_input":"2024-05-11T10:28:45.898284Z","iopub.status.idle":"2024-05-11T10:28:45.903834Z","shell.execute_reply.started":"2024-05-11T10:28:45.898253Z","shell.execute_reply":"2024-05-11T10:28:45.902757Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Activation function","metadata":{}},{"cell_type":"markdown","source":"Befor using ANN first try to learn what is activation function\n**Activation function**\nThe activation function can be defined as a mathematical function that introduces non-linearity to the neural network. This enables the models to learn complex patterns and helps them make accurate predictions.\n\nIn simple words, think of it like a switch, that decides whether a neuron should be activated or not. If the input is above a certain threshold or meets certain criteria, the neuron will activate/fire, or else it remains inactive.\n\nfor more better understanding please refer this article --link text\nwe have many activation function\n1. Step Function:\n2. Sigmoid Function: \n3. ReLU:","metadata":{}},{"cell_type":"markdown","source":"**ReLu:**\nReLU is the most popular and commonly used activation function. It outputs the input value if it is positive or returns zero. It has advantage over sigmoid and tanh\n\n![image.png](attachment:af64ac80-2feb-4d08-a288-816db785e7f6.png)","metadata":{},"attachments":{"af64ac80-2feb-4d08-a288-816db785e7f6.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAZQAAAA0CAIAAAAizFmtAAAgAElEQVR4Ae19e0xU1/b/PmdyZhgCDBMeEqoSgRrx2ghIUK+pChEfsWpvfdS0t216BSJXTREMvqKtBlCC2sYXKWjTWr1Fi1HrTX1FbZtaMAKa2paIaMRq6oPIwwAzw5xzflM/+a7f7jkz4+CrXDvzx2SdfdZee+2111577bUfh6n+n18Cfgn0SQnYH/yINVmWKyoqcnNzKeU5BioqKv7973+rqtrd3a0oiqqqNpuN6ivLsqIojJ79gF8Cfgn0KQnY7XZVVWVZdjgcqqoWFxenpKTwfbhPcfvEmZk1a9b06dNlWSbKNpsNZgspfuNFkvEDfgn0OQlQ1924cWNERERHR0efY/FpMpSSkjJ37lxPJfiNlyfJ+NP9EvjzJQDn69SpU6Ionj179s9n6BlyoChKa2traGjounXr3Bbr0Xi1t7eHhoYaDAbGmCAIkiQBFkXRYDBIksT++BMEITg4+IUXXhg7dmxhYWF1dTVmqjR04NEtE08qUVGUlpYWq9XKGBNFMTw8PCIiwmQyhT34hYeHW61Wi8USGBgoSZIgCBkZGaqqKori7HF64eHHH380mUyBgYEBAQHh4eEWi8VqtZrN5tDQ0LCwsICAgMDAQJPJxBj7/PPPPdHp16+fIAhhYWGBgYEhISEWiyU4ODgoKCg6OhrckqA8UfCn/9UkAJVobGxkjG3cuNFL9TWdC9NMm83W1dUFDae8GkxK75uA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Ozz//HCeLabL5VJnU9BfXV2++++67wYMHP9VCfSfucDgaGhoYY/SNqId/t9F36n0Bk28AHuZ58xsvXhp+uK9JAG4pPjMoSRI+Y+H79OqRq6PpL4qibN++fd68eY9M8AlmRARp4cKFoihihg6D7ve8nqCQ/aT8EngsCcCCyLKMy2SWLVvGGKPPPj4W6Ydl5o0XGBgxYsTu3bsflu8ZvcfJUwQBaafUc2W8npEg/cX4JfDUJADPC8sCqqqGhYXh/BPW6/m1hSfLAgL2dIFoTU1NZGTkky2iV9Sw/oYsritD8vPzXd+a1Cyw+I1Xr0TqR/ZL4FlIgIIbO3fudB3oOX/+PHyxp73WQSsDrvsgi4qKnkVVPZQBY4oLTVtbWw0GA935Q0LwGy8PwvMn+yXw50mA5o+KoqSkpKSmpmI/xNMLftGhIkVRioqK6DTCnycDlSqLz/HcuHGDX7tQFMVvvP7E1vEX7ZeAewmQ5yXL8q1bt0JCQkpLS73suHRPpTepmJAqilJXV2c0Gqurqx/nMxm9KdkjLnZInDhxwnVU8b///S8eye3yGy+PgvO/8Eugj0jAZrPhw0s+XvHymGxPnz790KFDtGf1Mak9cnaY75aWFovFggNbelJ+z0svE3+KXwJ9SwI2m624uDg2Npa/F/tpsIiZ2p9uuVA11zekMzIyZs+ejdXPrq4umkgCwW+8noYO+Gn6JfCEJeD65tCKFSteeumlJ0z3j+T41Uzfr6n5I40n8+RwODIzM6dNmwaW3J6C9BuvJyNrPxW/BJ6qBLAOuHnz5qf6pWuKKCE0zt9L8VRrpye+f//+xYsX022Ibk86/z/0+DHb8U4TegAAAABJRU5ErkJggg=="}}},{"cell_type":"markdown","source":"ReLU is majorly used in the hidden layers of the neural network since it brings sparsity to the data.\n1. Non-linearity:\n2. Computationally Efficient:\n3. No Vanishing Gradient Problem:","metadata":{}},{"cell_type":"markdown","source":"A **sample** is a single row of data.","metadata":{}},{"cell_type":"code","source":"# ANN\n# setting up the layers of Neural Network\n# A Sequential model is appropriate for a plain stack of\n# layers where each layer has exactly one input tensor and one output tensor\n\n# provides inbuilt modules for all neural network computations\nann_classifier = Sequential()\n\n# keras.flatten converts the multi-dimensional arrays into\n# flattened one-dimensional arrays or single-dimensional arrays\nann_classifier.add(Flatten(input_shape=(32,32,3)))  # Input Layer\n\n# Keras Dense layer is the layer that contains all the neurons that are deeply connected within themselves\n# Relu remove every negative value from the filtered image and replace it with zero.\nann_classifier.add(Dense(units=256, activation='relu'))   # Hidden Layer\nann_classifier.add(Dense(units=256, activation='relu'))   # Hidden Layer\nann_classifier.add(Dense(units=128, activation='relu'))   # Hidden Layer\nann_classifier.add(Dense(units=64, activation='relu'))   # Hidden Layer\nann_classifier.add(Dense(units=32, activation='relu'))   # Hidden Layer\n\n# The softmax function is used as the activation function in the output layer of\n# neural network models that predict a multinomial probability distribution.\nann_classifier.add(Dense(units=10, activation='softmax'))    # Output Layer","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:34:09.070040Z","iopub.status.idle":"2024-05-11T10:34:09.070826Z","shell.execute_reply.started":"2024-05-11T10:34:09.070625Z","shell.execute_reply":"2024-05-11T10:34:09.070645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Optimization\nThe optimization algorithm is called “**gradient descent**“, where “gradient” refers to the calculation of an error gradient or **slope of error** and “descent” refers to the moving down along that **slope towards some minimum** level of error.","metadata":{}},{"cell_type":"code","source":"\n# compile the neural network\n\n# compilation is a step that transforms the simple sequence of layers\n# that we previously defined into a highly efficient series of matrix transformations\n\n# Optimizer it helps in reducing the overall loss and improving accuracy.\n\n# Adam optimization is a stochastic gradient descent method that is based on\n# adaptive estimation of first-order and second-order moments.\n\n# sparse_categarical_cross. when each sample belongs exactly to one\n# categorical crossentropy when one sample can have multiple classes or labels are\n\n# soft probabilities (like [0.5, 0.3, 0.2]).\n\nann_classifier.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:46.053664Z","iopub.execute_input":"2024-05-11T10:28:46.054494Z","iopub.status.idle":"2024-05-11T10:28:46.073250Z","shell.execute_reply.started":"2024-05-11T10:28:46.054451Z","shell.execute_reply":"2024-05-11T10:28:46.072114Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Epoch\nThe number of epochs is a hyperparameter that defines the number times that the learning algorithm will work through the entire training dataset.\nThe number of epochs can be set to an integer value between **one and infinity**. You can run the algorithm for as long as you like and even stop it using other criteria besides a fixed number of epochs just like here i have use fixed number of **epochs equeal to 50** as well as other stoping criteria that is **Early stopping**","metadata":{}},{"cell_type":"markdown","source":"# Batch\nThe batch size is a hyperparameter that defines the number of samples to work through before updating the internal model parameters.\n\n**1<= batch size <= number of samples in the training dataset.**\n\nThink of a batch as a for-loop iterating over one or more samples and making predictions. At the end of the batch, the predictions are compared to the expected output variables and an error is calculated. From this error, the update algorithm is used to improve the model, e.g. move down along the error gradient.\n\n**Depending upon size of batch we divide it into 3 category**\n1. **Batch Gradient Descent**. Batch Size = Size of Training Set\n2. **Stochastic Gradient Descent**. Batch Size = 1\n3. **Mini-Batch Gradient Descent**. 1 < Batch Size < Size of Training Set","metadata":{}},{"cell_type":"code","source":"# Define early stopping callback\nearly_stopping = EarlyStopping(monitor='val_loss', patience=10)\n\n# training the neural network\n# validation_split is Fraction of the training data to be used as validation data\n# Epoch is the total number of iterations of the training data in one cycle\nhistory = ann_classifier.fit(x_train, y_train, validation_split=0.1, epochs=50, batch_size=64, callbacks=[early_stopping])","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:28:46.074723Z","iopub.execute_input":"2024-05-11T10:28:46.075380Z","iopub.status.idle":"2024-05-11T10:34:08.401444Z","shell.execute_reply.started":"2024-05-11T10:28:46.075338Z","shell.execute_reply":"2024-05-11T10:34:08.400208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**We got accuracy of 61.05% with training dataset and 48.24 with validation dataset**\nwhich is quit low.","metadata":{}},{"cell_type":"markdown","source":"Now we can save our trained model, since it takes lots of resuources to train our model everytime so we can save and later we load and use it directly.","metadata":{}},{"cell_type":"code","source":"ann_classifier.save('ann_classifier.h5')","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:45:19.317844Z","iopub.execute_input":"2024-05-11T10:45:19.318339Z","iopub.status.idle":"2024-05-11T10:45:19.375774Z","shell.execute_reply.started":"2024-05-11T10:45:19.318305Z","shell.execute_reply":"2024-05-11T10:45:19.374704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"loss, accuracy = ann_classifier.evaluate(x_test, y_test)\nprint('Test Accuracy =', accuracy)","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:43:26.092861Z","iopub.execute_input":"2024-05-11T10:43:26.094096Z","iopub.status.idle":"2024-05-11T10:43:27.359285Z","shell.execute_reply.started":"2024-05-11T10:43:26.094041Z","shell.execute_reply":"2024-05-11T10:43:27.358237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"h = history\nplt.title('ANN')\n# plot the loss value\nplt.plot(h.history['loss'], label='train loss')\nplt.plot(h.history['val_loss'], label='validation loss')\nplt.legend()\nplt.show()\n\n# plot the accuracy value\nplt.plot(h.history['accuracy'], label='train accuracy')\nplt.plot(h.history['val_accuracy'], label='validation accuracy')\nplt.legend()\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-05-11T10:43:31.347864Z","iopub.execute_input":"2024-05-11T10:43:31.348304Z","iopub.status.idle":"2024-05-11T10:43:31.884408Z","shell.execute_reply.started":"2024-05-11T10:43:31.348269Z","shell.execute_reply":"2024-05-11T10:43:31.883168Z"},"trusted":true},"execution_count":null,"outputs":[]}]}