|
@@ -25,21 +25,21 @@
|
|
|
"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",
|
|
|
+ "In this notebook you will be introduced to the concept of a convolutional neural network (CNN) and implement one using Keras. This notebook is designed as a starting point for absolute beginners to deep learning.\n",
|
|
|
"\n",
|
|
|
- "**Contents of the this notebook:**\n",
|
|
|
+ "**Contents of this notebook:**\n",
|
|
|
"\n",
|
|
|
- "- [How a Deep Learning project is planned ?](#Machine-Learning-Pipeline)\n",
|
|
|
- "- [Wrapping things up with an example ( Classification )](#Wrapping-Things-up-with-an-Example)\n",
|
|
|
- " - [Fully Connected Networks](#Image-Classification-on-types-of-Clothes)\n",
|
|
|
+ "- [How a deep learning project is planned](#Machine-Learning-Pipeline)\n",
|
|
|
+ "- [Wrapping things up with an example (classification)](#Wrapping-Things-up-with-an-Example)\n",
|
|
|
+ " - [Fully connected networks](#Image-Classification-on-types-of-Clothes)\n",
|
|
|
"\n",
|
|
|
"\n",
|
|
|
- "**By the end of this notebook participant will:**\n",
|
|
|
+ "**By the end of this notebook the participant will:**\n",
|
|
|
"\n",
|
|
|
- "- Understand the Machine Learning Pipeline\n",
|
|
|
- "- Write a Deep Learning Classifier and train it.\n",
|
|
|
+ "- Understand machine learning pipelines\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**"
|
|
|
+ "**We will be building a _multi-class classifier_ to classify images of clothing into their respective classes.**"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -48,29 +48,29 @@
|
|
|
"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",
|
|
|
+ "During the bootcamp we will be making use of the following concepts to help us understand how a machine learning (ML) project should be planned and executed:\n",
|
|
|
"\n",
|
|
|
"1. **Data**: To start 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 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. "
|
|
|
+ "2. **Task**: There are many possible tasks in the field of 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 (requiring a lot of computational power) nor too small (preventing it from learning the important features).\n",
|
|
|
+ "4. **Loss**: Out of the many _loss functions_ that can be defined, we need to carefully choose one which is suitable for the task we are about to carry out.\n",
|
|
|
+ "5. **Learning**: There are a variety of _optimisers_, each with their advantages and disadvantages. We must choose one which is suitable for our task and train our model using some suitably chosen hyperparameters.\n",
|
|
|
+ "6. **Evaluation**: We must determine if our model has learned the features properly by analysing how it performs on data it has not previously seen. "
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "**Here we will be building a _Multi-class Classifier_ to classify images of clothing to their respective classes.**\n",
|
|
|
+ "**Here we will be building a _multi-class classifier_ to classify images of clothing into their respective classes.**\n",
|
|
|
"\n",
|
|
|
- "We will follow the above discussed pipeline to complete the example.\n",
|
|
|
+ "We will follow the pipeline presented above to complete the example.\n",
|
|
|
"\n",
|
|
|
- "## Image Classification on types of clothes \n",
|
|
|
+ "## Image classification on types of clothes \n",
|
|
|
"\n",
|
|
|
- "#### Step -1 : Data \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",
|
|
|
+ "We will be using the **Fashion MNIST** dataset, which is a very popular introductory dataset in deep learning. 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",
|
|
|
"<img src=\"images/fashion-mnist.png\" alt=\"Fashion MNIST sprite\" width=\"600\">\n",
|
|
|
"\n",
|
|
@@ -196,27 +196,27 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "#Print Array Size of Training Set \n",
|
|
|
- "print(\"Size of Training Images :\"+str(train_images.shape))\n",
|
|
|
- "#Print Array Size of Label\n",
|
|
|
- "print(\"Size of Training Labels :\"+str(train_labels.shape))\n",
|
|
|
- "\n",
|
|
|
- "#Print Array Size of Test Set \n",
|
|
|
- "print(\"Size of Test Images :\"+str(test_images.shape))\n",
|
|
|
- "#Print Array Size of Label\n",
|
|
|
- "print(\"Size of Test Labels :\"+str(test_labels.shape))\n",
|
|
|
- "\n",
|
|
|
- "#Let's See how our Outputs Look like \n",
|
|
|
- "print(\"Training Set Labels :\"+str(train_labels))\n",
|
|
|
- "#Data in the Test Set\n",
|
|
|
- "print(\"Test Set Labels :\"+str(test_labels))"
|
|
|
+ "# Print array size of training dataset\n",
|
|
|
+ "print(\"Size of Training Images: \" + str(train_images.shape))\n",
|
|
|
+ "# Print array size of labels\n",
|
|
|
+ "print(\"Size of Training Labels: \" + str(train_labels.shape))\n",
|
|
|
+ "\n",
|
|
|
+ "# Print array size of test dataset\n",
|
|
|
+ "print(\"Size of Test Images: \" + str(test_images.shape))\n",
|
|
|
+ "# Print array size of labels\n",
|
|
|
+ "print(\"Size of Test Labels: \" + str(test_labels.shape))\n",
|
|
|
+ "\n",
|
|
|
+ "# Let's see how our outputs look\n",
|
|
|
+ "print(\"Training Set Labels: \" + str(train_labels))\n",
|
|
|
+ "# Data in the test dataset\n",
|
|
|
+ "print(\"Test Set Labels: \" + str(test_labels))"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "## Data Pre-processing\n"
|
|
|
+ "## Data Preprocessing\n"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -236,7 +236,7 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "The image pixel values range from 0 to 255. Let us now normalise the data range from 0 - 255 to 0 - 1 in both the *Train* and *Test* set. This Normalisation of pixels helps us by optimizing the process where the gradients are computed."
|
|
|
+ "The image pixel values range from 0 to 255. Let us now normalise the data range from 0 - 255 to 0 - 1 in both the *Train* and *Test* set. This normalisation of pixels helps us by optimizing the process where the gradients are computed."
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -255,7 +255,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "# Let's Print to Veryify if the Data is of the correct format.\n",
|
|
|
+ "# Let's print to verify whether the data is of the correct format.\n",
|
|
|
"plt.figure(figsize=(10,10))\n",
|
|
|
"for i in range(25):\n",
|
|
|
" plt.subplot(5,5,i+1)\n",
|
|
@@ -273,13 +273,13 @@
|
|
|
"source": [
|
|
|
"## Defining our Model\n",
|
|
|
"\n",
|
|
|
- "Our Model has three layers :\n",
|
|
|
+ "Our model has three layers:\n",
|
|
|
"\n",
|
|
|
- "- 784 Input features ( 28 * 28 ) \n",
|
|
|
- "- 128 nodes in hidden layer (Feel free to experiment with the value)\n",
|
|
|
- "- 10 output nodes to denote the Class\n",
|
|
|
+ "- 784 input features (28 * 28)\n",
|
|
|
+ "- 128 nodes in the hidden layer (feel free to experiment with this value)\n",
|
|
|
+ "- 10 output nodes to denote the class\n",
|
|
|
"\n",
|
|
|
- "Implementing the same in Keras ( Machine Learning framework built on top of Tensorflow, Theano, etc..) \n"
|
|
|
+ "We will implement this model in Keras (TensorFlow's high-level API for machine learning).\n"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -346,7 +346,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "model.fit(train_images, train_labels ,epochs=5)"
|
|
|
+ "model.fit(train_images, train_labels, epochs=5)"
|
|
|
]
|
|
|
},
|
|
|
{
|
|
@@ -364,7 +364,7 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
- "#Evaluating the Model using the Test Set\n",
|
|
|
+ "# Evaluating the model using the test dataset\n",
|
|
|
"\n",
|
|
|
"test_loss, test_acc = model.evaluate(test_images, test_labels, verbose=2)\n",
|
|
|
"\n",
|
|
@@ -375,14 +375,14 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
- "We get an Accuracy of 87% in the Test dataset which is less than the 89% we got during the Training phase, This problem in ML is called as Overfitting, and we have discussed the same in the previous notebook. \n",
|
|
|
+ "We get an accuracy of 87% on the test dataset, which is less than the 89% we got during the training phase. This problem in machine learning is called overfitting.\n",
|
|
|
"\n",
|
|
|
"## Exercise\n",
|
|
|
"\n",
|
|
|
- "Try adding more dense layers to the network above and observe change in accuracy.\n",
|
|
|
+ "Try adding more dense layers to the network above and observe the change in accuracy.\n",
|
|
|
"\n",
|
|
|
"## Important:\n",
|
|
|
- "<mark>Shutdown the kernel before clicking on “Next Notebook” to free up the GPU memory.</mark>\n",
|
|
|
+ "<mark>Shut down the kernel before clicking on “Next Notebook” to free up the GPU memory.</mark>\n",
|
|
|
"\n",
|
|
|
"\n",
|
|
|
"## Licensing\n",
|