2016-10-25 06:42:43 +03:00
{
"cells": [
{
"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": [
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",
2016-10-26 09:34:40 +03:00
"* 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",
2016-10-26 09:34:40 +03:00
"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",
2016-10-26 11:30:39 +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:\n",
2016-10-26 09:34:40 +03:00
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/cifar-10.png\", width=500, height=500>\n",
2016-10-26 09:34:40 +03:00
"\n",
"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",
2016-10-26 09:34:40 +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.\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/Conv2D.png\">\n",
2016-10-25 06:42:43 +03:00
"\n",
"The stack of feature maps output are the input to the next layer.\n",
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/Conv2DFeatures.png\">\n",
2016-10-25 06:42:43 +03:00
"\n",
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",
"Here an example of max pooling with a stride of 2:\n",
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/MaxPooling.png\", 200,200>\n",
2016-10-25 06:42:43 +03:00
"\n",
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",
"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",
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",
2016-10-25 06:42:43 +03:00
"## Computational Network Toolkit (CNTK)\n",
"\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",
2016-11-03 10:42:00 +03:00
"execution_count": 1,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
2016-10-26 09:34:40 +03:00
"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",
"from cntk.blocks import default_options\n",
2016-10-26 09:34:40 +03:00
"from cntk.layers import Convolution, MaxPooling, AveragePooling, Dropout, BatchNormalization, Dense\n",
2016-10-26 11:30:39 +03:00
"from cntk.models import Sequential, LayerStack\n",
2016-10-25 06:42:43 +03:00
"from cntk.io import MinibatchSource, ImageDeserializer, StreamDef, StreamDefs\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",
2016-11-02 21:29:44 +03:00
"from cntk.learner import momentum_sgd, learning_rate_schedule, UnitType, momentum_as_time_constant_schedule\n",
2016-11-02 04:03:02 +03:00
"from cntk.ops import cross_entropy_with_softmax, classification_error, relu, input_variable, softmax, element_times\n",
2016-10-26 09:34:40 +03:00
"from cntk.utils import *"
2016-10-25 06:42:43 +03:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now that we imported the needed modules, let's implement our first CNN, as shown below:\n",
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/CNN.png\">\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",
2016-11-03 10:42:00 +03:00
"execution_count": 2,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_basic_model(input, out_dims):\n",
2016-10-26 06:41:49 +03:00
" \n",
2016-11-01 06:03:17 +03:00
" net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=True)(input)\n",
2016-10-26 06:41:49 +03:00
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-01 06:03:17 +03:00
" net = Convolution((5,5), 32, init=glorot_uniform(), activation=relu, pad=True)(net)\n",
2016-10-26 06:41:49 +03:00
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-01 06:03:17 +03:00
" net = Convolution((5,5), 64, init=glorot_uniform(), activation=relu, pad=True)(net)\n",
2016-10-26 06:41:49 +03:00
" net = MaxPooling((3,3), strides=(2,2))(net)\n",
" \n",
2016-11-01 06:03:17 +03:00
" net = Dense(64, init=glorot_uniform())(net)\n",
" net = Dense(out_dims, init=glorot_uniform(), 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",
2016-11-03 10:42:00 +03:00
"execution_count": 3,
2016-10-25 06:42:43 +03:00
"metadata": {
2016-10-26 06:41:49 +03:00
"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",
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",
" if train:\n",
" transforms += [\n",
" ImageDeserializer.crop(crop_type='Random', ratio=0.8, jitter_type='uniRatio') # train uses jitter\n",
" ]\n",
" transforms += [\n",
" ImageDeserializer.scale(width=image_width, height=image_height, channels=num_channels, interpolations='linear'),\n",
" ImageDeserializer.mean(mean_file)\n",
" ]\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",
2016-11-03 10:42:00 +03:00
"execution_count": 4,
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",
" input_var = input_variable((num_channels, image_height, image_width))\n",
" label_var = 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",
" input_var_norm = element_times(feature_scale, input_var)\n",
" \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",
" 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",
2016-11-03 10:42:00 +03:00
" # 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",
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",
2016-11-01 06:03:17 +03:00
" learner = momentum_sgd(z.parameters, \n",
2016-11-02 21:29:44 +03:00
" lr = lr_per_minibatch, momentum = momentum_time_constant, \n",
2016-11-01 06:03:17 +03:00
" l2_regularization_weight=l2_reg_weight)\n",
2016-10-25 06:42:43 +03:00
" trainer = Trainer(z, ce, pe, [learner])\n",
"\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",
" progress_printer = ProgressPrinter(tag='Training')\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",
" progress_printer.update_with_trainer(trainer, with_metric=True) # log progress\n",
" batch_index += 1\n",
" progress_printer.epoch_summary(with_metric=True)\n",
" \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",
2016-11-03 10:42:00 +03:00
"execution_count": 5,
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",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 2.007709 * 50000, metric = 73.7% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.645898 * 50000, metric = 60.7% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.519421 * 50000, metric = 55.6% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.420799 * 50000, metric = 51.4% * 50000\n",
"Finished Epoch [5]: [Training] loss = 1.338837 * 50000, metric = 47.7% * 50000\n",
2016-10-25 06:42:43 +03:00
"\n",
2016-11-03 10:42:00 +03:00
"Final Results: Minibatch[1-626]: errs = 42.3% * 10000\n",
2016-10-25 06:42:43 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3Xmc1fP+wPHXO6VUKmvJLqIsMeNay752U7kSU9Z7ccna\ndV26lrjX5eKnLBWunTJ2SsiWCBGTJUpIi0ShmvZ13r8/3t+v853TmZkzy5nznTPv5+NxHue7fz+f\n8z113vNZRVVxzjnnnIuLBtlOgHPOOedclAcnzjnnnIsVD06cc845FysenDjnnHMuVjw4cc4551ys\neHDinHPOuVjx4MQ555xzseLBiXPOOedixYMT55xzzsWKBycuJ4hIiYhcV8VzZ4rIQ5H1M4Pr5dVc\nCqtORLYP0vO3bKfFlU1EPhSRV6p47pMiMrWm05TmvaucbucyxYMTFxuRoKBERA4q45gfgv2jknZ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YYBnbAf1MuwovHRqloiIsdjPzBh49/fsCBlchr5SzffKY8J8tATGIQFKTOwcUbas35wUt00\nAIzC2nY0o3QvndCdQHesK2xj7HP6J/B/Ke5ZWeWdkzIPqvqliJyMPd/bsR/hwVipz7A07lHWPcv6\nHNM99/d9qvqsiJwOXIs9w2lYkNwPaJvyCuXcW1WXiUgXbFyWs7Fxd6YCfVU1+swewdqS9MOCtp+w\nYPGGyDGDsQEIj8We5wysK/UdaabL1VNS/Z6Fzjnn4iYYHfYbVe1R4cHOxUzW25yIyACxYbgXiw0P\n/YKIpGqMVdb5B4sNjT0pk+l0zrk4Ehvyv0HStuOwgdzezk6qnKuerJeciM1FUYiNPtgQG+54D6CD\nqqbq+hg9tyVWN/0t0Fp
2016-10-25 06:42:43 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x89f5ef0>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXeYFFXWh98fiKCyYgZZs2KOYMKcw+6aVldFMa1hzYh+\nhjXHZdU1r3ENGDHromIC46oYBrNgQIxIEkUkKDDn++NU2zVNz0x3T89Mz8x5n6eeqrp1w7lV3V2n\n7z3nXJkZQRAEQRAElUK75hYgCIIgCIIgTSgnQRAEQRBUFKGcBEEQBEFQUYRyEgRBEARBRRHKSRAE\nQRAEFUUoJ0EQBEEQVBShnARBEARBUFGEchIEQRAEQUURykkQBEEQBBVFKCdBUUiqlnR2iWW/kHRr\n6vygpL6e5ZOwdCQtm8hzYnPL0paR9IKk98pcZ43PXiWT53uyZfK53KKMbZT8PQ6CpiCUkzZISimo\nlrRJLXm+Tq4PzrlkyVYK1XnKlnX9BEl9JPUrZ51B/SSflavLVF1jrKlR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tqtiJoLf0InBg5abvUGH41szubSxBgXtyA8H7c\nhuAo/Ifk8eT6q/jIwx3KhkjvS/5/hlXA3pIuw11kf07quQN377w8iXnwMu4uvC1wrZmVSymrbVj7\nXuBi4NGkDwvgL9+Pca+pcnMfcBf+8n86x8AX4CNJL+D3azKwAW7MmQ5BvwfuZXQwfv/qY31JZ+RJ\nf57iniG4V84pkpbDbQj2BdYGDk+NfN1J1sV4a+AVXKldDZ/K2oGsItMkmNlLkm4ETpO0Lv6ynIWP\nXu2Fu4Q/nNiW/CvJ9ziuiK8H7ET+qZ/fPldmZpKOAgYD78hjmnyHf3dWN7Odk6xVSblrJD2Ne+7c\nV4voZ+JGqa9Iug5XJo/
2016-10-25 06:42:43 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x9998eb8>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
2016-10-25 09:14:01 +03:00
"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",
2016-11-03 10:42:00 +03:00
"execution_count": 6,
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",
2016-10-26 06:41:49 +03:00
" with default_options(activation=relu):\n",
" model = Sequential([\n",
" LayerStack(3, lambda i: [\n",
2016-11-01 06:03:17 +03:00
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
2016-10-26 06:41:49 +03:00
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
2016-11-01 06:03:17 +03:00
" Dense(64, init=glorot_uniform()),\n",
" Dense(out_dims, init=glorot_uniform(), 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",
2016-11-03 10:42:00 +03:00
"execution_count": 7,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 116906 parameters in 10 parameter tensors.\n",
"\n",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 2.052350 * 50000, metric = 75.9% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.718251 * 50000, metric = 63.8% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.561047 * 50000, metric = 57.2% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.469333 * 50000, metric = 53.1% * 50000\n",
"Finished Epoch [5]: [Training] loss = 1.390282 * 50000, metric = 50.2% * 50000\n",
"Finished Epoch [6]: [Training] loss = 1.312587 * 50000, metric = 47.0% * 50000\n",
"Finished Epoch [7]: [Training] loss = 1.246972 * 50000, metric = 44.3% * 50000\n",
"Finished Epoch [8]: [Training] loss = 1.203198 * 50000, metric = 42.7% * 50000\n",
"Finished Epoch [9]: [Training] loss = 1.149999 * 50000, metric = 40.5% * 50000\n",
"Finished Epoch [10]: [Training] loss = 1.102825 * 50000, metric = 38.7% * 50000\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-11-03 10:42:00 +03:00
"Final Results: Minibatch[1-626]: errs = 35.9% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3Xmc1fP+wPHXu6JUVKRsUbQoElN2ZctShFzbhEt+172E\nS9yLrkt2cS+JZEl2TYgSQtnXuGZCkdCuIpRKe83798f7+3W+58yZfc6cM2fez8fjPL7n+/lun885\nU/OezyqqinPOOedcpqiT7gw455xzzkV5cOKcc865jOLBiXPOOecyigcnzjnnnMsoHpw455xzLqN4\ncOKcc865jOLBiXPOOecyigcnzjnnnMsoHpw455xzLqN4cOKygogUish1Fbx2rog8Etk/J7hfTtXl\nsOJEZJcgP5enOy+ueCIyRUQmVvDaMSIyo6rzVMZnVzjfzqWKBycuY0SCgkIROaiYcxYExyckHNLg\nVRGFSa6t0nUdRCRXRC6tynu64onIo5GfpZJej5R+tzKrzM+gYj+H6eBrmLiMUy/dGXAuiTVAP+Cj\naKKIHArsCKxNcs0WwMYKPq8Dqf/F0A/YAxiW4uc48wAwObLfBrgReAh4P5I+qwqf2Z2K/6I/C5Aq\nzItzNZoHJy4TTQROFZG/q2o0aOgHfAY0T7xAVddX9GGquqGi19ZUItJQVVenOx+poqqfAJ+E+yLS\nFbgJ+FhVR5flHiLSQFWTBcLFPbOiwTGquqmi1zqXjbxZx2UaBfKAbYCjwkQR2Qw4BRhNkr8wE/uc\niMj1QdpuIvKYiCwTkd9E5BERaZBw7dxiqvcbiciDIvKLiCwXkcdFpGnCtSeIyMsislBE1orI9yLy\nbxGpEznnbeA4IOw7UigisyPH6wf5nSkia0RkkYg8LyJtkpTz/OAZa0XkUxHpVtoHGmku6yEiI0Tk\nJ2BBcOwxEZmT5JrrRaQwIa1QRO4RkRNFZFqQh+kickwpz28hIhtE5Nokx9oH9x0Q7NcTkcEi8m3w\nWfwiIu+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DWvSWQe8GD1HRLZOuGY11jxRP3LOVsFQ27I0qVRWWHMR\n/Y63wSZNK4uUzr6qqnOwviXnSmSIvNjw7nbFXliyidiw9xMj96uH/Yz+BnwYpCV+V4p1cIbg+0py\nzu/Y6Ln6OFcCH0rsMk1cdbWqPlncidVgc+BNEXkW69x6IfC+qr4cHP8Iq3l4QkTuCdLOIvkvpHzg\nNBG5ExuW+ntwnyew+TTuEpH9sQ6PjYEjgftUtaqCsuKaAcYAtwPjgzI0wgLCmdioqar2DDbsdQDw\nekIHX4CvReQd7PNaCuyLzW9zT+Scvtgoo3Oxzy+VXgNuBV4VkYexWqa/YqNoikwGmER1NL9cg32u\nH4jIE0AL7Gf1Kyr2B+h92JD70SIyHOv3cgb283BBpOPtUyJSHxsFthCrObkY+CQImsD6mryKjVha\nhg0zPh64owL5crWIBycu05TlL81kc0JUdl2TZPe7GJtb5AZgM2y00B9zrKjqUhE5Dpvj5CbsP98n\nsWGmryfcbwTQBfuFehlWNf6yqhaKSC/sF0zY+fdXLEiZVobylbXcSc8JynAScBcWpMzB5hlpT9Hg\npLJ5AJiA9e1oRPwondAw4ARsKGx97HP6F/DfJM8sr5KuSVoGVZ0uIqdi3++d2C/hoVitz4gyPKO4\nZxb3OZb12j+OqepYETkbuBb7DmdiQfIAYIekdyjh2aq6SkS6Y/Oy9Mfm3ZkBnKmq0e/sMawvyQAs\naFuMBYs3RM4Zik1AeAz2fc7BhlLfXcZ8uVpKKj+y0DnnXKYJZof9VlVPLPVk5zJM2vuciMggsWm4\nV4hNDz1ORJJ1xiru+oPFpsYuSGU+nXMuE4lN+V8nIe1YbCK3t9OTK+cqJ+01J2JrUeRhsw/Ww6Y7\n3hPoqKrJhj5Gr22CtU1
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x1a71f60>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
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Fmt1fAqZkilSdZFq+7wnkOw5TudcLsZ3ahFXThywf9QDgZ2IuANqCMH+bX74b4NIM0xR+m/Q1B37\nR3aYqo6K9NsoyXiplIBJwI4i0lDTC2rNNXOwf9SJrF8N93oVez2PDYION8UsFnGo6j/Ak8CTItIU\nM83fgAVy5prupP8aAnQQy+0R/fHoiL2+YfDyJKCTqn5QDfJmyyQsUHa0VrysOHQ7bELk37uItKFy\n68Mk7HOzFVCREpWuu2ImsBB7fhPZHIvNqAsrWQplHg6+lNjB3ChYUqQbsIDSmuZMEYkqyudiFoW3\nguMV2JdxdNnwykG/RBaQ3M3zEmb2PT8XAmfBJKCliGwVNojImsDhub6R2oqH4Zhr5zhstcNr0T4i\nsnrCNQsxF0PjSJ8WItJRRKIumGzJ5DUE++N0dqRvI2zVxUwsMBYsXmptEemdeLGINAkUrppmGCZ7\nudTwItIwsCCBBdkux1bxRClK4x5jMQXt4sh4yVgQ3LfC1y9wdb4LHCYiobsJEWmHrb75WFUrcs3m\nBYUyD8dwy0n9Jc78qqpP1ZYgwMpYAOEwLIbgHOyL5M3g/GjM8jBUYinSTyT5P8MS4BgRuQdbIjs/\nGGcotryzX5Dz4GNsufDewABVzZVSlsqs/RxwB/BqMIdm2I/vT9iqqVzzPPA09uM/PCHAF+AHERmJ\nPV+zgR2wYM5oCvojsFVGp2DPX2VsLyLXJGn/gMxeQ7BVOZeLyPpYDMFxQCegd8Ty9RSxJcZ7AqMw\npXZzzJW1HzFFpkZQ1Y9EZCBwpYhsi/1YLsOsV0dhS8JfDmJL7g76vYkp4tsB+5Pc9fPv+0pVVUTO\nAV4HvhLLafIn9tnZQlU
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x997db38>"
2016-10-25 23:52:23 +03:00
]
},
"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": [
"Now that we have a trained model, let's classify the following image:\n",
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/00014.png\", width=64, height=64>\n"
2016-10-26 11:30:39 +03:00
]
},
{
"cell_type": "code",
2016-11-03 10:42:00 +03:00
"execution_count": 8,
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": [
"from PIL import Image\n",
"\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(Image.open(image_path), dtype=np.float32).T\n",
" image_data -= image_mean\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",
2016-11-03 10:42:00 +03:00
"execution_count": 9,
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",
2016-11-03 10:42:00 +03:00
"\tLabel: truck , confidence: 47.62%\n",
"\tLabel: ship , confidence: 30.42%\n",
"\tLabel: automobile, confidence: 12.52%\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": [
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",
2016-11-03 10:42:00 +03:00
"execution_count": 10,
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",
2016-10-26 06:41:49 +03:00
" with default_options(activation=relu):\n",
" model = Sequential([\n",
" LayerStack(3, lambda i: [\n",
2016-11-01 06:03:17 +03:00
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
2016-10-26 06:41:49 +03:00
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
2016-11-01 06:03:17 +03:00
" Dense(64, init=glorot_uniform()),\n",
2016-10-26 06:41:49 +03:00
" Dropout(0.25),\n",
2016-11-01 06:03:17 +03:00
" Dense(out_dims, init=glorot_uniform(), 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",
2016-11-03 10:42:00 +03:00
"execution_count": 11,
2016-10-25 23:52:23 +03:00
"metadata": {
"collapsed": false
},
"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",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 2.133263 * 50000, metric = 79.1% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.814037 * 50000, metric = 67.1% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.656499 * 50000, metric = 61.2% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.569030 * 50000, metric = 57.7% * 50000\n",
"Finished Epoch [5]: [Training] loss = 1.504180 * 50000, metric = 55.1% * 50000\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-11-03 10:42:00 +03:00
"Final Results: Minibatch[1-626]: errs = 48.2% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvDQgoKlgBDWJDxS7Ye43YNVaIimhi78YW\nY0l5Y4k19t5dey/YjV0j2CWoCKggglSlCLj3+8d9xjkzO9vLzM7+Ptc115l5TnueOQt771PN3RER\nEREpFe2KnQERERGRNAUnIiIiUlIUnIiIiEhJUXAiIiIiJUXBiYiIiJQUBSciIiJSUhSciIiISElR\ncCIiIiIlRcGJiIiIlBQFJ1IWzKzSzM5p4LljzOyW1OfByfX6NV0OG87Meif5ObnYeZHqmdnbZvZ0\nA8+918xGNHWe6njvBudbpLkoOJGSkQoKKs1s02qO+SbZ/3jeLk9eDVFZ4NwmXdfBzAaa2QlNeU2p\nnpndmvpZqul1S+1Xq7PG/Aw68XNYDFrDREpOh2JnQKSA2cAg4M10opltBSwLzClwzoLA/Abeb1Wa\n/xfDIGAN4Ipmvo+E64DnU59XAP4G3AC8lkof1YT33IKG/6I/ELAmzItIq6bgRErR08C+Zna8u6eD\nhkHAe8CS+Se4+9yG3szd5zX03NbKzBZy91nFzkdzcfd3gHcyn82sP/B34C13v6cu1zCzzu5eKBCu\n7p4NDY5x918aeq5IOVKzjpQaByqAJYAdMolmtgCwD3APBf7CzO9zYmbnJWkrmdltZjbVzKaZ2S1m\n1jnv3DHVVO93MbPrzewHM5tuZrebWb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\nCw19TJ/blWib/gLo7u7
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x1b51828>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXecFFXywL9FVhAUUTBHUBRUgnKYET08c1YUFUUMeIKY\nM8afWQ8RFCNGzKee4VSMGMBzUUwIiogBSRIls1u/P6rb7pmd2Z2Znd2d3a3v59Of7n793ut60xNq\n6lXVE1XFcRzHcRynUKhX3QI4juM4juPEceXEcRzHcZyCwpUTx3Ecx3EKCldOHMdxHMcpKFw5cRzH\ncRynoHDlxHEcx3GcgsKVE8dxHMdxCgpXThzHcRzHKShcOXEcx3Ecp6Bw5cTJChEpEZGrcmz7k4g8\nFDs/Oeivc/4kzB0R2SyQ57zqlqUuIyLviciXee4z4b1XyKT4nOwVvC/3zOM9cv4cO05V4MpJHSSm\nFJSIyK5p6vwSXH856ZIGWy6UpGib1/UTRKS3iAzKZ59O+QTvlbvy1F1lrKmRUZ+xz0WJiBSLyG8i\n8oaI7FUJMqUjlaxZvyYi8g8RGVLGPap87RIRGZL0Gie/3utXtUxOYdKgugVwqpVlwPHAx/HC4It4\nI2B5ijZrAKtzvN82mIJSmRwPbA8MreT7OLWXN4FHAQG2AAYA74jIAar6RlULo6rvi8gaqroyy6YH\nYLJfk+JaRT7HFUWBM4ElKa4tqGJZnALFlZO6zWvA0SIyUFXjSsPxwGdAq+QGOXxBxtuuyrVtTUVE\n1lTVpdUth5MVU1T1yfBERF4EvgTOBVIqJyIiQCNVXVEZAuX4uZM895dPnlfVedk0EJHGwEpNsVpt\nPj5n/lktLHxap+6iwGhgXWC/sFBEGgJHAU+S4sstea5aRK4OyrYSkVE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plotlib.figure.Figure at 0x1b0ee10>"
2016-10-25 23:52:23 +03:00
]
},
"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)"
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",
2016-11-03 10:42:00 +03:00
"execution_count": 12,
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",
2016-10-25 06:42:43 +03:00
" with default_options(activation=relu):\n",
" model = Sequential([\n",
" LayerStack(3, lambda i: [\n",
2016-11-01 06:03:17 +03:00
" Convolution((5,5), [32,32,64][i], init=glorot_uniform(), pad=True),\n",
2016-10-26 06:41:49 +03:00
" BatchNormalization(map_rank=1),\n",
2016-10-25 06:42:43 +03:00
" MaxPooling((3,3), strides=(2,2))\n",
" ]),\n",
2016-11-01 06:03:17 +03:00
" Dense(64, init=glorot_uniform()),\n",
2016-10-26 06:41:49 +03:00
" BatchNormalization(map_rank=1),\n",
2016-11-01 06:03:17 +03:00
" Dense(out_dims, init=glorot_uniform(), 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",
2016-11-03 10:42:00 +03:00
"execution_count": 13,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
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",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 1.587309 * 50000, metric = 56.8% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.243764 * 50000, metric = 44.1% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.105299 * 50000, metric = 38.9% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.022793 * 50000, metric = 35.7% * 50000\n",
"Finished Epoch [5]: [Training] loss = 0.966495 * 50000, metric = 33.6% * 50000\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-11-02 21:29:44 +03:00
"Final Results: Minibatch[1-626]: errs = 31.4% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XecVNX5x/HPFxRQRBQNWIIFu0ZRMCYWsERjC5aoKNiN\n+lM0UWKiMbGbxMTEgrHGioW1xYIlVuzdRWMBxQJ2RQUWpUjZ5/fHc8e5O8zuzta5u/u8X6957dxz\nz733nLkL8+xpV2ZGCCGEEEJWdCp3AUIIIYQQ0iI4CSGEEEKmRHASQgghhEyJ4CSEEEIImRLBSQgh\nhBAyJYKTEEIIIWRKBCchhBBCyJQITkIIIYSQKRGchBBCCCFTIjgJ7YKkakmnNfLYKZKuSW0fnJxv\nQPOVsPEkrZqU57flLkuonaTnJd3fyGNvljSxuctU4rUbXe4QWkoEJyEzUkFBtaQtasnzUbJ/bMEu\nS16NUV3k2GZ9roOkYZKOa85zhtpJujb1u1TX65r6z1aypvwOGv57WA7xDJOQOYuVuwAhFDEHGA48\nm06UtDWwMjC3yDFLAAsaeb11aPkvhuHABsCoFr5OcJcDD6e2VwfOAv4NPJVKf68ZrzmIxn/RHwCo\nGcsSQpsWwUnIovuBfST9xszSQcNw4GVg+cIDzGxeYy9mZvMbe2xb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IYSQNcnqsJPMbPd6M4eQMWUfcyLpZPky3DPly0PfKanYYKzajt9SvjT2+JYsZwghZJF8yf9OBWk7\n4Qu5PVaeUoXQNGVvOZE/i6ICX31wMXy54x8B65lZsamP6WN74n3T7wB9zKwl+shDCCGzJK2Dz4Sq\nwLtWNsCn7H4ObNTIKfg
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x1693c3c8>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFFXWgN8DEkQECZIEFRQVwypgzoKYMLuCKMZV1/C5\niq6YxbiorJjBDIsBIypmxIgBURARQVBAAckSJcOc78epsqt7ume6e3pmembO+zz1VNWte2+dW9Uz\nffqecEVVcRzHcRzHyReqlbcAjuM4juM4UVw5cRzHcRwnr3DlxHEcx3GcvMKVE8dxHMdx8gpXThzH\ncRzHyStcOXEcx3EcJ69w5cRxHMdxnLzClRPHcRzHcfIKV04cx3Ecx8krXDlxMkJECkTk5izb/ioi\nT0fOzw7665A7CbNHRLYJ5LmyvGWpyojIJyIyIcd9xn328pkkfyeHBJ/Lg3N4j6z/jh2nLHDlpAoS\nUQoKRGT/FHVmBdeHJ1zSYMuGgiRtc7p+goj0EJHLc9mnUzzBZ+XBHHVXGmtqpNVn5O+iQEQ2isjv\nIvK+iBxSCjKlIpmsGT8TETlaRPoUcY8yX7tERPokPOPE592krGVy8pNNylsAp1xZDZwOfBktDP4R\nbwWsSdJmU2BDlvfbEVNQSpPTgV2AB0r5Pk7lZQQwBBCgNXAJ8JGIHKOq75e1MKr6qYhsqqrrMmx6\nDCb7rUmuleTvuKQocBGwMsm1pWUsi5OnuHJStXkHOFVE/qWqUaXhd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5vEdkW8yE4DfgbcEFk5usZYiHGhwFf\nYEptO8yUdQQxRaZMUNXPROQx4FoR2QP7slyPzV79HQsJHxb4lvw3qPcWpoi3B44iuennr8+VqqqI\nXAwMB8aL5TSZi/3t7Ky
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x17e43400>"
2016-10-25 23:52:23 +03:00
]
},
"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",
2016-11-03 10:42:00 +03:00
"execution_count": 14,
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",
" LayerStack(3, lambda i: [\n",
2016-11-01 06:03:17 +03:00
" 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",
" LayerStack(2, lambda : [\n",
2016-11-01 06:03:17 +03:00
" Dense(1024, init=glorot_uniform())\n",
2016-10-25 06:42:43 +03:00
" ]),\n",
2016-11-01 06:03:17 +03:00
" Dense(out_dims, init=glorot_uniform(), 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",
2016-11-03 10:42:00 +03:00
"execution_count": 15,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
2016-10-25 23:52:23 +03:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training 2675978 parameters in 18 parameter tensors.\n",
"\n",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 2.268612 * 50000, metric = 84.6% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.954496 * 50000, metric = 72.8% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.709687 * 50000, metric = 63.5% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.578118 * 50000, metric = 58.1% * 50000\n",
"Finished Epoch [5]: [Training] loss = 1.468823 * 50000, metric = 53.4% * 50000\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-11-03 10:42:00 +03:00
"Final Results: Minibatch[1-626]: errs = 50.4% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvDSgozV4wRLGLRhQ0VtRYYouixraiIrbY\nokFjjMbYkleNvbeogG1tiYoNS+xdFwtGRCOgIiogHQGFvd8/7jPO7DC7O1vn7O7vc11zzcw5zznn\neeYszD1PNXdHREREJC3alToDIiIiIrkUnIiIiEiqKDgRERGRVFFwIiIiIqmi4ERERERSRcGJiIiI\npIqCExEREUkVBSciIiKSKgpOREREJFUUnEirYGaVZnZOPY+dYGa357wflJyvb+PlsP7MbPUkP6eW\nOi9SPTN7w8yeqOex95rZmMb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aua1LofCcRc4ucDyxBjBb6aY4Vd59mZnsSc5z8\njfjP905imOlTeee7AehDfKH+gagaf8zdK81sd+ILJtP59zsiSBldRPmKLXfBNEkZ9gGuIIKU8cQ8\nI+uyeHDS0DwAjCD6dnSm6iidjKuBvYmhsB2Jz+ks4LIC16yrmo4pWAZ3/9DMDiDu7+XEl/CVRK3P\nDUVco7prVvc5FnvsT/vc/UEzOwz4K3EPxxJB8glAj4JnqOHa7j7XzPoT87IMJubdGQMMdPfcezaM\n6EtyAhG0fU0Ei+fnpLmSmIBwV+J+jieGUl9VZL6kjbKGjywUEZG0SWaH/cTdB9SaWCRlSt7nxMzO\ntJiGe5bF9NAPmVmhzljVHb+NxdTYo5oynyIiaWQx5X+7vG27ERO5PV+aXIk0TMlrTizWoignZh/s\nQEx3vBGwgbsXGvqYe2x
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x17e35da0>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXeYFGXSwH8FEkROEDjBiGBAEAPgqYCgyKcYzoByBCMm\njBxiOj1UMOKdihnlTBgxB4wgRlQwLIiAopJUJCpIEBDYre+P6nZ6Z2d2Z2Znd2d36/c883T322+/\nXe/07E5NVb1Voqo4juM4juPkCjUqWgDHcRzHcZworpw4juM4jpNTuHLiOI7jOE5O4cqJ4ziO4zg5\nhSsnjuM4juPkFK6cOI7jOI6TU7hy4jiO4zhOTuHKieM4juM4OYUrJ47jOI7j5BSunDhpISIFInJN\nhtfOF5GHI8enBeO1z56EmSMizQN5Lq5oWaozIvK+iHyV5TELffZymQR/JwcFn8uuWbxHxn/HjlMe\nuHJSDYkoBQUi0ilJn5+C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VwCveYgiloF0XGS8TvwX2LfX6Bq3M8cKyIhO4mRKQp\ntvpmoqoW55rNCarKPBzDLSfVl0LmV1V9vKIEAWpjAYTPYjEE52H/SF4Lzn+CWR4ek1iK9JNJ/Msw\nD+gtIrdhS2TXBOM8hi3vHBHkPJiILRfuDtyrqtlSypKZtZ8G/gO8HMxhC+zL91ts1VS2eQZ4Avvy\nHxcX4AvwtYi8j71fy4G/YcGc0RT0PbFVRv2x968k9hWRIQna3yO9Zwi2KudyEdkJiyHoC+wFnB2x\nfD1ObIlxN+BjTKltjbmyDiOmyJQLqvqhiIwCrhCRfbAvy42Y9aoXtiT8xSC25Nag32uYIt4OOJzE\nrp8/P1eqqiJyHjAW+FI
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x1c7f1b38>"
2016-10-25 23:52:23 +03:00
]
},
"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",
"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:\n",
"\n",
2016-11-14 16:52:39 +03:00
"<img src=\"https://cntk.ai/jup/201/ResNetBlock2.png\">\n",
2016-10-25 06:42:43 +03:00
"\n",
"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",
2016-11-03 10:42:00 +03:00
"execution_count": 16,
2016-10-25 06:42:43 +03:00
"metadata": {
2016-11-01 06:03:17 +03:00
"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",
2016-10-26 06:41:49 +03:00
" if activation is None:\n",
" activation = lambda x: x\n",
" \n",
2016-11-01 06:03:17 +03:00
" r = Convolution(filter_size, num_filters, strides=strides, init=init, activation=None, pad=True, bias=False)(input)\n",
2016-10-26 06:41:49 +03:00
" 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",
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",
" return relu(p)\n",
"\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",
" 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",
2016-11-03 10:42:00 +03:00
"execution_count": 17,
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",
2016-10-26 06:41:49 +03:00
" 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",
2016-11-03 10:42:00 +03:00
"execution_count": 18,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": false
},
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",
2016-11-03 10:42:00 +03:00
"Finished Epoch [1]: [Training] loss = 1.871826 * 50000, metric = 70.2% * 50000\n",
"Finished Epoch [2]: [Training] loss = 1.571909 * 50000, metric = 58.3% * 50000\n",
"Finished Epoch [3]: [Training] loss = 1.445266 * 50000, metric = 53.2% * 50000\n",
"Finished Epoch [4]: [Training] loss = 1.338138 * 50000, metric = 48.8% * 50000\n",
"Finished Epoch [5]: [Training] loss = 1.257438 * 50000, metric = 45.6% * 50000\n",
2016-10-25 23:52:23 +03:00
"\n",
2016-11-03 10:42:00 +03:00
"Final Results: Minibatch[1-626]: errs = 43.5% * 10000\n",
2016-10-25 23:52:23 +03:00
"\n"
]
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvvSgQFVGM2GJvQWNj1WjsJVHQaDSxYIkl\n0SgaE5I3GvMm1jdqNHbEklijoMaS2MVeImrcFRtYoqhEFESKKKDA3u8f9znO2WF2d3bZ3Tk7+/tc\n11w75znteeYszL1PNXdHREREJC9qKp0BERERkSwFJyIiIpIrCk5EREQkVxSciIiISK4oOBEREZFc\nUXAiIiIiuaLgRERERHJFwYmIiIjkioITERERyRUFJ1IVzKzBzE5p47nvmtk1me3DkusNbL8ctp2Z\nrZ7k51eVzos0zcyeNbP72njuzWY2vr3zVOa925xvkY6i4ERyIxMUNJjZd5o4ZmKy/66iXZ682qKh\nxLntuq6DmQ0xs1+05zWlaWZ2beZ3qbnXNS1frWyL8jvoxO9hJWgNE8mdxSqdAZES5gAHAc9kE81s\nB2AVYG6Jc74GzG/j/dan478YDgI2BC7u4PtIuAJ4KLO9JnAGcBXwVCb97Xa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mdEGfdo6p5NfY7lnvvVPne/zcwOBf5APMM3iCB5KLByySs0c293/9zMtiPmZTmCmHdnPHCw\nu2ef2XVEX5KhRND2IREsnp455kJiAsLdiOc5gRhKfVGZ+ZJuyhZ9ZKGIiORNMjvsm+6+d4sHi+RM\nxfucmNkxyZTHM5PXM2a2ewvn7GjJFNMW01wf1ln5FRHJE4sp/2uK0nYnJnJ7rDK5Elk0Fa85SarF\nFxCduoyo9v4NsKm7L7Q
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x2c6ef438>"
2016-10-25 23:52:23 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2016-11-03 10:42:00 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFNXSgN8CySgqKKgYUFHBDJivIHjNAQMSVMwiZlE/\nMWO8posZzBLkiqKCqKgoCoogKouiSFAQFATJkvPW96N6nJ5hdnZmdnZ3drfe5+mnu0/ortM9u1NT\np6qOqCqO4ziO4zi5QqXSFsBxHMdxHCeMKyeO4ziO4+QUrpw4juM4jpNTuHLiOI7jOE5O4cqJ4ziO\n4zg5hSsnjuM4juPkFK6cOI7jOI6TU7hy4jiO4zhOTuHKieM4juM4OYUrJ05aiEi+iNydYd9ZIvJq\n6PzC4HrNsidh5ojIroE8N5a2LBUZERklIj9m+Zoxn71cJsHfSavgc9kyi/fI+O/YcUoCV04qICGl\nIF9Ejiygzeyg/r24Kg22TMhP0Der6yeISCcRuT6b13QKJ/isPJ2lyxXHmhopXTP0d5EvIptE5E8R\nGS4irYpBpoJIJGvaz0REThKRHknuUeJrl4hIj7hnHP+8ty9pmZzcZIvSFsApVdYA5wJjw4XBP+Kd\ngLUJ+tQANmZ4v70xBaU4ORfYF3iqmO/jlF8+AfoDAjQCrgI+F5GTV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LNm8AA7Mt/eJyDL8BkERmF\nPa8lwCGYM2c4Bf2ZWJTRRdjzK4wWInJHgvKRpPcOwaJybhGR3TAfgo7AAcDlIcvXa0RDjFsDYzCl\ntgk2lXU8UUWmRFDVL0XkBeBWETkI+7LcgFmv2mEh4YMD35L/Bu0+wBTxg4ETSTz188/nSlVVRK4E\n3gN+EMtpMg/722mqqic
2016-10-25 23:52:23 +03:00
"text/plain": [
2016-11-03 10:42:00 +03:00
"<matplotlib.figure.Figure at 0x1c76fe48>"
2016-10-25 23:52:23 +03:00
]
},
"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
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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",
"version": "3.4.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}