CNTK/Tutorials/CNTK_201B_CIFAR-10_ImageHan...

1285 строки
327 KiB
Plaintext
Исходник Обычный вид История

2016-10-25 06:42:43 +03:00
{
"cells": [
2017-02-03 04:40:20 +03:00
{
"cell_type": "code",
"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": [
"# CNTK 201B: Hands On Labs Image Recognition"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2016-11-18 13:48:30 +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 in order to classify Cifar dataset, then you will keep adding advanced feature to your network. Finally, you will implement a VGG net and residual net similar to 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",
"* Understanding subset of CNTK python API needed for image classification task.\n",
2016-10-25 06:42:43 +03:00
"* Write a custom convolution network to classify Cifar dataset.\n",
"* 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",
2016-11-18 13:48:30 +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",
"CNTK 102 lab is recommended but not a prerequisites for this tutorials. However, a basic understanding of Deep Learning is needed.\n",
"\n",
"## Dataset\n",
"\n",
2017-02-03 04:40:20 +03:00
"You will use Cifar 10 dataset, from https://www.cs.toronto.edu/~kriz/cifar.html, during this tutorials. The dataset contains 50000 training images and 10000 test images, all images are 32x32x3. Each image is classified as one of 10 classes as shown below:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"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": [
"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",
"Convolution Neural Network (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",
"\n",
"### Convolution layer\n",
"\n",
2017-02-03 04:40:20 +03:00
"Convolution layer consist of multiple 2D convolution kernels applied on the input image or the previous layer, each convolution kernel output a feature map."
]
},
{
"cell_type": "code",
"execution_count": 3,
2017-02-03 04:40:20 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/Conv2D.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"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,
"metadata": {
"collapsed": false
},
"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",
"#### In CNTK:\n",
"\n",
2016-11-02 04:03:02 +03:00
"Here the [convolution][] layer in Python:\n",
"\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,
"metadata": {
"collapsed": false
},
"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": [
"#### In CNTK:\n",
"\n",
2016-11-02 04:03:02 +03:00
"Here the [pooling][] layer in Python:\n",
"\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",
"Dropout layer takes a probability value as an input, the value is called the dropout rate. Let's say the dropu 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 nework. This behavior help regularize the network.\n",
"\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",
"```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",
"```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-02-03 04:40:20 +03:00
"collapsed": false
2016-10-25 06:42:43 +03:00
},
"outputs": [],
"source": [
2016-12-19 15:49:05 +03:00
"from __future__ import print_function\n",
"import os\n",
2016-10-25 06:42:43 +03:00
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import math\n",
2016-10-26 11:30:39 +03:00
"\n",
"import cntk as C\n",
2017-02-10 03:06:36 +03:00
"from cntk.layers import default_options, Convolution, MaxPooling, AveragePooling, Dropout, BatchNormalization, Dense, Sequential, For\n",
2016-10-25 06:42:43 +03:00
"from cntk.io import MinibatchSource, ImageDeserializer, StreamDef, StreamDefs\n",
HTK deserializers and Reader Transforms Squashed commit of the following: commit f0250727423dcea2fa138e519562fc868b60633e Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:36:10 2017 -0800 fix a typo commit 87d4a2119fc0011bb3199c9dcefead913a92b358 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:23:20 2017 -0800 Moved C++ test to use HTK deserializers commit 7b52fe1e5de282787e3e59d1a798336976f3d331 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:07:23 2017 -0800 final api for htk deserializers commit e21495f3db074e2fa95ac30933925ed30262a7ba Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 15:19:20 2017 -0800 test commit e3951291d060acad2caf49e3a4d6781da354835a Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:45:06 2017 -0800 fix commit 3096607bd2fcbaa93e970daccdb503e29ac4d37c Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:27:27 2017 -0800 Incorporated CR feedback. commit 2e3c9d31fa1e4dc141fbc6f2ca3ce69d1b5ad855 Merge: 3e116ed e70eac3 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:45:00 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 3e116ed79d35d788c5326eef4d93ad39f715983f Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:43:48 2017 -0800 typo fix commit 02587a5ef53ded988621ab9759f4507f69b72933 Merge: a01c137 721a6f7 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:25:48 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit a01c13727aeb4788ddebdfdbd05b64319dd08443 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:05:41 2017 -0800 Removed dead code commit 1e6f6f9c30edeea27d7f7fdd01baeaf8a3d590ec Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:56:10 2017 -0800 Updated examples that use transforms commit b40c71667300d0803e38f5b78cd8b68a6c5dd70d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:43:12 2017 -0800 pytests pass commit a6f6af04d854f0a2cefc2f20142cf0164fadde32 Merge: 7bc0893 df46851 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:21:07 2017 -0800 Merge branch 'mudithtk' into nikosk/iocleanup commit 7bc08937eeee000682afe28405143896c563940b Merge: d9b5fdf 0bf2f46 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:12:14 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit df468513c53a2a5189172045a6df91a699a564a8 Merge: 0bf2f46 15737ef Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:03:57 2017 -0800 Merge branch 'muditj/HTKDeserializerPythonWrapper' of https://github.com/MSharman/CNTK into mudithtk commit d9b5fdf0ebab2ff4175d7ae27d1e3cc52d1c195d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:01:46 2017 -0800 Various fixes commit 45d149ef1013fc118de142d96c19110753331aab Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:16:47 2017 -0800 added docs for HTK deserializers commit 3baaaf019dd95990f2f8962e35b9bbd0f37f768b Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:00:54 2017 -0800 update htk test to conform to new trainer commit 9a39a41be1d2d553f9730dde1912eecbe0805dfb Merge: 05d211b fd2e796 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:54:09 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 05d211b3ffcb58c98f71d717b79cb8f30bada060 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:45:41 2017 -0800 HTK deserializers working properly with a test commit 910580b3df72f15846c9a3e65dced1b121c0a192 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 22:03:03 2017 -0800 cleanup commit bb17ae40818ca901d6c2fc09fd692be947e7bdc9 Merge: c920260 b159781 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:53:22 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit c92026038a6a194f996f7e64261378eb563d9659 Merge: 1db7eb8 74fa7f4 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:50:33 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 1db7eb832f6c878aeb46faa015d21e55780bc219 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 17:24:58 2017 -0800 All tests work commit af6ee5af9ddd95677192f997a134276834cec537 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Wed Feb 8 22:34:18 2017 -0800 All tests that should pass pass commit 15737ef8437f8c47413f7479ba2549320fb4f0a6 Author: Mudit Jain <muditj@microsoft.com> Date: Tue Feb 7 13:45:41 2017 -0800 Add Htkfeature and mlf deserializers commit a8941ac82e8a028f4444e64e3dd826cbbe266761 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Feb 6 10:14:15 2017 -0800 image deserializer in C++ commit b599a14189a2c36b9a9c14df5d58fa8c577046b9 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Jan 30 17:39:10 2017 -0800 Image transforms in c++
2017-02-18 03:39:58 +03:00
"import cntk.io.transforms as xforms \n",
2016-11-02 04:03:02 +03:00
"from cntk.initializer import glorot_uniform, he_normal\n",
2016-10-25 06:42:43 +03:00
"from cntk import Trainer\n",
"from cntk.learners import momentum_sgd, learning_rate_schedule, UnitType, momentum_as_time_constant_schedule\n",
"from cntk import cross_entropy_with_softmax, classification_error, relu, input, softmax, element_times\n",
"from cntk.logging import *\n",
"\n",
"# Use CPU in test environment.\n",
"if 'TEST_DEVICE' in os.environ:\n",
" if os.environ['TEST_DEVICE'] == 'cpu':\n",
" C.device.set_default_device(C.device.cpu())\n",
" else:\n",
" C.device.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",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/CNN.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 7,
"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",
"Let's implement the above network using CNTK layer API:"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 8,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model(input, out_dims):\n",
" \n",
" net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=True)(input)\n",
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
" net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=True)(net)\n",
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
" net = Convolution((5,5), 64, init=glorot_uniform(), activation=relu, pad=True)(net)\n",
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
" \n",
" net = Dense(64, init=glorot_uniform())(net)\n",
" net = Dense(out_dims, init=glorot_uniform(), activation=None)(net)\n",
" \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",
"* 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-02-03 04:40:20 +03:00
"execution_count": 9,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
2016-10-25 06:42:43 +03:00
},
"outputs": [],
"source": [
"# model dimensions\n",
"image_height = 32\n",
"image_width = 32\n",
"num_channels = 3\n",
"num_classes = 10\n",
"\n",
"#\n",
"# Define the reader for both training and evaluation action.\n",
"#\n",
"def create_reader(map_file, mean_file, train):\n",
" if not os.path.exists(map_file) or not os.path.exists(mean_file):\n",
" 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",
" if train:\n",
" transforms += [\n",
HTK deserializers and Reader Transforms Squashed commit of the following: commit f0250727423dcea2fa138e519562fc868b60633e Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:36:10 2017 -0800 fix a typo commit 87d4a2119fc0011bb3199c9dcefead913a92b358 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:23:20 2017 -0800 Moved C++ test to use HTK deserializers commit 7b52fe1e5de282787e3e59d1a798336976f3d331 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:07:23 2017 -0800 final api for htk deserializers commit e21495f3db074e2fa95ac30933925ed30262a7ba Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 15:19:20 2017 -0800 test commit e3951291d060acad2caf49e3a4d6781da354835a Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:45:06 2017 -0800 fix commit 3096607bd2fcbaa93e970daccdb503e29ac4d37c Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:27:27 2017 -0800 Incorporated CR feedback. commit 2e3c9d31fa1e4dc141fbc6f2ca3ce69d1b5ad855 Merge: 3e116ed e70eac3 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:45:00 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 3e116ed79d35d788c5326eef4d93ad39f715983f Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:43:48 2017 -0800 typo fix commit 02587a5ef53ded988621ab9759f4507f69b72933 Merge: a01c137 721a6f7 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:25:48 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit a01c13727aeb4788ddebdfdbd05b64319dd08443 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:05:41 2017 -0800 Removed dead code commit 1e6f6f9c30edeea27d7f7fdd01baeaf8a3d590ec Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:56:10 2017 -0800 Updated examples that use transforms commit b40c71667300d0803e38f5b78cd8b68a6c5dd70d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:43:12 2017 -0800 pytests pass commit a6f6af04d854f0a2cefc2f20142cf0164fadde32 Merge: 7bc0893 df46851 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:21:07 2017 -0800 Merge branch 'mudithtk' into nikosk/iocleanup commit 7bc08937eeee000682afe28405143896c563940b Merge: d9b5fdf 0bf2f46 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:12:14 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit df468513c53a2a5189172045a6df91a699a564a8 Merge: 0bf2f46 15737ef Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:03:57 2017 -0800 Merge branch 'muditj/HTKDeserializerPythonWrapper' of https://github.com/MSharman/CNTK into mudithtk commit d9b5fdf0ebab2ff4175d7ae27d1e3cc52d1c195d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:01:46 2017 -0800 Various fixes commit 45d149ef1013fc118de142d96c19110753331aab Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:16:47 2017 -0800 added docs for HTK deserializers commit 3baaaf019dd95990f2f8962e35b9bbd0f37f768b Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:00:54 2017 -0800 update htk test to conform to new trainer commit 9a39a41be1d2d553f9730dde1912eecbe0805dfb Merge: 05d211b fd2e796 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:54:09 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 05d211b3ffcb58c98f71d717b79cb8f30bada060 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:45:41 2017 -0800 HTK deserializers working properly with a test commit 910580b3df72f15846c9a3e65dced1b121c0a192 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 22:03:03 2017 -0800 cleanup commit bb17ae40818ca901d6c2fc09fd692be947e7bdc9 Merge: c920260 b159781 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:53:22 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit c92026038a6a194f996f7e64261378eb563d9659 Merge: 1db7eb8 74fa7f4 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:50:33 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 1db7eb832f6c878aeb46faa015d21e55780bc219 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 17:24:58 2017 -0800 All tests work commit af6ee5af9ddd95677192f997a134276834cec537 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Wed Feb 8 22:34:18 2017 -0800 All tests that should pass pass commit 15737ef8437f8c47413f7479ba2549320fb4f0a6 Author: Mudit Jain <muditj@microsoft.com> Date: Tue Feb 7 13:45:41 2017 -0800 Add Htkfeature and mlf deserializers commit a8941ac82e8a028f4444e64e3dd826cbbe266761 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Feb 6 10:14:15 2017 -0800 image deserializer in C++ commit b599a14189a2c36b9a9c14df5d58fa8c577046b9 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Jan 30 17:39:10 2017 -0800 Image transforms in c++
2017-02-18 03:39:58 +03:00
" xforms.crop(crop_type='randomside', side_ratio=0.8) # train uses data augmentation (translation only)\n",
2016-10-25 06:42:43 +03:00
" ]\n",
" transforms += [\n",
HTK deserializers and Reader Transforms Squashed commit of the following: commit f0250727423dcea2fa138e519562fc868b60633e Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:36:10 2017 -0800 fix a typo commit 87d4a2119fc0011bb3199c9dcefead913a92b358 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:23:20 2017 -0800 Moved C++ test to use HTK deserializers commit 7b52fe1e5de282787e3e59d1a798336976f3d331 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 16:07:23 2017 -0800 final api for htk deserializers commit e21495f3db074e2fa95ac30933925ed30262a7ba Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 15:19:20 2017 -0800 test commit e3951291d060acad2caf49e3a4d6781da354835a Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:45:06 2017 -0800 fix commit 3096607bd2fcbaa93e970daccdb503e29ac4d37c Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 14:27:27 2017 -0800 Incorporated CR feedback. commit 2e3c9d31fa1e4dc141fbc6f2ca3ce69d1b5ad855 Merge: 3e116ed e70eac3 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:45:00 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 3e116ed79d35d788c5326eef4d93ad39f715983f Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Fri Feb 17 09:43:48 2017 -0800 typo fix commit 02587a5ef53ded988621ab9759f4507f69b72933 Merge: a01c137 721a6f7 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:25:48 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit a01c13727aeb4788ddebdfdbd05b64319dd08443 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 20:05:41 2017 -0800 Removed dead code commit 1e6f6f9c30edeea27d7f7fdd01baeaf8a3d590ec Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:56:10 2017 -0800 Updated examples that use transforms commit b40c71667300d0803e38f5b78cd8b68a6c5dd70d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 19:43:12 2017 -0800 pytests pass commit a6f6af04d854f0a2cefc2f20142cf0164fadde32 Merge: 7bc0893 df46851 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:21:07 2017 -0800 Merge branch 'mudithtk' into nikosk/iocleanup commit 7bc08937eeee000682afe28405143896c563940b Merge: d9b5fdf 0bf2f46 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 12:12:14 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit df468513c53a2a5189172045a6df91a699a564a8 Merge: 0bf2f46 15737ef Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:03:57 2017 -0800 Merge branch 'muditj/HTKDeserializerPythonWrapper' of https://github.com/MSharman/CNTK into mudithtk commit d9b5fdf0ebab2ff4175d7ae27d1e3cc52d1c195d Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 16 10:01:46 2017 -0800 Various fixes commit 45d149ef1013fc118de142d96c19110753331aab Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:16:47 2017 -0800 added docs for HTK deserializers commit 3baaaf019dd95990f2f8962e35b9bbd0f37f768b Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 17:00:54 2017 -0800 update htk test to conform to new trainer commit 9a39a41be1d2d553f9730dde1912eecbe0805dfb Merge: 05d211b fd2e796 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:54:09 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 05d211b3ffcb58c98f71d717b79cb8f30bada060 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Sat Feb 11 16:45:41 2017 -0800 HTK deserializers working properly with a test commit 910580b3df72f15846c9a3e65dced1b121c0a192 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 22:03:03 2017 -0800 cleanup commit bb17ae40818ca901d6c2fc09fd692be947e7bdc9 Merge: c920260 b159781 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:53:22 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit c92026038a6a194f996f7e64261378eb563d9659 Merge: 1db7eb8 74fa7f4 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 21:50:33 2017 -0800 Merge remote-tracking branch 'origin/master' into nikosk/iocleanup commit 1db7eb832f6c878aeb46faa015d21e55780bc219 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Thu Feb 9 17:24:58 2017 -0800 All tests work commit af6ee5af9ddd95677192f997a134276834cec537 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Wed Feb 8 22:34:18 2017 -0800 All tests that should pass pass commit 15737ef8437f8c47413f7479ba2549320fb4f0a6 Author: Mudit Jain <muditj@microsoft.com> Date: Tue Feb 7 13:45:41 2017 -0800 Add Htkfeature and mlf deserializers commit a8941ac82e8a028f4444e64e3dd826cbbe266761 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Feb 6 10:14:15 2017 -0800 image deserializer in C++ commit b599a14189a2c36b9a9c14df5d58fa8c577046b9 Author: Nikos Karampatziakis <nikosk@microsoft.com> Date: Mon Jan 30 17:39:10 2017 -0800 Image transforms in c++
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",
" return MinibatchSource(ImageDeserializer(map_file, StreamDefs(\n",
" features = StreamDef(field='image', transforms=transforms), # first column in map file is referred to as 'image'\n",
" labels = StreamDef(field='label', shape=num_classes) # and second as 'label'\n",
" )))"
]
},
{
"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-02-03 04:40:20 +03:00
"execution_count": 10,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"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",
" # Normalize the input\n",
" feature_scale = 1.0 / 256.0\n",
" input_var_norm = element_times(feature_scale, input_var)\n",
" \n",
2016-10-25 06:42:43 +03:00
" # apply model to input\n",
" 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",
" ce = cross_entropy_with_softmax(z, label_var)\n",
" pe = classification_error(z, label_var)\n",
"\n",
" # training config\n",
" epoch_size = 50000\n",
" minibatch_size = 64\n",
"\n",
" # Set training parameters\n",
2016-11-18 13:48:30 +03:00
" lr_per_minibatch = learning_rate_schedule([0.01]*10 + [0.003]*10 + [0.001], UnitType.minibatch, epoch_size)\n",
2016-11-02 21:29:44 +03:00
" momentum_time_constant = momentum_as_time_constant_schedule(-minibatch_size/np.log(0.9))\n",
" 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",
" learner = momentum_sgd(z.parameters, \n",
" lr = lr_per_minibatch, momentum = momentum_time_constant, \n",
" l2_regularization_weight=l2_reg_weight)\n",
" progress_printer = ProgressPrinter(tag='Training', num_epochs=max_epochs)\n",
" trainer = 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",
" log_number_of_parameters(z) ; print()\n",
"\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",
" data = reader_train.next_minibatch(min(minibatch_size, epoch_size - sample_count), input_map=input_map) # fetch minibatch.\n",
" 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",
" 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",
" return softmax(z)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 11,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"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-03-29 12:07:15 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.063247 * 50000, metric = 0.00% * 50000 15.936s (3137.6 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.679241 * 50000, metric = 0.00% * 50000 13.449s (3717.7 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.522509 * 50000, metric = 0.00% * 50000 13.370s (3739.7 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.426424 * 50000, metric = 0.00% * 50000 13.371s (3739.4 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.342300 * 50000, metric = 0.00% * 50000 13.441s (3720.0 samples/s);\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 42.8% * 10000\n",
2016-10-25 06:42:43 +03:00
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvDQgoCqhR7AUriFHB2EVj75hY166xBUuC\nJb72kqIxdsUWLFhYTexGETR2iQ1UULFSROmC2ACBvd8/7jPO2WG2l5md/X2ua64zpz/PnIG596nm\n7oiIiIgUizaFToCIiIhImoITERERKSoKTkRERKSoKDgRERGRoqLgRERERIqKghMREREpKgpORERE\npKgoOBEREZGiouBEREREioqCEykJZlZhZ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6HE9+HkVMPb+8ysA9EL7Cui5ORU4I0kaIJoazKU6LE0m+hm\nvA9wZT3SJa2IghMpNrX5SzPfmBANndck3/VOJcYWuRRYgugt9PMYK+4+y8z2JsY4+TPxn++9RDfT\nYTnXuxnYhPhB/SNRNP4fd68wsz2JH5hM49+viSBlTC3yV9t85z0mycP+wDVEkDKeGGdkfRYPThqa\nBoAniLYdnajcSyfjemA/oitsB+JzOg+4Ks8966q6c/Lmwd3fN7ODiOd7NfEjfC1R6nNzLe5R1T2r\n+hxre+7P+9z9ITM7EriQeIYfE0Fyf2CVvFeo5t7u/oOZbU+My3IsMe7OWOBwd08/s7uJtiT9iaBt\nChEsXpo65lpiAMLdiec5nuhKfV0t0yWtlDW8Z6GIiBSbZHTYT9y9X40HixSZgrc5MbNzLYbh/tZi\neOhHzSxfY6yqzt/WYmjsUU2ZThGRYmQx5H+bnG17EAO5vVCYVIk0TMFLTizmoignRh9sRwx33Avo\n4e75uj6mz+1C1E1/CnR
2016-10-25 06:42:43 +03:00
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a6cc7d588>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXecVOXVx78/EJAiIBIBW2zYK2DvXaPGGhV7iQ01ir4x\n5lWjxkSNRn3tJUaxJNh7JagoKrbFLnZBDAoixQJI2fP+ce44d4fZ3ZnZ2d3Z3fP9fO7n3vvU88yd\ncuY85zmPzIwgCIIgCIJKoV1zCxAEQRAEQZAmlJMgCIIgCCqKUE6CIAiCIKgoQjkJgiAIgqCiCOUk\nCIIgCIKKIpSTIAiCIAgqilBOgiAIgiCoKEI5CYIgCIKgogjlJAiCIAiCiiKUk6AoJFVL+lOJdc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8aC+0stI+no3MqSFk0Urqbmblz2hULDS2qfWJDAnWzn46t40gwtoI+xuIJ2Sqq9\nfPyY9Fvn80umOkcAe0jKTDchqQ+++ma0mdU1NVsRtJZxBE5YTtouNcyvZnZ7cwkCdMQdCO/GfQiO\nx79IHk3yX8ItD7cpGyL9YPL/M6wC9pN0Kb5E9oekndvw5Z2XJTEPRuPLhbcDrjGzcilltZm17wT+\nBjyYjKEr/uP7Ib5qqtzcBdyB//g/lePgC/C+pFH46zUN2AB35kyHoN8LX2V0OP761ccgSWfmSX+W\n4p4h+Kqc0yUtj/sQHACsAxydsnzdTnaJ8TbAi7hSuzo+lbUjWUWmSTCz5yXdAJwhaT38x3Iebr3a\nF18Sfn/iW/L3pNyjuCK+PrAz+ad+fn5fmZlJOh54GHhTHtPkK/yzs4aZ7ZIUrUrqXSXpKXzlzl21\niH4W7pT6oqRrcWXyGPy
2016-10-25 06:42:43 +03:00
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a0f1d9e10>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"data_path = os.path.join('data', 'CIFAR-10')\n",
"reader_train = create_reader(os.path.join(data_path, 'train_map.txt'), os.path.join(data_path, 'CIFAR-10_mean.xml'), True)\n",
"reader_test = create_reader(os.path.join(data_path, 'test_map.txt'), os.path.join(data_path, 'CIFAR-10_mean.xml'), False)\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-10-26 11:30:39 +03:00
"pred = train_and_evaluate(reader_train, reader_test, max_epochs=5, 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-02-03 04:40:20 +03:00
"execution_count": 12,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model_terse(input, out_dims):\n",
2016-10-25 06:42:43 +03:00
"\n",
" with default_options(activation=relu):\n",
" model = Sequential([\n",
2017-02-10 03:06:36 +03:00
" For(range(3), lambda i: [\n",
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
" Dense(64, init=glorot_uniform()),\n",
" Dense(out_dims, init=glorot_uniform(), activation=None)\n",
" ])\n",
2016-10-25 06:42:43 +03:00
"\n",
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 13,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 116906 parameters in 10 parameter tensors.\n",
"\n",
2017-03-29 12:07:15 +03:00
"Finished Epoch[1 of 10]: [Training] loss = 2.056384 * 50000, metric = 0.00% * 50000 13.728s (3642.2 samples/s);\n",
"Finished Epoch[2 of 10]: [Training] loss = 1.692674 * 50000, metric = 0.00% * 50000 13.455s (3716.1 samples/s);\n",
"Finished Epoch[3 of 10]: [Training] loss = 1.542460 * 50000, metric = 0.00% * 50000 13.473s (3711.1 samples/s);\n",
"Finished Epoch[4 of 10]: [Training] loss = 1.449036 * 50000, metric = 0.00% * 50000 13.502s (3703.2 samples/s);\n",
"Finished Epoch[5 of 10]: [Training] loss = 1.372120 * 50000, metric = 0.00% * 50000 13.380s (3736.9 samples/s);\n",
"Finished Epoch[6 of 10]: [Training] loss = 1.305663 * 50000, metric = 0.00% * 50000 13.409s (3728.8 samples/s);\n",
"Finished Epoch[7 of 10]: [Training] loss = 1.245300 * 50000, metric = 0.00% * 50000 13.296s (3760.5 samples/s);\n",
"Finished Epoch[8 of 10]: [Training] loss = 1.184832 * 50000, metric = 0.00% * 50000 13.946s (3585.3 samples/s);\n",
"Finished Epoch[9 of 10]: [Training] loss = 1.140430 * 50000, metric = 0.00% * 50000 13.577s (3682.7 samples/s);\n",
"Finished Epoch[10 of 10]: [Training] loss = 1.106576 * 50000, metric = 0.00% * 50000 13.371s (3739.4 samples/s);\n",
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 35.2% * 10000\n",
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XmcVfP/wPHXu7RoJxS+hRJKRFn6okLWKGVtCsXXGl+E\nr+/XWvYvfpU12VUYO5UsIUvEl6ZkKaHFUmmRJm1a5v37432Oe+6dOzO3aWbunTvv5+NxH+eecz7n\nnM/n3ql5z2cVVcU555xzLlNUS3cGnHPOOeeiPDhxzjnnXEbx4MQ555xzGcWDE+ecc85lFA9OnHPO\nOZdRPDhxzjnnXEbx4MQ555xzGcWDE+ecc85lFA9OnHPOOZdRPDhxWUFECkTkhlJeO09EHo/s9wvu\n177sclh6IrJTkJ/L050XVzQR+VREXi/ltc+KyMyyzlOKzy51vp0rLx6cuIwRCQoKROSgItL8HJwf\nm3BKg1dpFCS5tkzXdRCRHBG5tCzv6YomIk9EfpaKez1e8t1Stjk/g4r9HKaDr2HiMs4W6c6Ac0ms\nAfoAk6MHRaQLsCOwNsk1WwIbSvm83Sn/Xwx9gD2Be8r5Oc6MAN6O7O8C3AQ8DEyKHJ9dhs/sROl/\n0Z8OSBnmxblKzYMTl4leB04RkUtUNRo09AGmANskXqCq60r7MFVdX9prKysRqaOqq9Odj/Kiqv8D\n/hfui0gH4GbgE1V9JpV7iEhtVU0WCBf1zNIGx6jqxtJe61w28mYdl2kUyAUaA0eGB0WkBnAy8AxJ\n/sJM7HMiIoODYy1F5EkR+V1ElovI4yJSO+HaeUVU79cVkYdEZKmI5IvISBFplHBtDxF5TUTmi8ha\nEflBRK4TkWqRNO8BxwF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.figure.Figure at 0x21a0f22b278>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFNXSgN8iCIICSjaDAUG9IoiJa0Av15y94gIGFBWz\n+JlRMes1YA4YCKZVzFmvWVQQBRURRBGMKEgQkQxb34/qtntmZ3ZnZmfTUO/z9NPdp0+frjMzu1NT\np4KoKo7jOI7jODWFOtUtgOM4juM4ThxXThzHcRzHqVG4cuI4juM4To3ClRPHcRzHcWoUrpw4juM4\njlOjcOXEcRzHcZwahSsnjuM4juPUKFw5cRzHcRynRuHKieM4juM4NQpXTpysEJESEbksx3u/F5Fh\nsfNjg/G65E/C3BGRjQN5zqluWVZnRORdEZmY5zETPns1mRR/J7sHn8vd8viMnP+OHacqcOVkNSSm\nFJSIyC5p+vwUXH8h6ZIGWy6UpLg3r/UTRKRIRM7K55hO+QSfldvzNFxl1NTIaMzY30WJiKwSkV9E\n5HUR2b0SZEpHKlmzfk1EZF8RGVzGM6q8domIDE56jZNf71ZVLZNTM6lX3QI41coSoDfwUbwx+Ee8\nPrA0xT1rAitzfF4HTEGpTHoDWwG3VfJznMLlf8BDgADtgFOBt0VkP1V9vaqFUdX3RGRNVV2e5a37\nYbJfkeJaRf6OK4oCA4BFKa79UcWyODUUV05Wb14B/iMiZ6pqXGnoDXwKtEi+IYd/kPF7V+R6b21F\nRBqp6uLqlsPJim9U9bHwRESeAyYCZwMplRMREWANVV1WGQLl+HcneR4vnzytqvOyuUFEGgDLNUW1\n2nz8nfnfas3Cl3VWXxQoBpoDPcNGEakPHAE8Rop/bslr1SJyedC2qYiMEJH5IvKHiAwTkYZJ96Zb\n928sIkNFZI6ILBCRkSLSLOneg0TkpcDMvlREponIJSJSJ9bnHWB/IPQdKRGR6bHrDQJ5p4rIEhG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o1ZCwaKyMmqmvdkZZX0HtYBvsT8HVK9Lrk6OP6s\nqm9n0C/V+1wH87XqnUamVIpUbaTS/t6TSPUaZ3ItH+M71YgrJw7YL+qhwI7ElgOqCMF+bb73d4NI\nY0xRejlo2gP7RXawqn4Y67dpivHSKQHfATuISF3NzKk138zHflEns0klPOs57P3sFTgdboFZLBJQ\n1T+AkcBIEWmEmeYvxxw5880eZP4eAqwnltsj/uXRAXt/Q+fl74B/qOo7lSBvrnyHOcp+pGWHFYfL\nDpsT+/UuIi0o3/rwHfZ3szVQlhKV6XLF78Bi7PVNpiPmm1EbIlkKZR4OHkrsYMsoWFKkyzGH0qrm\nJBGJK8qnYhaFV4LzVdg/43jY8BpBv2QWkXqZ52nM7Ht6PgTOge+ApiKyddggIm2BQ/L9ILWIh9ex\npZ2jsGiH5+N9RGTdpHsWY0sMDWJ9mohIBxGJL8HkSjbvIdgPpwGxvvWxqIvfMcdYMH+pDUTkxOSb\nRaRhoHBVNaMw2UulhheRuoEFCczJdiUWxRNnYAbPmIApaGfHxkvFouC5Zb5/wVLn/4CDRSRcbkJE\nWmPRN6NVtayl2RpBoczDMdxysvqSYH5V1YerSxBgDcyBcBTmQ3AK9o/kpeD6R5jl4SGJUqT3JfUv\nw/HAkSJyMxYi+1cwzkNYeOeQIOfBaCxceC/gLlXNl1KWzqz9OPBf4LlgDo2xL9+pWNRUvnkCeAT7\n8n89ycEXYLKIvIu9XvOAbpgzZzwF/aFYlNFx2OtXHtuLyKAU7e+Q3XsIFpVzvohsgvkQHAX8Azgx\nZvl6mCjEuAfwIabUdsSWsv5NpMhUCar6vogMBS4Ukc7Yl+UKzHp1BBYS/kzgW3JT0O8lTBHfDtiH\n1Es/f3+uVFVF5BTgBeB
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a10d1d978>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2016-10-26 20:16:27 +03:00
"pred_basic_model = train_and_evaluate(reader_train, reader_test, max_epochs=10, model_func=create_basic_model_terse)"
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2017-02-03 04:40:20 +03:00
"Now that we have a trained model, let's classify the following image:"
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/00014.png\" width=\"64\" height=\"64\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 14,
"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",
"execution_count": 15,
2016-10-26 11:30:39 +03:00
"metadata": {
2016-10-26 20:16:27 +03:00
"collapsed": false
2016-10-26 11:30:39 +03:00
},
"outputs": [],
"source": [
"import PIL\n",
2016-10-26 11:30:39 +03:00
"\n",
"def eval(pred_op, image_path):\n",
" label_lookup = [\"airplane\", \"automobile\", \"bird\", \"cat\", \"deer\", \"dog\", \"frog\", \"horse\", \"ship\", \"truck\"]\n",
" image_mean = 133.0\n",
" image_data = np.array(PIL.Image.open(image_path), dtype=np.float32)\n",
2016-10-26 11:30:39 +03:00
" image_data -= image_mean\n",
2016-11-29 05:56:43 +03:00
" image_data = np.ascontiguousarray(np.transpose(image_data, (2, 0, 1)))\n",
2016-11-02 04:03:02 +03:00
" \n",
2016-11-18 21:15:15 +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-02-03 04:40:20 +03:00
"execution_count": 16,
2016-10-26 11:30:39 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-11-02 04:03:02 +03:00
"Top 3 predictions:\n",
2017-03-29 12:07:15 +03:00
"\tLabel: truck , confidence: 97.17%\n",
"\tLabel: ship , confidence: 1.82%\n",
"\tLabel: automobile, confidence: 0.51%\n"
2016-10-26 11:30:39 +03:00
]
}
],
"source": [
2016-11-18 13:48:30 +03:00
"eval(pred_basic_model, \"data/CIFAR-10/test/00014.png\")"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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-02-03 04:40:20 +03:00
"execution_count": 17,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model_with_dropout(input, out_dims):\n",
"\n",
" with default_options(activation=relu):\n",
" model = Sequential([\n",
2017-02-10 03:06:36 +03:00
" For(range(3), lambda i: [\n",
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
" Dense(64, init=glorot_uniform()),\n",
" Dropout(0.25),\n",
" Dense(out_dims, init=glorot_uniform(), activation=None)\n",
" ])\n",
"\n",
" return model(input)"
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 116906 parameters in 10 parameter tensors.\n",
"\n",
2017-03-29 12:07:15 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.132150 * 50000, metric = 0.00% * 50000 13.891s (3599.5 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.828141 * 50000, metric = 0.00% * 50000 13.548s (3690.6 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.676076 * 50000, metric = 0.00% * 50000 13.398s (3731.9 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.587138 * 50000, metric = 0.00% * 50000 13.441s (3720.0 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.516182 * 50000, metric = 0.00% * 50000 13.424s (3724.7 samples/s);\n",
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 48.0% * 10000\n",
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvvYigohh7CVFRULAlYKLGiCU27F2xo7Gh\nUXmNGqMGNcUSa4JYY9e1JSqoERsWbCjYASt2ikpTBCl7v3/cZ5yzs7O7s7NlZnd/n+uaa+Y8pz3P\nnIW996nm7oiIiIiUi4pSZ0BEREQkTcGJiIiIlBUFJyIiIlJWFJyIiIhIWVFwIiIiImVFwYmIiIiU\nFQUnIiIiUlYUnIiIiEhZUXAiIiIiZUXBibQJZlZlZn8u8tyPzezG1PbhyfX6NF0Oi2dmayT5+b9S\n50VqZ2YvmdkjRZ57l5lNaOo8FXjvovMt0lwUnEjZSAUFVWb261qO+SzZPzxnlyevYlTlObdJ13Uw\nswFmdnJTXlNqZ2Y3pX6W6nrdWP/VCtaYn0Enfg5LQWuYSNlZrNQZEMljLnAQ8EI60cy2AlYH5uU5\nZwlgYZH3W5fm/8VwELA+cGUz30fCNcDjqe21gPOB64DnUukfNuE9t6T4X/SHANaEeRFp1RScSDl6\nBNjPzE5y93TQcBDwKrBC7gnuPr/Ym7n7gmLPba3MbEl3/77U+Wgu7v4y8HJm28z6An8BXnT3Owu5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JvqSDCKC\ntslEsHhe6pjLiQkIdySe5yRiKPUVBeZL2ilr/MhCEREpN8nssO+5+x71HixSZkre58TMzrSYhnu2\nxfTQ95tZvs5YtZ2/hcXU2OOaM58iIuXIYsr/ipy0nYiJ3EaVJlcijVPymhOLtSgqidkHFyOmO94A\n6OXu+YY+ps/tSrRNvw+
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a10ccd828>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAADeCAYAAAAjIDq0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXm8VeP6wL9PSd1EIhokDbpIXMpwk58Ml8yZc0Jlpkwn\n7jXLPFdcQ4qrTB1yUemq3BBRiZJCopRb0qiiUXWe3x/PWvY6++x9zt777DP2fD+f9Vlrvet93/Ws\nvc8++9nP+wyiqjiO4ziO41QmqpW3AI7jOI7jOOniCozjOI7jOJUOV2Acx3Ecx6l0uALjOI7jOE6l\nwxUYx3Ecx3EqHa7AOI7jOI5T6XAFxnEcx3GcSocrMI7jOI7jVDpcgXEcx3Ecp9LhCoyTdUQkX0Tu\nyHDsfBF5PnLePZivbfYkzBwR2SOQp3d5y7I1IyLjRWRGlucs8LdXkUnwOekY/F0ekcV7ZPw5dpyy\nwBUYJyERxSFfRA5L0mdBcH1k3CUNtkzITzA2q/UuRCRHRK7N5pxO8QR/K//M0nSlUQMlpTkjn4t8\nEdkiIj+JyFgR6VgKMiUjkaxpvyYicoKI9CniHmVea0ZE+sS9xvGv965lLZNTMdmmvAVwKjzrga7A\nxGhj8M96N2BDgjF/AjZneL+9MCWmNOkK7As8Xsr3caou7wIvAgI0B3oC74vIiao6tqyFUdUPReRP\nqvp7mkNPxGS/K8G1knyOS4oCVwBrE1xbVcayOBUUV2Cc4ngHOFtErlHVqGLRFfgcqB8/IIN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nhnOB/YFLIxa0l4iFVx8FfIIpvvtgy2bHEVN2ygRV/UhEBgI3icgB2BfqJswKdhYWDv9m4OvyaNBv\nFKasHwgcT+Jlpj/+rlR
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a0f1e30f0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2016-10-26 20:16:27 +03:00
"pred_basic_model_dropout = train_and_evaluate(reader_train, reader_test, max_epochs=5, model_func=create_basic_model_with_dropout)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add batch normalization after each convolution and before the last dense layer:"
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model_with_batch_normalization(input, out_dims):\n",
"\n",
2016-10-25 06:42:43 +03:00
" with default_options(activation=relu):\n",
" model = Sequential([\n",
2017-02-10 03:06:36 +03:00
" For(range(3), lambda i: [\n",
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
" BatchNormalization(map_rank=1),\n",
2016-10-25 06:42:43 +03:00
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
" Dense(64, init=glorot_uniform()),\n",
" BatchNormalization(map_rank=1),\n",
" Dense(out_dims, init=glorot_uniform(), activation=None)\n",
2016-10-25 06:42:43 +03:00
" ])\n",
"\n",
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 20,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 117290 parameters in 18 parameter tensors.\n",
"\n",
2017-03-29 12:07:15 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 1.510581 * 50000, metric = 0.00% * 50000 13.826s (3616.4 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.192194 * 50000, metric = 0.00% * 50000 13.504s (3702.6 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.077411 * 50000, metric = 0.00% * 50000 13.573s (3683.8 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.012250 * 50000, metric = 0.00% * 50000 13.409s (3728.8 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 0.941758 * 50000, metric = 0.00% * 50000 13.409s (3728.8 samples/s);\n",
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 30.0% * 10000\n",
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XecVNX9//HXGwsqKMQOii02bCiQaKLYorG3qOhaYon6\nUywJJpr4jQaNhWgS1MQaK7a1G1Gxt2DXRbGA2EBRFJSqFCn7+f3xuePcHWZ3Z5ctd2c/z8djHjP3\n3HPvPWfu6nw49xSZGSGEEEIIWdGhtQsQQgghhJAWwUkIIYQQMiWCkxBCCCFkSgQnIYQQQsiUCE5C\nCCGEkCkRnIQQQgghUyI4CSGEEEKmRHASQgghhEyJ4CSEEEIImRLBSSgLkqol/aWRx46XdGNq+6jk\nfL2broSNJ2ntpDynt3ZZQu0kvSJpeCOPvVPSmKYuU4nXbnS5Q2guEZyEzEgFBdWSfl5LngnJ/mEF\nuyx5NUZ1kWObdF0HSRWSftuU5wy1k3RT6m+prteN9Z+tZIvzN2j432FriDVMQuYs2doFCKGIOcBh\nwEvpREk7AGsAc4scsyywoJHX24jm/2E4DNgUuLyZrxPcNcCTqe11gb8C/wFGpNI/bsJr9qPxP/RH\nAGrCsoTQpkVwErJoOHCwpNPMLB00HAa8AaxceICZzWvsxcxsfmOPbaskLWdms1u7HM3FzF4FXs1t\nS+oDnA+8bGZ3lHIOScuYWbFAuLZrNjY4xswWNvbYEMpRPNYJWWNAJbASsGsu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7JHNWc4QQsgi\n+ZT/HQrSdscncnu2dUoVwuJp9ZYT+VoUlfjsg0vi0x1vBvQ0s2JDH9PHdsGfTX8IrGZmzfGMPIQQ\nMkvSRvhIqEr80cqm+JD
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a17feccc0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXeYVOXVwH8HBBRRUJHiJ2BDRFAELLEglig21EQFUewl\niA1iiVETjJpoYm8oGgWxELBjRVExBER0UUClKKCo9CpNyu75/jj3OndnZ2Znhtnd2dnze577zL3v\nfct5587unDnvOecVVcVxHMdxHCdfqFXVAjiO4ziO40Rx5cRxHMdxnLzClRPHcRzHcfIKV04cx3Ec\nx8krXDlxHMdxHCevcOXEcRzHcZy8wpUTx3Ecx3HyCldOHMdxHMfJK1w5cRzHcRwnr3DlxMkIESkR\nkb9m2fY7EXkqcn1e0F+n3EmYPSLSKpDnj1UtS01GRMaIyJQc91nqs5fPJPg76Rp8Lg/P4RhZ/x07\nTmXgykkNJKIUlIjIIUnq/BDcHxl3S4MjG0oStM3p/gki0ktErs5ln075BJ+VB3PUXUXsqZFWn5G/\nixIRKRaRn0RklIh0rQCZkpFI1ozfExE5XkQGpBij0vcuEZEBce9x/PvdpLJlcvKTLapaAKdKWQec\nBYyPFgb/iP8P+CVBm62ATVmO1wZTUCqSs4B2wAMVPI5TuLwLDAUE2BXoC3wgIieo6qjKFkZVPxKR\nrVR1Q4ZNT8Bk/1uCe5vzd7y5KNAHWJPg3opKlsXJU1w5qdm8BZwhIlepalRpOAv4DGgc3yCLf5DR\nthuzbVtdEZH6qrq2quVwMmKmqj4fXojIq8AUoB+QUDkREQHqqur6ihAoy787yXF/ueQlVV2WSQMR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OwLHkXjp\n59fPlaqqiFwGjAS+EMt
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a097b1ef0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2016-10-26 20:16:27 +03:00
"pred_basic_model_bn = train_and_evaluate(reader_train, reader_test, max_epochs=5, 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-02-03 04:40:20 +03:00
"execution_count": 21,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_vgg9_model(input, out_dims):\n",
" with default_options(activation=relu):\n",
" model = Sequential([\n",
2017-02-10 03:06:36 +03:00
" For(range(3), lambda i: [\n",
" Convolution((3,3), [64,96,128][i], init=glorot_uniform(), pad=True),\n",
" Convolution((3,3), [64,96,128][i], init=glorot_uniform(), pad=True),\n",
2016-10-25 06:42:43 +03:00
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
2017-02-10 03:06:36 +03:00
" For(range(2), lambda : [\n",
" Dense(1024, init=glorot_uniform())\n",
2016-10-25 06:42:43 +03:00
" ]),\n",
" Dense(out_dims, init=glorot_uniform(), activation=None)\n",
2016-10-25 06:42:43 +03:00
" ])\n",
" \n",
" return model(input)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "code",
2017-02-03 04:40:20 +03:00
"execution_count": 22,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 2675978 parameters in 18 parameter tensors.\n",
"\n",
2017-03-29 12:07:15 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 2.252732 * 50000, metric = 0.00% * 50000 14.907s (3354.1 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.924135 * 50000, metric = 0.00% * 50000 13.797s (3624.0 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.711592 * 50000, metric = 0.00% * 50000 13.737s (3639.8 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.580235 * 50000, metric = 0.00% * 50000 13.677s (3655.8 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.476467 * 50000, metric = 0.00% * 50000 13.582s (3681.3 samples/s);\n",
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 49.7% * 10000\n",
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XmcnfPZx/HPlUVCQhAk9iWxhBASra2xq31prIMiqp5S\npalqqSparadaUq2ttohtyqNVe4h9pxIqiFgTS5CQSJAFmev547qPc8/JmZkzy5lzz5nv+/U6r/uc\n3739fueeZK75rebuiIiIiGRFl0pnQERERCRNwYmIiIhkioITERERyRQFJyIiIpIpCk5EREQkUxSc\niIiISKYoOBEREZFMUXAiIiIimaLgRERERDJFwYlUBTOrM7PftPDcqWZ2derzkcn1hrZdDlvOzNZM\n8vOzSudFGmZmT5vZ3S089x9mNrmt81TivVucb5FyUXAimZEKCurMbOsGjnk32X97wS5PXi1RV+Tc\nNl3XwcxqzOyktrymNMzMxqR+lhp7Xd301UrWmp9BJ34OK0FrmEjmdKt0BkSKmA8cCjyZTjSz7YBV\ng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9gMuIIKU\nt4l5RtZj8eCktXkAuJ3o29GL+qN0ci4E9iGGwvYgvqdfAX8ucs/mauycomVw95fM7EDi+Z5P/BIe\nTdT6XFLCPRq6Z0PfY6nnfrPP3W8xs+8DZxDPcAoRJB8PrFL0Co3c292/MLPhxLwsI4l5dyYDh7l7\n+pldQ/QlOZ4I2j4ggsWzU8eMJiYg3JV4nm8TQ6n/UmK+pJOy1o8sFBGRrElmh33N3fdt8mCRjKl4\nnxMzO81iGu65FtND32pmxTpjNXT+NhZTY08sZz5FRLLIYsr/LgVpuxETuT1UmVyJtE7Fa04s1qKo\nJWYf7EZMdzwYGOTuxYY
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a180889e8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFMXWgN9DVlEUkGQiCIqiEswBMaJiuEbAnFBEUVf9\n0HsNGK8ZFSMGRAxcFAMYUVAUDChgBhEQASWJJCWze74fp8fpnZ3ZnZmd3Z2dPe/z9NPd1VXVp6Yn\nnKk6QVQVx3Ecx3GcbKFaRQvgOI7jOI4TxpUTx3Ecx3GyCldOHMdxHMfJKlw5cRzHcRwnq3DlxHEc\nx3GcrMKVE8dxHMdxsgpXThzHcRzHySpcOXEcx3EcJ6tw5cRxHMdxnKzClRMnJUSkQERuSrPtryIy\nOHR+TtBfx8xJmD4iskMgz1UVLUtVRkTGich3Ge6z0Hsvm4nzOTk4eF92zuA90v4cO0554MpJFSSk\nFBSIyP4J6swLro+KuaTBlg4FcdpmNH+CiPQUkSsy2adTMsF7ZWCGuiuLnBpJ9Rn6XBSISL6I/C4i\no0Xk4DKQKRHxZE35NRGRo0WkfzH3KPfcJSLSP+Y1jn29G5W3TE52UqOiBX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c+8cEMQ8GI+5Cx8GPKqqmVLKEk1r/w+4G3gjGMNm2I/vdMxrKtMMB17AfvxHxxj4AkwV\nkXHY67UU2Asz5gyHoD8R8zI6F3v9SmJPEbk+TvlHpPYMwbxy+olIc8yGoAewO9ArNPP1PFEX40OA\nTzGlti22lHUkUUWmXFDVT0RkEHCdiLTHfiw3YLNXp2Au4a8FtiX3BfXewhTxDsBRxF/6+ed9paoq\nIpcAo4BvxGKaLMA+O7u
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a10cd9cc0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2016-10-25 06:42:43 +03:00
"source": [
2016-10-26 20:16:27 +03:00
"pred_vgg = train_and_evaluate(reader_train, reader_test, max_epochs=5, model_func=create_vgg9_model)"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Residual Network (ResNet)\n",
"\n",
2017-02-03 04:40:20 +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 gradient 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:"
]
},
{
"cell_type": "code",
"execution_count": 23,
2017-02-03 04:40:20 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://cntk.ai/jup/201/ResNetBlock2.png\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 23,
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",
"* During back propagation the gradient have a path that doesn't affect its magnitude.\n",
"* 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",
"execution_count": 24,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
2016-10-25 06:42:43 +03:00
},
"outputs": [],
"source": [
"from cntk.ops import combine, times, element_times, AVG_POOLING\n",
"\n",
2016-11-02 04:03:02 +03:00
"def convolution_bn(input, filter_size, num_filters, strides=(1,1), init=he_normal(), activation=relu):\n",
" if activation is None:\n",
" activation = lambda x: x\n",
" \n",
" r = Convolution(filter_size, num_filters, strides=strides, init=init, activation=None, pad=True, bias=False)(input)\n",
" r = BatchNormalization(map_rank=1)(r)\n",
" r = activation(r)\n",
" \n",
" return r\n",
"\n",
2016-10-25 06:42:43 +03:00
"def resnet_basic(input, num_filters):\n",
" 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",
" return relu(p)\n",
"\n",
"def resnet_basic_inc(input, num_filters):\n",
" c1 = convolution_bn(input, (3,3), num_filters, strides=(2,2))\n",
" c2 = convolution_bn(c1, (3,3), num_filters, activation=None)\n",
"\n",
" 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",
" return relu(p)\n",
"\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",
"execution_count": 25,
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",
" pool = AveragePooling(filter_shape=(8,8), strides=(1,1))(r3_2) \n",
2016-11-02 04:03:02 +03:00
" net = Dense(out_dims, init=he_normal(), activation=None)(pool)\n",
2016-10-25 06:42:43 +03:00
" \n",
" return net"
]
},
{
"cell_type": "code",
"execution_count": 26,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2016-11-02 21:29:44 +03:00
"Training 272474 parameters in 65 parameter tensors.\n",
"\n",
2017-03-29 12:07:15 +03:00
"Finished Epoch[1 of 5]: [Training] loss = 1.860499 * 50000, metric = 0.00% * 50000 17.333s (2884.7 samples/s);\n",
"Finished Epoch[2 of 5]: [Training] loss = 1.577205 * 50000, metric = 0.00% * 50000 16.166s (3092.9 samples/s);\n",
"Finished Epoch[3 of 5]: [Training] loss = 1.450118 * 50000, metric = 0.00% * 50000 16.113s (3103.1 samples/s);\n",
"Finished Epoch[4 of 5]: [Training] loss = 1.342510 * 50000, metric = 0.00% * 50000 16.078s (3109.8 samples/s);\n",
"Finished Epoch[5 of 5]: [Training] loss = 1.257909 * 50000, metric = 0.00% * 50000 16.147s (3096.6 samples/s);\n",
"\n",
2017-03-29 12:07:15 +03:00
"Final Results: Minibatch[1-626]: errs = 45.8% * 10000\n",
"\n"
]
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOX5//H3B1RQEBSMYosdGwkGjIlRNPYSW4yFtYFp\nPzVGxMQYY6xJNNGvEmM3RiWWtRdEgyX2rgt2gopiAUERWJAOe//+uM84Z4fZ3dllZ/fs7v26rrlm\nznPa88xZ2HufKjMjhBBCCCErOrV2BkIIIYQQ0iI4CSGEEEKmRHASQgghhEyJ4CSEEEIImRLBSQgh\nhBAyJYKTEEIIIWRKBCchhBBCyJQITkIIIYSQKRGchBBCCCFTIjgJ7YKkGklnNfHcSZKuT20PSa43\noPly2HSSNkjyc0pr5yXUTdKLkh5q4rm3SRrf3Hkq8d5NzncI5RLBSciMVFBQI+kHdRzzSbJ/VMEu\nS15NUVPk3GZd10FShaRhzXnNUDdJN6R+lup7Xd/w1Uq2PD+Dhv8ctoZYwyRkzgqtnYEQipgPHAE8\nn06UtDOwLrCgyDkrA0uaeL/NKf8vhiOArYFLy3yf4K4GHk1tbwScB1wLPJNKn9iM9xxE03/RHwWo\nGfMSQpsWwUnIooeAQyWdZGbpoOEI4FVgjcITzGxRU29mZoubem5bJWkVM5vX2vkoFzN7CXgpty1p\nIPAn4AUzu7W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QQtYks8O+a2YHNnhwCBnT6n1OJJ0un4Z7tnx66HslFeuMVXjeSpL+Ip96fIGkDyQNbYEs\nhxBCZsin/O9UkLY3PpHbE62TqxCWTxaadQbh4+VfxfNzAT4cbUszKzb0MedOvCPhsXinvrXJQLAV\nQggtbBO8z1Al3rSyNT5
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a17fbbe80>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-03-29 12:07:15 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXm8leP2wL8rGlSkRGUKIYlIxiuZLuEiXCKS4poyxs+c\n2cU15NIgGQpxyDULETJUptNANBjK1CQNaDx11u+P9b72u/fZ+5y999nnnH3OWd/P5/287/uM69nv\nHtZ+nrXWI6qK4ziO4zhOvlCnqgVwHMdxHMeJ4sqJ4ziO4zh5hSsnjuM4juPkFa6cOI7jOI6TV7hy\n4jiO4zhOXuHKieM4juM4eYUrJ47jOI7j5BWunDiO4ziOk1e4cuI4juM4Tl7hyomTESJSLCI3ZFl3\njog8Frk/I2hvj9xJmD0i0jqQ57KqlqU2IyLjROSLHLcZ997LZ5J8Tg4M3pddcthH1p9jx6kMXDmp\nhUSUgmIR+VuKMj8F+a8kZGlwZENxkro53T9BRHqIyCW5bNMpm+C98kCOmquIPTXSajPyuSgWkXUi\n8ouIjBGRAytAplQkkzXj10REjhSRG0vpo9L3LhGRGxNe48TXe7PKlsnJT9avagGcKmUlcCowIZoY\nfBFvAaxKUmcDYG2W/bXFFJSK5FSgPXB/Bffj1FzeAp4ABNgW6Au8KyJHqeqYyhZGVd8XkQ1UdU2G\nVY/CZL85SV55PsflRYHzgOVJ8pZWsixOnuLKSe3mdeAkEblYVaNKw6nA50DzxApZfEFG6xZlW7e6\nIiINVXVFVcvhZMQsVX06vBG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RHbHfiyLsNmrEzGX8BcC25J7gnKvYYp4R+AIki/9/PW+UlUV\nkfOBV4ApYjFN5mGfnZ1
"text/plain": [
2017-03-29 12:07:15 +03:00
"<matplotlib.figure.Figure at 0x21a1f396e80>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
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": {
"anaconda-cloud": {},
2016-10-25 06:42:43 +03:00
"kernelspec": {
"display_name": "Python [default]",
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
}