2016-10-25 06:42:43 +03:00
{
"cells": [
2017-02-03 04:40:20 +03:00
{
"cell_type": "code",
2017-03-16 08:07:51 +03:00
"execution_count": 1,
2017-02-03 04:40:20 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.display import Image"
]
},
2016-10-25 06:42:43 +03:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-25 23:52:23 +03:00
"# CNTK 201B: Hands On Labs Image Recognition"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2017-05-04 05:23:25 +03:00
"This hands-on lab shows how to implement image recognition task using [convolution network][] with CNTK v2 Python API. You will start with a basic feedforward CNN architecture to classify [CIFAR dataset](https://www.cs.toronto.edu/~kriz/cifar.html), then you will keep adding advanced features to your network. Finally, you will implement a VGG net and residual net like the one that won ImageNet competition but smaller in size.\n",
2016-11-02 04:03:02 +03:00
"\n",
"[convolution network]:https://en.wikipedia.org/wiki/Convolutional_neural_network\n",
2016-10-25 06:42:43 +03:00
"\n",
"## Introduction\n",
"\n",
"In this hands-on, you will practice the following:\n",
"\n",
2016-10-26 09:34:40 +03:00
"* Understanding subset of CNTK python API needed for image classification task.\n",
2017-05-04 05:23:25 +03:00
"* Write a custom convolution network to classify CIFAR dataset.\n",
2016-10-25 06:42:43 +03:00
"* Modifying the network structure by adding:\n",
2016-11-02 04:03:02 +03:00
" * [Dropout][] layer.\n",
2016-10-25 06:42:43 +03:00
" * Batchnormalization layer.\n",
2016-11-02 04:03:02 +03:00
"* Implement a [VGG][] style network.\n",
2016-10-25 06:42:43 +03:00
"* Introduction to Residual Nets (RESNET).\n",
2016-11-02 04:03:02 +03:00
"* Implement and train [RESNET network][].\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-02 04:03:02 +03:00
"[RESNET network]:https://github.com/Microsoft/CNTK/wiki/Hands-On-Labs-Image-Recognition\n",
"[VGG]:http://www.robots.ox.ac.uk/~vgg/research/very_deep/\n",
"[Dropout]:https://en.wikipedia.org/wiki/Dropout_(neural_networks)\n",
2016-10-25 06:42:43 +03:00
"\n",
"## Prerequisites\n",
"\n",
2017-05-04 05:23:25 +03:00
"CNTK 201A hands-on lab, in which you will download and prepare CIFAR dataset is a prerequisites for this lab. This tutorial depends on CNTK v2, so before starting this lab you will need to install CNTK v2. Furthermore, all the tutorials in this lab are done in python, therefore, you will need a basic knowledge of Python. \n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-04 05:23:25 +03:00
"CNTK 102 lab is recommended but not a prerequisite for this tutorial. However, a basic understanding of Deep Learning is needed. Familiarity with basic convolution operations is highly desirable (Refer to CNTK tutorial 103D).\n",
2016-10-26 09:34:40 +03:00
"\n",
"## Dataset\n",
"\n",
2017-05-04 05:23:25 +03:00
"You will use CIFAR 10 dataset, from https://www.cs.toronto.edu/~kriz/cifar.html, during this tutorial. The dataset contains 50000 training images and 10000 test images, all images are 32 x 32 x 3. Each image is classified as one of 10 classes as shown below:"
2017-02-03 04:40:20 +03:00
]
},
{
"cell_type": "code",
"execution_count": 2,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/cifar-10.png\" width=\"500\" height=\"500\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 1\n",
"Image(url=\"https://cntk.ai/jup/201/cifar-10.png\", width=500, height=500)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 09:34:40 +03:00
"The above image is from: https://www.cs.toronto.edu/~kriz/cifar.html\n",
2016-10-25 06:42:43 +03:00
"\n",
"## Convolution Neural Network (CNN)\n",
"\n",
2017-05-04 05:23:25 +03:00
"We recommend completing CNTK 103D tutorial before proceeding. Here is a brief recap of Convolution Neural Network (CNN). CNN is a feedforward network comprise of a bunch of layers in such a way that the output of one layer is fed to the next layer (There are more complex architecture that skip layers, we will discuss one of those at the end of this lab). Usually, CNN start with alternating between convolution layer and pooling layer (downsample), then end up with fully connected layer for the classification part.\n",
2016-10-25 06:42:43 +03:00
"\n",
"### Convolution layer\n",
"\n",
2017-05-04 05:23:25 +03:00
"Convolution layer consist of multiple 2D convolution kernels applied on the input image or the previous layer, each convolution kernel outputs a feature map."
2017-02-03 04:40:20 +03:00
]
},
{
"cell_type": "code",
2017-03-16 08:07:51 +03:00
"execution_count": 3,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/Conv2D.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
2017-03-16 08:07:51 +03:00
"execution_count": 3,
2017-02-03 04:40:20 +03:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 2\n",
"Image(url=\"https://cntk.ai/jup/201/Conv2D.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The stack of feature maps output are the input to the next layer."
]
},
{
"cell_type": "code",
"execution_count": 4,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/Conv2DFeatures.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 3\n",
"Image(url=\"https://cntk.ai/jup/201/Conv2DFeatures.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 20:16:27 +03:00
"> Gradient-Based Learning Applied to Document Recognition, Proceedings of the IEEE, 86(11):2278-2324, November 1998\n",
"> Y. LeCun, L. Bottou, Y. Bengio and P. Haffner\n",
"\n",
2016-10-26 09:34:40 +03:00
"#### In CNTK:\n",
"\n",
2016-11-02 04:03:02 +03:00
"Here the [convolution][] layer in Python:\n",
2016-10-26 09:34:40 +03:00
"\n",
"```python\n",
"def Convolution(filter_shape, # e.g. (3,3)\n",
" num_filters, # e.g. 64\n",
" activation, # relu or None...etc.\n",
" init, # Random initialization\n",
" pad, # True or False\n",
" strides) # strides e.g. (1,1)\n",
"```\n",
"\n",
2016-11-02 04:03:02 +03:00
"[convolution]:https://www.cntk.ai/pythondocs/layerref.html#convolution\n",
"\n",
2016-10-25 06:42:43 +03:00
"### Pooling layer\n",
"\n",
"In most CNN vision architecture, each convolution layer is succeeded by a pooling layer, so they keep alternating until the fully connected layer. \n",
"\n",
"The purpose of the pooling layer is as follow:\n",
"\n",
"* Reduce the dimensionality of the previous layer, which speed up the network.\n",
"* Provide a limited translation invariant.\n",
"\n",
2017-02-03 04:40:20 +03:00
"Here an example of max pooling with a stride of 2:"
]
},
{
"cell_type": "code",
"execution_count": 5,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/MaxPooling.png\" width=\"400\" height=\"400\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 4\n",
"Image(url=\"https://cntk.ai/jup/201/MaxPooling.png\", width=400, height=400)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 09:34:40 +03:00
"#### In CNTK:\n",
"\n",
2016-11-02 04:03:02 +03:00
"Here the [pooling][] layer in Python:\n",
2016-10-26 09:34:40 +03:00
"\n",
"```python\n",
"\n",
"# Max pooling\n",
"def MaxPooling(filter_shape, # e.g. (3,3)\n",
" strides, # (2,2)\n",
" pad) # True or False\n",
"\n",
"# Average pooling\n",
"def AveragePooling(filter_shape, # e.g. (3,3)\n",
" strides, # (2,2)\n",
" pad) # True or False\n",
"```\n",
"\n",
2016-11-02 04:03:02 +03:00
"[pooling]:https://www.cntk.ai/pythondocs/layerref.html#maxpooling-averagepooling\n",
"\n",
2016-10-25 06:42:43 +03:00
"### Dropout layer\n",
"\n",
2017-05-04 05:23:25 +03:00
"Dropout layer takes a probability value as an input, the value is called the dropout rate. Let us say the dropout rate is 0.5, what this layer does it pick at random 50% of the nodes from the previous layer and drop them out of the network. This behavior help regularize the network.\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-10-26 20:16:27 +03:00
"> Dropout: A Simple Way to Prevent Neural Networks from Overfitting\n",
"> Nitish Srivastava, Geoffrey Hinton, Alex Krizhevsky, Ilya Sutskever, Ruslan Salakhutdinov\n",
"\n",
"\n",
"#### In CNTK:\n",
"\n",
"Dropout layer in Python:\n",
"\n",
2016-10-26 09:34:40 +03:00
"```python\n",
"\n",
"# Dropout\n",
"def Dropout(prob) # dropout rate e.g. 0.5\n",
"```\n",
"\n",
2016-10-25 06:42:43 +03:00
"### Batch normalization (BN)\n",
"\n",
"Batch normalization is a way to make the input to each layer has zero mean and unit variance. BN help the network converge faster and keep the input of each layer around zero. BN has two learnable parameters called gamma and beta, the purpose of those parameters is for the network to decide for itself if the normalized input is what is best or the raw input.\n",
"\n",
2016-10-26 20:16:27 +03:00
"> Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift\n",
"> Sergey Ioffe, Christian Szegedy\n",
"\n",
"#### In CNTK:\n",
"\n",
2016-11-02 04:03:02 +03:00
"[Batch normalization][] layer in Python:\n",
2016-10-26 20:16:27 +03:00
"\n",
2016-10-26 09:34:40 +03:00
"```python\n",
"\n",
"# Batch normalization\n",
"def BatchNormalization(map_rank) # For image map_rank=1\n",
"```\n",
"\n",
2016-11-02 04:03:02 +03:00
"[Batch normalization]:https://www.cntk.ai/pythondocs/layerref.html#batchnormalization-layernormalization-stabilizer\n",
"\n",
2017-02-03 04:40:20 +03:00
"## Microsoft Cognitive Network Toolkit (CNTK)\n",
2016-10-25 06:42:43 +03:00
"\n",
"CNTK is a highly flexible computation graphs, each node take inputs as tensors and produce tensors as the result of the computation. Each node is exposed in Python API, which give you the flexibility of creating any custom graphs, you can also define your own node in Python or C++ using CPU, GPU or both.\n",
"\n",
"For Deep learning, you can use the low level API directly or you can use CNTK layered API. We will start with the low level API, then switch to the layered API in this lab.\n",
"\n",
"So let's first import the needed modules for this lab."
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 6,
2016-10-25 06:42:43 +03:00
"metadata": {
2017-05-04 05:23:25 +03:00
"collapsed": true
2016-10-25 06:42:43 +03:00
},
"outputs": [],
"source": [
2017-05-04 05:23:25 +03:00
"from __future__ import print_function # Use a function definition from future version (say 3.x from 2.7 interpreter)\n",
2017-05-13 05:37:33 +03:00
"\n",
2016-10-25 06:42:43 +03:00
"import matplotlib.pyplot as plt\n",
"import math\n",
2017-05-13 05:37:33 +03:00
"import numpy as np\n",
"import os\n",
2017-05-16 22:15:54 +03:00
"import PIL\n",
2017-05-13 05:37:33 +03:00
"import sys\n",
2017-05-16 22:15:54 +03:00
"try: \n",
" from urllib.request import urlopen \n",
"except ImportError: \n",
" from urllib import urlopen\n",
2016-10-26 11:30:39 +03:00
"\n",
2017-05-13 05:37:33 +03:00
"import cntk as C"
2017-05-04 05:23:25 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the block below, we check if we are running this notebook in the CNTK internal test machines by looking for environment variables defined there. We then select the right target device (GPU vs CPU) to test this notebook. In other cases, we use CNTK's default policy to use the best available device (GPU, if available, else CPU)."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
2017-03-16 08:07:51 +03:00
"if 'TEST_DEVICE' in os.environ:\n",
" if os.environ['TEST_DEVICE'] == 'cpu':\n",
2017-05-20 03:36:18 +03:00
" C.device.try_set_default_device(C.device.cpu())\n",
2017-03-16 08:07:51 +03:00
" else:\n",
2017-05-20 03:36:18 +03:00
" C.device.try_set_default_device(C.device.gpu(0))"
2016-10-25 06:42:43 +03:00
]
},
2017-02-03 04:40:20 +03:00
{
"cell_type": "code",
2017-05-04 05:23:25 +03:00
"execution_count": 8,
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/CNN.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
2017-05-04 05:23:25 +03:00
"execution_count": 8,
2017-02-03 04:40:20 +03:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 5\n",
"Image(url=\"https://cntk.ai/jup/201/CNN.png\")"
]
},
2016-10-25 06:42:43 +03:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2017-02-03 04:40:20 +03:00
"Now that we imported the needed modules, let's implement our first CNN, as shown in Figure 5 above.\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-10-26 06:41:49 +03:00
"Let's implement the above network using CNTK layer API:"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-04 05:23:25 +03:00
"execution_count": 9,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model(input, out_dims):\n",
2017-05-04 05:23:25 +03:00
" with C.layers.default_options(init=C.glorot_uniform(), activation=C.relu):\n",
" net = C.layers.Convolution((5,5), 32, pad=True)(input)\n",
" net = C.layers.MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-04 05:23:25 +03:00
" net = C.layers.Convolution((5,5), 32, pad=True)(net)\n",
" net = C.layers.MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-04 05:23:25 +03:00
" net = C.layers.Convolution((5,5), 64, pad=True)(net)\n",
" net = C.layers.MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-26 06:41:49 +03:00
" \n",
2017-05-04 05:23:25 +03:00
" net = C.layers.Dense(64)(net)\n",
" net = C.layers.Dense(out_dims, activation=None)(net)\n",
2016-10-26 06:41:49 +03:00
" \n",
2016-10-25 06:42:43 +03:00
" return net"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-11-18 13:48:30 +03:00
"To train the above model we need two things:\n",
2016-10-26 06:41:49 +03:00
"* Read the training images and their corresponding labels.\n",
"* Define a cost function, compute the cost for each mini-batch and update the model weights according to the cost value.\n",
"\n",
"To read the data in CNTK, we will use CNTK readers which handle data augmentation and can fetch data in parallel.\n",
"\n",
"Example of a map text file:\n",
"\n",
2016-11-10 15:02:35 +03:00
" S:\\data\\CIFAR-10\\train\\00001.png\t9\n",
" S:\\data\\CIFAR-10\\train\\00002.png\t9\n",
" S:\\data\\CIFAR-10\\train\\00003.png\t4\n",
" S:\\data\\CIFAR-10\\train\\00004.png\t1\n",
" S:\\data\\CIFAR-10\\train\\00005.png\t1\n"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-04 05:23:25 +03:00
"execution_count": 10,
2017-05-16 02:41:38 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
2016-10-25 06:42:43 +03:00
"source": [
2017-05-13 05:37:33 +03:00
"# Determine the data path for testing\n",
"# Check for an environment variable defined in CNTK's test infrastructure\n",
"envvar = 'CNTK_EXTERNAL_TESTDATA_SOURCE_DIRECTORY'\n",
"def is_test(): return envvar in os.environ\n",
"\n",
"if is_test():\n",
2017-05-16 02:41:38 +03:00
" data_path = os.path.join(os.environ[envvar],'Image','CIFAR','v0','tutorial201')\n",
2017-05-15 23:57:56 +03:00
" data_path = os.path.normpath(data_path)\n",
2017-05-13 05:37:33 +03:00
"else:\n",
" data_path = os.path.join('data', 'CIFAR-10')\n",
"\n",
2016-10-25 06:42:43 +03:00
"# model dimensions\n",
"image_height = 32\n",
"image_width = 32\n",
"num_channels = 3\n",
"num_classes = 10\n",
"\n",
2017-05-04 05:23:25 +03:00
"import cntk.io.transforms as xforms \n",
2016-10-25 06:42:43 +03:00
"#\n",
"# Define the reader for both training and evaluation action.\n",
"#\n",
"def create_reader(map_file, mean_file, train):\n",
2017-05-16 02:41:38 +03:00
" print(\"Reading map file:\", map_file)\n",
" print(\"Reading mean file:\", mean_file)\n",
2017-05-13 05:37:33 +03:00
" \n",
2016-10-25 06:42:43 +03:00
" if not os.path.exists(map_file) or not os.path.exists(mean_file):\n",
2016-10-26 06:41:49 +03:00
" raise RuntimeError(\"This tutorials depends 201A tutorials, please run 201A first.\")\n",
2016-10-25 06:42:43 +03:00
"\n",
" # transformation pipeline for the features has jitter/crop only when training\n",
" transforms = []\n",
2017-05-04 05:23:25 +03:00
" # train uses data augmentation (translation only)\n",
2016-10-25 06:42:43 +03:00
" if train:\n",
" transforms += [\n",
2017-05-04 05:23:25 +03:00
" xforms.crop(crop_type='randomside', side_ratio=0.8) \n",
2016-10-25 06:42:43 +03:00
" ]\n",
" transforms += [\n",
2017-02-18 03:39:58 +03:00
" xforms.scale(width=image_width, height=image_height, channels=num_channels, interpolations='linear'),\n",
" xforms.mean(mean_file)\n",
2016-10-25 06:42:43 +03:00
" ]\n",
" # deserializer\n",
2017-05-04 05:23:25 +03:00
" return C.io.MinibatchSource(C.io.ImageDeserializer(map_file, C.io.StreamDefs(\n",
" features = C.io.StreamDef(field='image', transforms=transforms), # first column in map file is referred to as 'image'\n",
" labels = C.io.StreamDef(field='label', shape=num_classes) # and second as 'label'\n",
2016-10-25 06:42:43 +03:00
" )))"
]
},
2017-05-15 23:57:56 +03:00
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2017-05-16 02:41:38 +03:00
"Reading map file: c:\\Data\\CNTKTestData\\Image\\CIFAR\\v0\\tutorial201\\train_map.txt\n",
"Reading mean file: c:\\Data\\CNTKTestData\\Image\\CIFAR\\v0\\tutorial201\\CIFAR-10_mean.xml\n",
"Reading map file: c:\\Data\\CNTKTestData\\Image\\CIFAR\\v0\\tutorial201\\test_map.txt\n",
"Reading mean file: c:\\Data\\CNTKTestData\\Image\\CIFAR\\v0\\tutorial201\\CIFAR-10_mean.xml\n"
2017-05-15 23:57:56 +03:00
]
}
],
"source": [
"# Create the train and test readers\n",
"reader_train = create_reader(os.path.join(data_path, 'train_map.txt'), \n",
" os.path.join(data_path, 'CIFAR-10_mean.xml'), True)\n",
"reader_test = create_reader(os.path.join(data_path, 'test_map.txt'), \n",
" os.path.join(data_path, 'CIFAR-10_mean.xml'), False) "
]
},
2016-10-25 06:42:43 +03:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-11-18 13:48:30 +03:00
"Now let us write the the training and validation loop."
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 12,
2016-10-25 06:42:43 +03:00
"metadata": {
2017-05-04 05:23:25 +03:00
"collapsed": true
2016-10-25 06:42:43 +03:00
},
"outputs": [],
"source": [
"#\n",
"# Train and evaluate the network.\n",
"#\n",
"def train_and_evaluate(reader_train, reader_test, max_epochs, model_func):\n",
2016-11-02 04:03:02 +03:00
" # Input variables denoting the features and label data\n",
2017-05-12 03:00:07 +03:00
" input_var = C.input_variable((num_channels, image_height, image_width))\n",
" label_var = C.input_variable((num_classes))\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-01 06:03:17 +03:00
" # Normalize the input\n",
" feature_scale = 1.0 / 256.0\n",
2017-05-04 05:23:25 +03:00
" input_var_norm = C.element_times(feature_scale, input_var)\n",
2016-11-01 06:03:17 +03:00
" \n",
2016-10-25 06:42:43 +03:00
" # apply model to input\n",
2016-11-01 06:03:17 +03:00
" z = model_func(input_var_norm, out_dims=10)\n",
2016-10-25 06:42:43 +03:00
"\n",
" #\n",
" # Training action\n",
" #\n",
"\n",
" # loss and metric\n",
2017-05-04 05:23:25 +03:00
" ce = C.cross_entropy_with_softmax(z, label_var)\n",
" pe = C.classification_error(z, label_var)\n",
2016-10-25 06:42:43 +03:00
"\n",
" # training config\n",
" epoch_size = 50000\n",
" minibatch_size = 64\n",
"\n",
2016-11-03 10:42:00 +03:00
" # Set training parameters\n",
2017-05-04 05:23:25 +03:00
" lr_per_minibatch = C.learning_rate_schedule([0.01]*10 + [0.003]*10 + [0.001], \n",
" C.UnitType.minibatch, epoch_size)\n",
" momentum_time_constant = C.momentum_as_time_constant_schedule(-minibatch_size/np.log(0.9))\n",
2016-11-03 10:42:00 +03:00
" l2_reg_weight = 0.001\n",
2016-11-02 21:29:44 +03:00
" \n",
2016-10-25 06:42:43 +03:00
" # trainer object\n",
2017-05-04 05:23:25 +03:00
" learner = C.momentum_sgd(z.parameters, \n",
" lr = lr_per_minibatch, \n",
" momentum = momentum_time_constant, \n",
" l2_regularization_weight=l2_reg_weight)\n",
" progress_printer = C.logging.ProgressPrinter(tag='Training', num_epochs=max_epochs)\n",
" trainer = C.Trainer(z, (ce, pe), [learner], [progress_printer])\n",
2016-10-25 06:42:43 +03:00
"\n",
" # define mapping from reader streams to network inputs\n",
" input_map = {\n",
" input_var: reader_train.streams.features,\n",
" label_var: reader_train.streams.labels\n",
" }\n",
"\n",
2017-05-04 05:23:25 +03:00
" C.logging.log_number_of_parameters(z) ; print()\n",
2016-10-25 06:42:43 +03:00
"\n",
" # perform model training\n",
" batch_index = 0\n",
" plot_data = {'batchindex':[], 'loss':[], 'error':[]}\n",
" for epoch in range(max_epochs): # loop over epochs\n",
" sample_count = 0\n",
" while sample_count < epoch_size: # loop over minibatches in the epoch\n",
2017-05-04 05:23:25 +03:00
" data = reader_train.next_minibatch(min(minibatch_size, epoch_size - sample_count), \n",
" input_map=input_map) # fetch minibatch.\n",
2016-10-25 06:42:43 +03:00
" trainer.train_minibatch(data) # update model with it\n",
"\n",
" sample_count += data[label_var].num_samples # count samples processed so far\n",
" \n",
" # For visualization... \n",
" plot_data['batchindex'].append(batch_index)\n",
" plot_data['loss'].append(trainer.previous_minibatch_loss_average)\n",
" plot_data['error'].append(trainer.previous_minibatch_evaluation_average)\n",
" \n",
" batch_index += 1\n",
2017-02-23 03:37:37 +03:00
" trainer.summarize_training_progress()\n",
2016-10-25 06:42:43 +03:00
" \n",
" #\n",
" # Evaluation action\n",
" #\n",
" epoch_size = 10000\n",
" minibatch_size = 16\n",
"\n",
" # process minibatches and evaluate the model\n",
" metric_numer = 0\n",
" metric_denom = 0\n",
" sample_count = 0\n",
" minibatch_index = 0\n",
"\n",
" while sample_count < epoch_size:\n",
" current_minibatch = min(minibatch_size, epoch_size - sample_count)\n",
"\n",
" # Fetch next test min batch.\n",
" data = reader_test.next_minibatch(current_minibatch, input_map=input_map)\n",
"\n",
" # minibatch data to be trained with\n",
" metric_numer += trainer.test_minibatch(data) * current_minibatch\n",
" metric_denom += current_minibatch\n",
"\n",
" # Keep track of the number of samples processed so far.\n",
" sample_count += data[label_var].num_samples\n",
" minibatch_index += 1\n",
"\n",
" print(\"\")\n",
" print(\"Final Results: Minibatch[1-{}]: errs = {:0.1f}% * {}\".format(minibatch_index+1, (metric_numer*100.0)/metric_denom, metric_denom))\n",
" print(\"\")\n",
" \n",
" # Visualize training result:\n",
" window_width = 32\n",
" loss_cumsum = np.cumsum(np.insert(plot_data['loss'], 0, 0)) \n",
" error_cumsum = np.cumsum(np.insert(plot_data['error'], 0, 0)) \n",
"\n",
" # Moving average.\n",
" plot_data['batchindex'] = np.insert(plot_data['batchindex'], 0, 0)[window_width:]\n",
" plot_data['avg_loss'] = (loss_cumsum[window_width:] - loss_cumsum[:-window_width]) / window_width\n",
" plot_data['avg_error'] = (error_cumsum[window_width:] - error_cumsum[:-window_width]) / window_width\n",
" \n",
" plt.figure(1)\n",
" plt.subplot(211)\n",
" plt.plot(plot_data[\"batchindex\"], plot_data[\"avg_loss\"], 'b--')\n",
" plt.xlabel('Minibatch number')\n",
" plt.ylabel('Loss')\n",
" plt.title('Minibatch run vs. Training loss ')\n",
"\n",
" plt.show()\n",
"\n",
" plt.subplot(212)\n",
" plt.plot(plot_data[\"batchindex\"], plot_data[\"avg_error\"], 'r--')\n",
" plt.xlabel('Minibatch number')\n",
" plt.ylabel('Label Prediction Error')\n",
" plt.title('Minibatch run vs. Label Prediction Error ')\n",
2016-10-26 11:30:39 +03:00
" plt.show()\n",
" \n",
2017-05-04 05:23:25 +03:00
" return C.softmax(z)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 13,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 06:42:43 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-10-26 11:30:39 +03:00
"Training 116906 parameters in 10 parameter tensors.\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.127933 * 50000, metric = 77.96% * 50000 15.851s (3154.4 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.768975 * 50000, metric = 64.90% * 50000 11.970s (4177.1 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.589650 * 50000, metric = 58.28% * 50000 11.958s (4181.3 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.495402 * 50000, metric = 54.32% * 50000 11.960s (4180.6 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.421285 * 50000, metric = 51.41% * 50000 11.965s (4178.9 samples/s);\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-16 22:15:54 +03:00
"Final Results: Minibatch[1-626]: errs = 46.4% * 10000\n",
2016-10-25 06:42:43 +03:00
"\n"
]
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXmYVNW1t98fIIgREIegOKPJNY7g54DRKEJMFCMiRhNn\njVOMRqM316i50cQhMdcYBzRGcUjEgag4ICpKEJUhOAGCAgYFEVAmZZ4b1vfHOpWqbqq6q5uqrqp2\nvc9TzzlnT2ed3V1n1d5r7b1kZgRBEARBXTQrtQBBEARBZR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ZBEARFoWK8pAAk\nPQwsMLMrcuTvBAwDzjCzMbW006heUqNGwaGHNtrtgiAIikLFKIwkgNIbwEQ8ONIGAZQk9QP6ADPw\neN5rzeygLG2FW20QBEE9qRiFUUhKqTDeftu9qPbbryS3D4IgaDCVtA6jSfCvf8Gf/1xqKYIgCEpL\njDDy4OOP3d120CD3ogqCIKgUYkqqkTGD00+H996DCROgWYzLgiCoEGJKqpGR4OGHYc4cuPtuT+vU\nydPnzCmtbEEQBI1FKIw8ad7cY2scdpiPOGbP9vQirB0MgiAoS2JKaiMYNcoVyMqVsOmmpZYmCIJg\nQ8KGUUasWeMut0EQBOVI2DDKiJSymDIFHn/cFUiKTz4piUhBEARFoagKQ9IOkl6V9IGkiZIuzVHu\nTklTJY2X1LmYMhWLkSPh1FOhbVuforr1Vth1V3ipZHvvBkEQFJaSB1CSdAywm5l9A7gQ+GuRZSoK\nP/mJK4zVq+HKK2H//T29Z09YsKC0sgVBEBSCkgdQAo7Hw7hiZm8C7SR1KKZcxaBZM3j0UfjgA7jx\nRjjySFi71vNGj4ZVq3z
2016-10-25 06:42:43 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec6cb8f908>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXecFeX1/98fERELYC/YEmNDYyyxJDbEht1oLGgsmHzt\nMbaomIKx/NRYsWtiwd4bauyK2AsoSBNFUBBRlKYgbc/vjzOXO3v37t3Z5e7du3Ler9e8ZuaZZ57n\nzLN358x5yjkyM4IgCIKgIRZpaQGCIAiC1kEojCAIgiAToTCCIAiCTITCCIIgCDIRCiMIgiDIRCiM\nIAiCIBOhMKoMSTdI+ltj80raQdIXzSvd/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vmW1eAfnScli5\n++OCIAh+6kjCKjjo3TanLADMXRu3LUflQRAEQeshy6D3e5L+i7uGBjiM2q6RgyAIgoWALF1S7fCZ\nTNsmSQOA663CAUaiSyoIgqDxlLNLqqTCkAdCv8PMDitHZQtCKIwgCILGU7ExDPPIZGsm02qDIAiC\nhZgsYxij8TgJT+BrJQAwsyuaTaogCIKg6siiMD5NtkXwaGNBEATBQkhJhZGMYSxtZmc0tQJJ3fFo\nXYsAt5jZJQXXO+GRsNbGI5sdbWbDmlpfEARB0DxkGcPYpqmFJ7GUr8WDKG0I9EjiIKc5BxhkZr8C\njgTK5dgwCIIgKCNZFu59IOkJSYdL2j+3ZSx/S2CUmY1N/E/dhwdNStMFjy1MskBwrVzg+qIMHw6n\nnZax+iAIgqBcZFEYiwPfAt2AvZNtr4zlFwZIGkfdAEkfAvsDSNoSDzC/Wr0ljh4NV14JQ4dmFCEI\ngiAoB1m81Ta3B9mLgT6
2016-10-25 06:42:43 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec09a99e10>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2017-05-04 05:23:25 +03:00
"pred = train_and_evaluate(reader_train, \n",
" reader_test, \n",
" max_epochs=5, \n",
" model_func=create_basic_model)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 11:30:39 +03:00
"Although, this model is very simple, it still has too much code, we can do better. Here the same model in more terse format:"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 14,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
2016-10-26 06:41:49 +03:00
"def create_basic_model_terse(input, out_dims):\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-05-04 05:23:25 +03:00
" with C.layers.default_options(init=C.glorot_uniform(), activation=C.relu):\n",
" model = C.layers.Sequential([\n",
" C.layers.For(range(3), lambda i: [\n",
" C.layers.Convolution((5,5), [32,32,64][i], pad=True),\n",
" C.layers.MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
" C.layers.Dense(64),\n",
" C.layers.Dense(out_dims, activation=None)\n",
2016-10-26 06:41:49 +03:00
" ])\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-10-26 06:41:49 +03:00
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 15,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 116906 parameters in 10 parameter tensors.\n",
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 10]: [Training] loss = 2.064481 * 50000, metric = 75.90% * 50000 12.260s (4078.3 samples/s);\n",
"Finished Epoch[2 of 10]: [Training] loss = 1.703777 * 50000, metric = 63.17% * 50000 12.127s (4123.0 samples/s);\n",
"Finished Epoch[3 of 10]: [Training] loss = 1.561847 * 50000, metric = 57.11% * 50000 12.116s (4126.8 samples/s);\n",
"Finished Epoch[4 of 10]: [Training] loss = 1.463862 * 50000, metric = 53.17% * 50000 12.078s (4139.8 samples/s);\n",
"Finished Epoch[5 of 10]: [Training] loss = 1.374724 * 50000, metric = 49.49% * 50000 12.117s (4126.4 samples/s);\n",
"Finished Epoch[6 of 10]: [Training] loss = 1.294328 * 50000, metric = 46.14% * 50000 12.158s (4112.5 samples/s);\n",
"Finished Epoch[7 of 10]: [Training] loss = 1.231594 * 50000, metric = 43.62% * 50000 12.084s (4137.7 samples/s);\n",
"Finished Epoch[8 of 10]: [Training] loss = 1.179700 * 50000, metric = 41.84% * 50000 12.156s (4113.2 samples/s);\n",
"Finished Epoch[9 of 10]: [Training] loss = 1.136541 * 50000, metric = 39.93% * 50000 12.065s (4144.2 samples/s);\n",
"Finished Epoch[10 of 10]: [Training] loss = 1.096253 * 50000, metric = 38.56% * 50000 12.148s (4115.9 samples/s);\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-16 22:15:54 +03:00
"Final Results: Minibatch[1-626]: errs = 34.4% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXm4FNXR/z9fRBHcUDQgIKgQ5XVBwD0SRYyKGtHoqwbj\nrvmp0WjM5vZGoiYuCcYYjSbGJUZFxC2Ca1DRqLixI7iDC6uIAgLKWr8/qsfpO8xc5sLMvTOX+jzP\nPN3n9OnT1Q23q+vUqToyM4IgCIJgVTRpaAGCIAiC6iAURhAEQVAUoTCCIAiCogiFEQRBEBRFKIwg\nCIKgKEJhBEEQBEURCmMtRdItki6ta1tJ+0n6pLzSfXPdKZJ618e1GgPJv82EUrddDTlelHRSOfoO\nGpamDS1AUFokfQi0Adqa2eep+jHALsDWZvaxmZ1dbJ952q5W8I6kjsAUoKmZrVidPhoLknoCT+LP\nsgnQAlgAKKnbwcym1qVPM3sB2LnUbYMgQ1gYjQ/DX8r9MhWSdgKas5ov+hKSeRmq7BeS1in3NdYE\nM3vJzDYys42BHfHnskmmLldZKKFBhA2ChFAYjZO7gZNT5ZOBu9INJN0p6Ypkfz9Jn0j6uaRZkqZJ\nOiVf22yVLpY0W9JkScenDhwqabSkeZI+ktQ/dd4LyXaupPmS9kzO+bGkSUndm5K6pc7pLmmcpC8k\n3SdpvXw3LOlkSS9J+pOk2UB/Sf0l3Z1q01HSCklNkvJwSVck582X9JSkzQr0P0nSoanyOpI+ldRN\nUjNJd0v6LJHzNUlb5OtnFdRQCMnQzhWSRuDWx1aSTk89q/cknZ5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H84x9wzjmw7rpet2JF+DaC\nIGhchMIoMbvtBqNGwWu
2016-10-25 23:52:23 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec09b867b8>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXecFEX2wL8PBAEJZkwkUcwJFT0Dcnh6eCqcZ0D0zPDz\nDOeZ03mip57hzGLCiHoGjIAeigGUMyKgoCIiWUUEyVFg3++PV830zM7M9i6zs7Pyvp9Pf7q6urrq\nde9sv656Ve+JquI4juM4FVGnpgVwHMdxageuMBzHcZxEuMJwHMdxEuEKw3Ecx0mEKwzHcRwnEa4w\nHMdxnES4wigxROR+Efl7ZcuKyEEiMr16pVvd7mQR6VyMtmobIlImIlsX+9o1Jd52ZX6DWepZKCKt\nCymbUzq4wigSIjJFRJaJyIYZ+aPDP2tLAFU9S1VvSFJnlrJVWlQjIq2CDP57YI2fx5osbMp5rYgM\nE5GlIrJARH4SkRdFpPkatJWz7aS/QREZKiKnp1Wi2kRVpxRQrqitKSKyJNz/wrC/u9DtOPnxF0Tx\nUGAy0CPKEJGdgYas2UumEEiQQaq9IZG61d1Ggajq32RNnmG+axU4W1WbAu2A9YE7slZSNUVX7X/7\nNUSBw1W1aVBKTVX1vGwFs/3GKvu7q0W/06LiCqO4PAmcEjs+BegXLyAij4nIP0P6IBGZLiIXishM\nEfleRE7NVjaVJVeIyCwRmSQiJ8RO/EFERonIfBGZKiK9Y9e9G/bzwpfbPuGaXiLyVcj7QkR2j12z\nh4h8LiJzReQZEamf7YZF5BQR+Z+I3C4is4DeItJbRJ6MlUn7og9frv8M1y0Qkdcze2axa78SkT/E\njuuGL/DdRWRdEXlSRGYHOT8WkU2y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/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec10332128>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2017-05-04 05:23:25 +03:00
"pred_basic_model = train_and_evaluate(reader_train, \n",
" reader_test, \n",
" max_epochs=10, \n",
" model_func=create_basic_model_terse)"
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2017-05-16 22:15:54 +03:00
"Now that we have a trained model, let us classify the following image of a truck. We use PIL to read the image."
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 16,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/00014.png\" width=\"64\" height=\"64\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
2017-05-15 23:57:56 +03:00
"execution_count": 16,
2017-02-03 04:40:20 +03:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 6\n",
"Image(url=\"https://cntk.ai/jup/201/00014.png\", width=64, height=64)"
]
},
{
"cell_type": "code",
2017-05-15 23:57:56 +03:00
"execution_count": 17,
2016-10-26 11:30:39 +03:00
"metadata": {
2017-05-04 05:23:25 +03:00
"collapsed": true
2016-10-26 11:30:39 +03:00
},
"outputs": [],
"source": [
2017-05-16 22:15:54 +03:00
"# Download a sample image \n",
"# (this is 00014.png from test dataset)\n",
"# Any image of size 32,32 can be evaluated\n",
2016-10-26 11:30:39 +03:00
"\n",
2017-05-16 22:15:54 +03:00
"url = \"https://cntk.ai/jup/201/00014.png\"\n",
"myimg = np.array(PIL.Image.open(urlopen(url)), dtype=np.float32)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"During training we have subtracted the mean from the input images. Here we take an approximate value of the mean and subtract it from the image."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def eval(pred_op, image_data):\n",
2016-10-26 11:30:39 +03:00
" label_lookup = [\"airplane\", \"automobile\", \"bird\", \"cat\", \"deer\", \"dog\", \"frog\", \"horse\", \"ship\", \"truck\"]\n",
2017-05-16 22:15:54 +03:00
" image_mean = 133.0\n",
" image_data -= image_mean\n",
" image_data = np.ascontiguousarray(np.transpose(image_data, (2, 0, 1)))\n",
2016-11-02 04:03:02 +03:00
" \n",
2017-05-16 22:15:54 +03:00
" result = np.squeeze(pred_op.eval({pred_op.arguments[0]:[image_data]}))\n",
2016-11-02 04:03:02 +03:00
" \n",
" # Return top 3 results:\n",
" top_count = 3\n",
" result_indices = (-np.array(result)).argsort()[:top_count]\n",
2016-10-26 11:30:39 +03:00
"\n",
2016-11-02 04:03:02 +03:00
" print(\"Top 3 predictions:\")\n",
" for i in range(top_count):\n",
" print(\"\\tLabel: {:10s}, confidence: {:.2f}%\".format(label_lookup[result_indices[i]], result[result_indices[i]] * 100))"
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 19,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-26 11:30:39 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-11-02 04:03:02 +03:00
"Top 3 predictions:\n",
2017-05-16 22:15:54 +03:00
"\tLabel: truck , confidence: 96.59%\n",
"\tLabel: ship , confidence: 2.31%\n",
"\tLabel: cat , confidence: 0.43%\n"
2016-10-26 11:30:39 +03:00
]
}
],
"source": [
2017-05-16 22:15:54 +03:00
"# Run the evaluation on the downloaded image\n",
"eval(pred_basic_model, myimg)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 09:34:40 +03:00
"Adding dropout layer, with drop rate of 0.25, before the last dense layer:"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 20,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
2016-10-26 06:41:49 +03:00
"def create_basic_model_with_dropout(input, out_dims):\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-04 05:23:25 +03:00
" with C.layers.default_options(activation=C.relu, init=C.glorot_uniform()):\n",
" model = C.layers.Sequential([\n",
" C.layers.For(range(3), lambda i: [\n",
" C.layers.Convolution((5,5), [32,32,64][i], pad=True),\n",
" C.layers.MaxPooling((3,3), strides=(2,2))\n",
2016-10-26 06:41:49 +03:00
" ]),\n",
2017-05-04 05:23:25 +03:00
" C.layers.Dense(64),\n",
" C.layers.Dropout(0.25),\n",
" C.layers.Dense(out_dims, activation=None)\n",
2016-10-26 06:41:49 +03:00
" ])\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-10-26 06:41:49 +03:00
" return model(input)"
2016-10-25 23:52:23 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 21,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-10-26 06:41:49 +03:00
"Training 116906 parameters in 10 parameter tensors.\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.107245 * 50000, metric = 79.08% * 50000 12.977s (3853.0 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.795581 * 50000, metric = 67.10% * 50000 12.244s (4083.6 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.657041 * 50000, metric = 61.52% * 50000 12.265s (4076.6 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.567592 * 50000, metric = 57.72% * 50000 12.251s (4081.3 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.500142 * 50000, metric = 54.97% * 50000 12.228s (4089.0 samples/s);\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-16 22:15:54 +03:00
"Final Results: Minibatch[1-626]: errs = 47.1% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXeYVOX1xz9fQAgqoNhQELA3VEBFY2NFjb38NJhgiT1q\nbIkldkFNsEWNNREjqChixYJdBDs2QBBRsVBEUUSqgFLO749zxxmW2d3ZZWZndjmf55nn3vve9773\n3Hd37pnznnPeV2ZGEARBEFRFg2ILEARBENQNQmEEQRAEOREKIwiCIMiJUBhBEARBToTCCIIgCHIi\nFEYQBEGQE6EwVlAk/UfSJdWtK6mrpMmFle7X+34lqVtt3Ks+kPxtxuS7bg3keF3SnwrRdlBcGhVb\ngCC/SJoAtALWM7MfM8pHAtsC7c1skpmdlmubWerWKHlHUjvgK6CRmS2pSRv1BUm7As/hfdkAWBmY\nCygp29LMvq5Om2b2KrB1vusGQYqwMOofhr+Ue6QKJHUAmlLDF30eSb0MVfAbSQ0LfY/lwczeMLNm\nZtYc2ArvlxapsvLKQglFETYIEkJh1E/6A8dmHB8L3JtZQVI/SVcm+10lTZZ0jqTvJE2RdFy2uuki\nXSRpmqQvJR2ZcWJ/SSMkzZI0UVLPjOteTbYzJc2WtGNyzcmSPk7KPpLUMeOaTpI+lDRD0oOSGmd7\nYEnHSnpD0o2SpgE9JfWU1D+jTjtJSyQ1SI6HSroyuW62pOcltayg/Y8l7Z9x3FDS95I6Smoiqb+k\nHxI535G0VrZ2qmAphZAM7Vwp6S3c+lhf0okZfTVe0okZ9feU9FXG8WRJf5M0OpHrAUkrVbducv4i\nSd8m9U5K+rFtlQ/kXC5pgqSpkvpKapaca5r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03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec1f9b5630>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZMAAACfCAYAAAA8qTSuAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXecFdX1wL9HQAQpdhQLKIpEsKGisSIRxVijwYCx19h7\nIfEnscRuLDEaVFQswRgbNhSNHRFQQDqIFBWQJiCdBc7vj3OHN+/t27ez+97uvoXz/XzmMzN3bjkz\n+3bO3HvPPUdUFcdxHMfJhw1qWgDHcRyn9uPKxHEcx8kbVyaO4zhO3rgycRzHcfLGlYnjOI6TN65M\nHMdxnLxxZVJLEJHHROQvFc0rIoeJyA9VK93adqeISKfqaKu2ISJrRGSn6i6bL/G2K/IbzFLPIhFp\nWUjZnOLClUkNIyJTRWS5iGyWkT48/CPvAKCqF6nq35LUmSVvpRYTiUiLIIP/Tsj7eeSzoKvMsiLy\nsYgsE5FfRGS2iLwiIs3yaKvMtpP+BkXkIxE5J60S1caqOrWAckVtTRWRpeH+F4X9w4Vuxykff0nU\nPApMAbpHCSLSDmhAfi+gQiBBBqnyhkTqVHUbBaKyf5N8nmGusgpcrKpNgNbAJsADWSupnBKs8r99\nnihwjKo2CQqriapeni1jtt9YRX93teh3Wu24MikOngPOjJ2fCfSJZxCRp0Xk1nB8mIj8ICJXi8gs\nEZkuImdly5tKkh4iMkdEJovIqbELvxWRYSKyUESmiUjPWLlPwn5B+OLbP5Q5X0TGhrTRIrJXrMze\nIvKNiMwXkb4ismG2GxaRM0XkcxH5u4jMAXqKSE8ReS6WJ60nEL54bw3lfhGRdzN7dLGyY0Xkt7Hz\nOuHLfS8RqS8iz4nI3CDnYBHZMls9SRGR/UTki1DfdBH5h4jUzch2jIh8F+S4J6P8OUHmeSLSP+qR\nJm0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ec1f9ccb38>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2017-05-04 05:23:25 +03:00
"pred_basic_model_dropout = train_and_evaluate(reader_train, \n",
" reader_test, \n",
" max_epochs=5, \n",
" model_func=create_basic_model_with_dropout)"
2016-10-25 23:52:23 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-26 09:34:40 +03:00
"Add batch normalization after each convolution and before the last dense layer:"
2016-10-25 23:52:23 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 22,
2016-10-25 23:52:23 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
2016-10-26 06:41:49 +03:00
"def create_basic_model_with_batch_normalization(input, out_dims):\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-04 05:23:25 +03:00
" with C.layers.default_options(activation=C.relu, init=C.glorot_uniform()):\n",
" model = C.layers.Sequential([\n",
" C.layers.For(range(3), lambda i: [\n",
" C.layers.Convolution((5,5), [32,32,64][i], pad=True),\n",
" C.layers.BatchNormalization(map_rank=1),\n",
" C.layers.MaxPooling((3,3), strides=(2,2))\n",
2016-10-25 06:42:43 +03:00
" ]),\n",
2017-05-04 05:23:25 +03:00
" C.layers.Dense(64),\n",
" C.layers.BatchNormalization(map_rank=1),\n",
" C.layers.Dense(out_dims, activation=None)\n",
2016-10-25 06:42:43 +03:00
" ])\n",
"\n",
2016-10-26 06:41:49 +03:00
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 23,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-10-26 06:41:49 +03:00
"Training 117290 parameters in 18 parameter tensors.\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 1.536584 * 50000, metric = 55.22% * 50000 12.978s (3852.7 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.215455 * 50000, metric = 43.35% * 50000 12.196s (4099.7 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.092067 * 50000, metric = 38.66% * 50000 12.260s (4078.3 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.011021 * 50000, metric = 35.57% * 50000 12.330s (4055.2 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 0.952613 * 50000, metric = 33.38% * 50000 12.286s (4069.7 samples/s);\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-16 22:15:54 +03:00
"Final Results: Minibatch[1-626]: errs = 30.1% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXmYVNW1t9+fqIgBBYMTouAQTBSNccIZJc4aNSbG6Cdx\niMYYFaNXY9BcUHON93rVkGgSr3PEoHEWNYojKhpwAASZkRYQBUERZRTo9f2xTlnV3VXVVU1VV3Wz\n3uepp87ZZ52919nQZ9Xaa++1ZWYEQRAEQWOsU2kFgiAIgpZBGIwgCIKgIMJgBEEQBAURBiMIgiAo\niDAYQRAEQUGEwQiCIAgKIgzGWoqkv0m6slhZSb0lzS6vdl+3WyOpT3O01RpI/m3Gl1q2CXq8Juln\n5ag7qCzrVlqBoLRI+gDYAuhiZp9llI8Bvgt0N7NZZnZeoXVmkW3S4h1J3YAaYF0zq21KHa0FSQcA\nz+B9uQ6wIbAYUFK2k5l9WEydZvYKsEupZYMgRXgYrQ/DX8qnpAok9QTa0cQXfQlJvQxV9oakNuVu\nY00wsxFm1sHMN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SDwZBEAQF0dKGpMrCypVwxx2V1iIIgmDtocV6GKtXw0Ybwdy50KFDBRUL\ngiCoYsLDANq0gaVL4Z57Kq1JEATB2kG5c0ndKWmepHE5rm8kaWiSQ2q8pDOKqf/oo+H++0uiahAE\nQdAI5Z4ldQCwGLjXzHbNcr0/sJGZ9ZfUGZgCbG5mDXa7yBb0njkTuneH+fNj5XcQBEE2WsyQlJmN\nABbmEwFSEYgOwKfZjEUuunWDc87x4akuXaBv3zVQNgiCIMhLc6z07gY8mcPDaI8v3Ps20B442cye\nyVFP3mm1ffrAyy9DbS2
2016-10-25 23:52:23 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec25a34e80>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXfYFNX1xz9fCygKNlSiYm9Rf/aWaASNNcaaWDCxRmM3\nGmPsYjSJmsRujLFhS+y9Y0ONBRVEUUFUQKWoiIgoiMh7fn+cGXbeZXffWdh3333hfJ5nnpm5c+fe\ns3d358y995x7ZGYEQRAEQUvM09YCBEEQBO2DUBhBEARBLkJhBEEQBLkIhREEQRDkIhRGEARBkItQ\nGEEQBEEuQmE0GJL+Jen0avNK6iHp49aVbka9IyRtU4+62huSmiStXO97Z5ds3dX8BkuUM0nSirWU\nLWgcQmHUCUkjJX0rafGi9NeTP+vyAGZ2pJn9JU+ZJfLOklONpBUSGeL3wGy3x+w4NpW9V1I/SVMk\nfSXpM0l3S1p6NuoqW3fe36CkZyQd0qwQs85mNrKGcqV1jZQ0Ofn8k5L9ZbWuJ6hMPCDqhwEjgF5p\ngqR1gAWZvYdMLVAig1q9Imne1q6jRszqdzI7bVjpXgOOMrMuwOrAosDFJQuZN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qducxjmkclWSMxqgyAIgrmYPHMYw/E4CQ/gkdIAMLOLWk2qIAiCoOHIozA+SLZ58GhjQRAEwVxI\nRYWRzGF0NrM/zGoFOQIodcEtsJYH5gUuNLMbZrW+IAiCoHXIYyX1kpn9aJYK9wBKw4Cf4mFDXwX2\nNbOhmTynAl3M7FRJXYF3gaXN7PuismLSOwiCoEpqOemdZ0hqUDJ/cSfN5zDyLEg4I4ASgKQ0gNLQ\nTB6jMNTVGRhfrCyCIAi
2016-10-25 23:52:23 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec09a89860>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2017-05-04 05:23:25 +03:00
"pred_basic_model_bn = train_and_evaluate(reader_train, \n",
" reader_test, \n",
" max_epochs=5, \n",
" model_func=create_basic_model_with_batch_normalization)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's implement an inspired VGG style network, using layer API, here the architecture:\n",
"\n",
"| VGG9 |\n",
"| ------------- |\n",
"| conv3-64 |\n",
"| conv3-64 |\n",
"| max3 |\n",
"| |\n",
"| conv3-96 |\n",
"| conv3-96 |\n",
"| max3 |\n",
"| |\n",
"| conv3-128 |\n",
"| conv3-128 |\n",
"| max3 |\n",
"| |\n",
"| FC-1024 |\n",
"| FC-1024 |\n",
"| |\n",
"| FC-10 |\n"
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 24,
2017-05-13 05:37:33 +03:00
"metadata": {
"collapsed": true
},
2016-10-25 06:42:43 +03:00
"outputs": [],
"source": [
"def create_vgg9_model(input, out_dims):\n",
2017-05-04 05:23:25 +03:00
" with C.layers.default_options(activation=C.relu, init=C.glorot_uniform()):\n",
" model = C.layers.Sequential([\n",
" C.layers.For(range(3), lambda i: [\n",
" C.layers.Convolution((3,3), [64,96,128][i], pad=True),\n",
" C.layers.Convolution((3,3), [64,96,128][i], pad=True),\n",
" C.layers.MaxPooling((3,3), strides=(2,2))\n",
2016-10-25 06:42:43 +03:00
" ]),\n",
2017-05-04 05:23:25 +03:00
" C.layers.For(range(2), lambda : [\n",
" C.layers.Dense(1024)\n",
2016-10-25 06:42:43 +03:00
" ]),\n",
2017-05-04 05:23:25 +03:00
" C.layers.Dense(out_dims, activation=None)\n",
2016-10-25 06:42:43 +03:00
" ])\n",
2016-10-26 06:41:49 +03:00
" \n",
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 25,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 2675978 parameters in 18 parameter tensors.\n",
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.267064 * 50000, metric = 84.67% * 50000 18.672s (2677.8 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.877782 * 50000, metric = 69.81% * 50000 12.578s (3975.2 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.689757 * 50000, metric = 63.07% * 50000 12.729s (3928.0 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.564912 * 50000, metric = 57.57% * 50000 12.536s (3988.5 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.475126 * 50000, metric = 53.79% * 50000 13.171s (3796.2 samples/s);\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-16 02:41:38 +03:00
"Final Results: Minibatch[1-626]: errs = 50.1% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHN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c1zo0bBHnvA7rs3\nvVxBELQ8YpZUidOqVe3KAmDmTDjwQDj3XLdOgiAIyoWCKgxJW0t6UdJUSZMlXVBLnZMkvZt8xkja\nrZAyFZthw+Ctt2DjjWHwYDj5ZHj33WJLFQRBUD+lkEBpJrC/me2B5/u9vcAyFZ1ttnG/x9tvQ+fO\noTCCICgPmtSHIelxYLiZvZDl/EbAZDOrMceonHwYQRAEpUJZ+jCyJVCqxtnAM00hTxAEQdAwSiGB\nUqrOIOAMYL9s7fzud7/7Zn/gwIHNMviXGRx3HAwf7osLgyAIGsLLL7/Myy+/XJC2Cz4klSRQegp4\nJltODEm7A48Ch5jZR1nqtJghqfPO83UdTz+dfUFiEARBLpTbkFSdCZQk9cCVxanZlEVLY/hwX8Xe\nqZMvAgyCICgFCmphJAmUXgUm48mRaiRQknQ7cAwwB8/nvcbM+tXSVouxMMAVxoAB8OabsHAhbLZZ\nsSUKgqAciZXeLQQzGDkSjjrK120EQRA0lFAYQRAEQU6Umw8jCIIgaAaEwigTKivhX/8qthRBELRk\nQmGUCWvXwmGHwfvvF1uSIAhaKqEwyoQ2beCnP4Xrriu2JEEQtFTC6V1GLFzomf2eeQb22qvY0gRB\nUA6E07uFsvnmcPHFvj4jCIKgqQkLo8yYOxd69vSUsa3LLiN7EARNTdlYGLkkUErq3SzpA0kTJfUp\npEzlTo8evqAvlEUQBE1N0RMoSToU2M7MdgDOAf5SYJmaDWvWwJlnwiuvFFuSIAhaAkVPoCTpL8BL\nZva35Hg6MNDMFla7Noa
2016-10-25 23:52:23 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec0f89f588>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-05-16 22:15:54 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFU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jAkVeGOwcbjKyE3lHSUuXO7II+qqqrG\nFiEVIWdpaQpyNgUZIeSsZGpduCfpQ+BQMxudpLsAj5rZ9mWQL1cOK/V4XBAEwfKOJKyMRu8WGWUB\nYO7auEUpGg+CIAiaDmkUxgeS7kkcuVVJupvqrpGLImkvSaMkjZF0boHza0h6Uh69bWDGMVsQBEFQ\nWaQZkloFOBnYNcl6A7jdUgQYSbyEjsEje03CHc0dbGajcspcA8wys0sTL5h/N7OlIoDFkFQQBEHd\nKduQlDwQ+n1mdoOZHZBsN6ZRFgndgbHmEa4W4J4998srsyXuNZNk6GsjpY27fMEFoPBIHARBUA6K\nKgzzyGQdk2m19SE/ktgEqkfcAvgIOACWxA/ugEdJq53hwzOC1lO8IAiCIC1pFu6Nw+Mk9McjpQFg\nZjeUSIar8LCVg4BheLzidCE0OybBsyZNgvb5eqgO/PADrLYafPQRdO1a/3qCIAiWY9IojE+TbSU8\n2lhdmEg22Ap4z6FaiEYzm4VHoANA0me4klqKPn36QN++0KIFVbfeStUtt8Ann8CcOXUUK4977/V9\nu3bFywVBEFQ4AwYMYMCAAQ1Sd1Gjd2LDuNrMzqpX5X79aNzoPRl4DzjEzEbmlGkLzDEPHXocsIuZ\nHV2gLjd6n3EGPP44TFyW0MB5XHstTJ4MN9wAbdrACy/ALruUrv4gCIJGomxG78SGUe83Z3L9KXh4\nyI/x+LkjJf1R0vFJsS2
2016-10-25 23:52:23 +03:00
"text/plain": [
2017-05-16 22:15:54 +03:00
"<matplotlib.figure.Figure at 0x2ec10398ef0>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2017-05-04 05:23:25 +03:00
"pred_vgg = train_and_evaluate(reader_train, \n",
" reader_test, \n",
" max_epochs=5, \n",
" model_func=create_vgg9_model)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Residual Network (ResNet)\n",
"\n",
2017-05-04 05:23:25 +03:00
"One of the main problem of a Deep Neural Network is how to propagate the error all the way to the first layer. For a deep network, the gradients keep getting smaller until it has no effect on the network weights. [ResNet](https://arxiv.org/abs/1512.03385) was designed to overcome such problem, by defining a block with identity path, as shown below:"
2017-02-03 04:40:20 +03:00
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 26,
2017-05-04 05:23:25 +03:00
"metadata": {},
2017-02-03 04:40:20 +03:00
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/ResNetBlock2.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
2017-05-16 22:15:54 +03:00
"execution_count": 26,
2017-02-03 04:40:20 +03:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 7\n",
"Image(url=\"https://cntk.ai/jup/201/ResNetBlock2.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-10-25 06:42:43 +03:00
"The idea of the above block is 2 folds:\n",
"\n",
2017-05-04 05:23:25 +03:00
"* During back propagation the gradients have a path that does not affect its magnitude.\n",
2016-10-25 06:42:43 +03:00
"* The network need to learn residual mapping (delta to x).\n",
"\n",
"So let's implements ResNet blocks using CNTK:\n",
"\n",
" ResNetNode ResNetNodeInc\n",
" | |\n",
" +------+------+ +---------+----------+\n",
" | | | |\n",
" V | V V\n",
" +----------+ | +--------------+ +----------------+\n",
" | Conv, BN | | | Conv x 2, BN | | SubSample, BN |\n",
" +----------+ | +--------------+ +----------------+\n",
" | | | |\n",
" V | V |\n",
" +-------+ | +-------+ |\n",
" | ReLU | | | ReLU | |\n",
" +-------+ | +-------+ |\n",
" | | | |\n",
" V | V |\n",
" +----------+ | +----------+ |\n",
" | Conv, BN | | | Conv, BN | |\n",
" +----------+ | +----------+ |\n",
" | | | |\n",
" | +---+ | | +---+ |\n",
" +--->| + |<---+ +------>+ + +<-------+\n",
" +---+ +---+\n",
" | |\n",
" V V\n",
" +-------+ +-------+\n",
" | ReLU | | ReLU |\n",
" +-------+ +-------+\n",
" | |\n",
" V V\n"
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 27,
2017-05-13 05:37:33 +03:00
"metadata": {
"collapsed": true
},
2016-10-25 06:42:43 +03:00
"outputs": [],
"source": [
2017-05-04 05:23:25 +03:00
"def convolution_bn(input, filter_size, num_filters, strides=(1,1), init=C.he_normal(), activation=C.relu):\n",
2016-10-26 06:41:49 +03:00
" if activation is None:\n",
" activation = lambda x: x\n",
" \n",
2017-05-04 05:23:25 +03:00
" r = C.layers.Convolution(filter_size, \n",
" num_filters, \n",
" strides=strides, \n",
" init=init, \n",
" activation=None, \n",
" pad=True, bias=False)(input)\n",
" r = C.layers.BatchNormalization(map_rank=1)(r)\n",
2016-10-26 06:41:49 +03:00
" r = activation(r)\n",
" \n",
" return r\n",
"\n",
2016-10-25 06:42:43 +03:00
"def resnet_basic(input, num_filters):\n",
2016-11-01 06:03:17 +03:00
" c1 = convolution_bn(input, (3,3), num_filters)\n",
" c2 = convolution_bn(c1, (3,3), num_filters, activation=None)\n",
2016-10-25 06:42:43 +03:00
" p = c2 + input\n",
2017-05-04 05:23:25 +03:00
" return C.relu(p)\n",
2016-10-25 06:42:43 +03:00
"\n",
"def resnet_basic_inc(input, num_filters):\n",
2016-11-01 06:03:17 +03:00
" c1 = convolution_bn(input, (3,3), num_filters, strides=(2,2))\n",
" c2 = convolution_bn(c1, (3,3), num_filters, activation=None)\n",
2016-10-26 06:41:49 +03:00
"\n",
2016-11-01 06:03:17 +03:00
" s = convolution_bn(input, (1,1), num_filters, strides=(2,2), activation=None)\n",
2016-10-25 06:42:43 +03:00
" \n",
" p = c2 + s\n",
2017-05-04 05:23:25 +03:00
" return C.relu(p)\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-02 04:03:02 +03:00
"def resnet_basic_stack(input, num_filters, num_stack):\n",
" assert (num_stack > 0)\n",
" \n",
" r = input\n",
" for _ in range(num_stack):\n",
" r = resnet_basic(r, num_filters)\n",
" return r"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's write the full model:"
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 28,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_resnet_model(input, out_dims):\n",
2016-11-02 04:03:02 +03:00
" conv = convolution_bn(input, (3,3), 16)\n",
2016-11-02 21:29:44 +03:00
" r1_1 = resnet_basic_stack(conv, 16, 3)\n",
2016-10-25 06:42:43 +03:00
"\n",
" r2_1 = resnet_basic_inc(r1_1, 32)\n",
2016-11-02 04:03:02 +03:00
" r2_2 = resnet_basic_stack(r2_1, 32, 2)\n",
2016-10-25 06:42:43 +03:00
"\n",
" r3_1 = resnet_basic_inc(r2_2, 64)\n",
2016-11-02 04:03:02 +03:00
" r3_2 = resnet_basic_stack(r3_1, 64, 2)\n",
2016-10-25 06:42:43 +03:00
"\n",
" # Global average pooling\n",
2017-05-04 05:23:25 +03:00
" pool = C.layers.AveragePooling(filter_shape=(8,8), strides=(1,1))(r3_2) \n",
" net = C.layers.Dense(out_dims, init=C.he_normal(), activation=None)(pool)\n",
2016-10-25 06:42:43 +03:00
" \n",
" return net"
]
},
{
"cell_type": "code",
2017-05-16 22:15:54 +03:00
"execution_count": 29,
2017-05-04 05:23:25 +03:00
"metadata": {},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-11-02 21:29:44 +03:00
"Training 272474 parameters in 65 parameter tensors.\n",
2016-10-25 23:52:23 +03:00
"\n",
2017-05-04 05:23:25 +03:00
"Learning rate per minibatch: 0.01\n",
"Momentum per sample: 0.9983550962823424\n",
2017-05-16 22:15:54 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 1.895607 * 50000, metric = 70.00% * 50000 24.547s (2036.9 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.594962 * 50000, metric = 59.18% * 50000 21.075s (2372.5 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.456406 * 50000, metric = 53.31% * 50000 21.631s (2311.5 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.354717 * 50000, metric = 49.36% * 50000 20.848s (2398.3 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.275108 * 50000, metric = 45.98% * 50000 21.164s (2362.5 samples/s);\n",
"\n",
"Final Results: Minibatch[1-626]: errs = 43.9% * 10000\n",
"\n"
2016-10-25 23:52:23 +03:00
]
2017-05-16 22:15:54 +03:00
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXe4lNW1/z9fkapYCHZs0VgQVPSKDRUxWKKAMTEGjaKJ\n0URjfRIN5v7EknajKbbkCooFry0aFSwxKmAXCyAIFhQFBKlSVepZvz/WO85wmJkzAzNnZg7r8zzz\nnF3Wu9/17nPOu2bvtffaMjOCIAiCoCE2qLQCQRAEQW0QBiMIgiAoiDAYQRAEQUGEwQiCIAgKIgxG\nEARBUBBhMIIgCIKCCIOxniLpH5J+U6yspCMkTSuvdl/f92NJPRrjXk2B5HczvtSya6HHi5LOKEfb\nQWXZsNIKBKVF0ifA1sC2ZvZ5RvkYYB9gJzObamY/L7TNLLJrtXlH0o7Ax8CGZla3Nm00FSR1A57C\n+3IDoA2wBFBS1tHMPi2mTTN7HuhcatkgSBEjjKaH4S/lvqkCSZ2A1qzli76EpF6GKvuNpGblvse6\nYGYvmVlbM9sE2Avvl01TZfWNhRIqomwQJITBaJoMAfpl5PsBd2UKSLpD0jVJ+ghJ0yRdKmmWpOmS\nzswmmy5Sf0lzJE2WdGpGxXckjZa0UNIUSQMyrns++blA0iJJBybX/FTSxKTsHUn7ZlzTRdLbkuZL\nuk9Si2wPLKmfpJck/UXSHGCApAGShmTI7CipTtIGSX6EpGuS6x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2ekMYjCAIgkoQBiMIgiAoiLIaDEkdJA2XNEHSeEkX\n5pE9QNIKSSc11G6HDtCqVWl1DYIgCPJT8dAgidwGwDPAV8BgM/tXlrYiNEgQBEGR1Myy2gJDgwBc\ngG/sm11OfYIgCIK1p+K
"text/plain": [
"<matplotlib.figure.Figure at 0x2ec0f8674e0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAACfCAYAAADqDO7LAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXe4FdXVh98fCiKiYO+9i7GLGpOI5LPEEqPG2BJrbDGx\npKhoEvQzRjTG8lmiRCyxEWKLaCyJiC0qShGUIkoTRERUBBG9wPr+WHM4c88959y5l3PPPRfW+zzz\nzMyePXuv2ffcWbP3XmttmRlBEARB0BjtWluAIAiCoG0QCiMIgiDIRCiMIAiCIBOhMIIgCIJMhMII\ngiAIMhEKIwiCIMhEKIwaQ9JfJF3S1LyS9pH0fstKt7jeiZJ6VqOutoakRZI2q/a9S0q67qb8BouU\nM0fSJpWULagdQmFUCUmTJM2XtFpB+vDkn3UjADM7y8yuyFJmkbzNcqqRtHEiQ/weWOL2WBLHppL3\nShos6UtJn0v6SNJDktZegrpK1p31NyjpOUmn1CvEbGUzm1RBuXJ1TZI0L3n+Ocn+/ypdT1CeeEFU\nDwMmAsfmEiRtD6zIkr1kKoESGdTiFUnLtXQdFaK5f5MlacNy9xrwMzNbBdgK6ApcV7SQ5im6Fv/b\nLyEGHGxmqyRKaRUzO6dYxmK/sab+7trQ77SqhMKoLvcAJ6bOTwTuTmeQdKek/02O95H0vqRfSpoh\naZqkk4rlzSepl6SZkiZIOi514SBJwyTNljRZUu/Ufc8n+8+SL7c9kntOkzQ6SXtL0k6pe3aW9Kak\nTyU9IKlDsQeWdKKklyRdK2km0FtSb0n3pPLU+6JPvlz/N7nvc0lPFfbMUveOlnRQ6ny55At8J0kr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Yt/UH8Oo7kB\nCZtFAyupww93r++vv4b
"text/plain": [
"<matplotlib.figure.Figure at 0x2ec2b341b00>"
]
},
"metadata": {},
"output_type": "display_data"
2016-10-25 23:52:23 +03:00
}
],
2016-10-25 06:42:43 +03:00
"source": [
2016-10-26 20:16:27 +03:00
"pred_resnet = train_and_evaluate(reader_train, reader_test, max_epochs=5, model_func=create_resnet_model)"
2016-10-25 06:42:43 +03:00
]
2017-02-03 04:40:20 +03:00
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
2016-10-25 06:42:43 +03:00
}
],
"metadata": {
2017-03-16 08:07:51 +03:00
"anaconda-cloud": {},
2016-10-25 06:42:43 +03:00
"kernelspec": {
2017-05-04 05:23:25 +03:00
"display_name": "Python 3",
2016-10-25 06:42:43 +03:00
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2017-02-03 04:40:20 +03:00
"version": "3.5.2"
2016-10-25 06:42:43 +03:00
}
},
"nbformat": 4,
"nbformat_minor": 1
}