{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Home Page](../Start_Here.ipynb)\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"[Next Notebook](CNN's.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CNN Primer and Keras 101"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"In this notebook, participants will be introduced to CNN, implement it using Keras. For an absolute beginner this notebook would serve as a good starting point.\n",
"\n",
"**Contents of the this notebook:**\n",
"\n",
"- [How a Deep Learning project is planned ?](#Machine-Learning-Pipeline)\n",
"- [Wrapping things up with an example ( Classification )](#Image-Classification-on-types-of-clothes)\n",
"\n",
"\n",
"**By the end of this notebook participant will:**\n",
"\n",
"- Understand the Machine Learning Pipeline\n",
"- Write a Deep Learning Classifier and train it.\n",
"\n",
"**We will be building a _Multi-class Classifier_ to classify images of clothing to their respective classes**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Machine Learning Pipeline\n",
"\n",
"During the bootcamp we will be making use of the following buckets to help us understand how a Machine Learning project should be planned and executed: \n",
"\n",
"1. **Data**: To start with any ML project we need data which is pre-processed and can be fed into the network.\n",
"2. **Task**: There are many tasks present in ML, we need to make sure we understand and define the problem statement accurately.\n",
"3. **Model**: We need to build our model, which is neither too deep and complex, thereby taking a lot of computational power or too small that it could not learn the important features.\n",
"4. **Loss**: Out of the many _loss functions_ present, we need to carefully choose a _loss function_ which is suitable for the task we are about to carry out.\n",
"5. **Learning**: As we mentioned in our last notebook, there are a variety of _optimisers_ each with their advantages and disadvantages. So here we choose an _optimiser_ which is suitable for our task and train our model using the set hyperparameters.\n",
"6. **Evaluation**: This is a crucial step in the process to determine if our model has learnt the features properly by analysing how it performs when unseen data is given to it. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Here we will be building a _Multi-class Classifier_ to classify images of clothing to their respective classes.**\n",
"\n",
"We will follow the above discussed pipeline to complete the example.\n",
"\n",
"## Image Classification on types of clothes \n",
"\n",
"#### Step -1 : Data \n",
"\n",
"We will be using the **F-MNIST ( Fashion MNIST )** dataset, which is a very popular dataset. This dataset contains 70,000 grayscale images in 10 categories. The images show individual articles of clothing at low resolution (28 by 28 pixels).\n",
"\n",
"\n",
"\n",
"*Source: https://www.tensorflow.org/tutorials/keras/classification*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import Necessary Libraries\n",
"\n",
"from __future__ import absolute_import, division, print_function, unicode_literals\n",
"\n",
"# TensorFlow and tf.keras\n",
"import tensorflow as tf\n",
"from tensorflow import keras\n",
"\n",
"# Helper libraries\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"print(tf.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# Let's Import the Dataset\n",
"fashion_mnist = keras.datasets.fashion_mnist\n",
"\n",
"(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Loading the dataset returns four NumPy arrays:\n",
"\n",
"* The `train_images` and `train_labels` arrays are the *training set*—the data the model uses to learn.\n",
"* The model is tested against the *test set*, the `test_images`, and `test_labels` arrays.\n",
"\n",
"The images are 28x28 NumPy arrays, with pixel values ranging from 0 to 255. The *labels* are an array of integers, ranging from 0 to 9. These correspond to the *class* of clothing the image represents:\n",
"\n",
"
Label | \n", "Class | \n", "
---|---|
0 | \n", "T-shirt/top | \n", "
1 | \n", "Trouser | \n", "
2 | \n", "Pullover | \n", "
3 | \n", "Dress | \n", "
4 | \n", "Coat | \n", "
5 | \n", "Sandal | \n", "
6 | \n", "Shirt | \n", "
7 | \n", "Sneaker | \n", "
8 | \n", "Bag | \n", "
9 | \n", "Ankle boot | \n", "