CNTK/Tutorials/CNTK_201B_CIFAR-10_ImageHan...

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

2016-10-25 06:42:43 +03:00
{
"cells": [
2017-02-03 04:40:20 +03:00
{
"cell_type": "code",
"execution_count": 25,
"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": 31,
"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": 31,
"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",
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",
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",
"from cntk.utils import *"
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",
2017-01-13 19:39:56 +03:00
" ImageDeserializer.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",
" 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",
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",
" 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",
" # 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",
2016-11-02 21:29:44 +03:00
" lr = lr_per_minibatch, momentum = momentum_time_constant, \n",
" l2_regularization_weight=l2_reg_weight)\n",
" trainer = Trainer(z, (ce, pe), [learner])\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",
" 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",
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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 2.062444 * 50000, metric = 75.3% * 50000 13.316s (3754.8 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.675133 * 50000, metric = 61.7% * 50000 13.772s (3630.5 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.520789 * 50000, metric = 55.4% * 50000 13.674s (3656.7 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.421881 * 50000, metric = 51.4% * 50000 13.668s (3658.2 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 1.338381 * 50000, metric = 48.0% * 50000 13.675s (3656.3 samples per second);\n",
2016-10-25 06:42:43 +03:00
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 43.3% * 10000\n",
2016-10-25 06:42:43 +03:00
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOX5//H3B1QQRGwR1Ii9FyJYEhULxl6TGHTtGvWb\noF8T9KeJ8auoSTR2jYolKPaNvWLvvS0YNSAaESwgqCBIFdj798d9xjk7O7s7u+zszM7er+uaa04/\nzzNnYO59qsyMEEIIIYRy0anUCQghhBBCSIvgJIQQQghlJYKTEEIIIZSVCE5CCCGEUFYiOAkhhBBC\nWYngJIQQQghlJYKTEEIIIZSVCE5CCCGEUFYiOAkhhBBCWYngJFQESbWSzmrhuRMk3ZhaPzK5Xr/W\nS2HLSVojSc/JpU5LaJik1yU92sJz/yVpbGunqcB7tzjdIRRLBCehbKSCglpJ2zZwzGfJ/odydlny\naonaPOe26rwOkqok/b41rxkaJmlE6rvU2OvGpq9WsMX5Dhr+PSyFmMMklJ0lSp2AEPKYCxwCvJre\nKGlHYDVgXp5zlgYWtvB+G1D8H4ZDgE2AK4p8n+CuBZ5Kra8FnAtcD7yU2v5xK95zAC3/oT8MUCum\nJYR2LYKTUI4eBX4t6SQzSwcNhwBvAyvlnmBm37f0Zma2oKXntleSupnZnFKno1jM7A3gjcy6pP7A\nX4DXzOyOQq4hqauZ5QuEG7pnS4NjzGxRS88NoRJFtU4oNwZUAysCu2Y2SloSOBC4gzx/Yea2OZF0\ndrJtHUk3SZou6VtJN0rqmnPuhAaK97tLuk7S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0wSXw4Y43BTYys3xdH9Pn9sTrpj8CeplZMerIQwihbEna\nAO8JVY1XrWyCd9n9Eti
2016-10-25 06:42:43 +03:00
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14663f064e0>"
2016-10-25 06:42:43 +03:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXeYFGXSwH8FEgQERQRMeKgYUERBUURMfIqYM2JOeCoq\noicGVDBnjKCiB+p5cCbMKIr5MJL1wISgIAIiWTJb3x/V7fTMzuzOzM7uzs7W73n66ek3db3Tszs1\n9VbVK6qK4ziO4zhOvlCjsgVwHMdxHMeJ4sqJ4ziO4zh5hSsnjuM4juPkFa6cOI7jOI6TV7hy4jiO\n4zhOXuHKieM4juM4eYUrJ47jOI7j5BWunDiO4ziOk1e4cuI4juM4Tl7hyomTESJSJCI3Ztl3pogM\njVyfFYzXLncSZo+IbBPIc0Vly1KdEZEPRWRKjseM++zlM0n+Tg4IPpf75/AeWf8dO05F4MpJNSSi\nFBSJyL4p2swK6l9LqNLgyIaiJH1zun+CiPQQkd65HNMpneCz8lCOhiuPPTXSGjPyd1EkIutF5FcR\nGS0iB5SDTKlIJmvG74mIdBOR/iXco8L3LhGR/gnvceL73bSiZXLykw0qWwCnUlkJnAp8Gi0M/hFv\nCaxK0mdDYF2W99sRU1DKk1OBXYAHy/k+TuHyDvAMIEBL4GLgfRE5XFVHV7QwqvqRiGyoqmsy7Ho4\nJvtNSerK8ndcVhS4EPgzSd3iCpbFyVNcOanejAJOEpHLVDWqNJwKjAOaJHbI4h9ktO/abPtWVUSk\nnqquqGw5nIz4XlWHhxci8gowBbgcSKqciIgAtVV1dXkIlOXfneR4vFzykqouzKSDiNQB1miS3Wpz\n8Xfmf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ain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x146068c5a90>"
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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 2.054147 * 50000, metric = 75.0% * 50000 13.674s (3656.6 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.695077 * 50000, metric = 62.6% * 50000 14.271s (3503.7 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.542115 * 50000, metric = 56.3% * 50000 13.872s (3604.3 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.450798 * 50000, metric = 52.3% * 50000 13.823s (3617.3 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 1.373555 * 50000, metric = 49.2% * 50000 13.857s (3608.4 samples per second);\n",
"Finished Epoch[6 of 300]: [Training] loss = 1.300828 * 50000, metric = 46.6% * 50000 13.965s (3580.3 samples per second);\n",
"Finished Epoch[7 of 300]: [Training] loss = 1.232516 * 50000, metric = 43.7% * 50000 13.827s (3616.0 samples per second);\n",
"Finished Epoch[8 of 300]: [Training] loss = 1.189415 * 50000, metric = 42.0% * 50000 13.885s (3600.9 samples per second);\n",
"Finished Epoch[9 of 300]: [Training] loss = 1.134052 * 50000, metric = 39.9% * 50000 13.871s (3604.6 samples per second);\n",
"Finished Epoch[10 of 300]: [Training] loss = 1.098405 * 50000, metric = 38.9% * 50000 13.961s (3581.3 samples per second);\n",
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 36.2% * 10000\n",
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3Xd4VGX2wPHvARQVBRRWQBcQBBVEUdC1YndtKOpPhWBn\nXRV0dVnXXtFVdl0FbNhBLETQtYAFsSt2g3VFcEFUREQBg3RIzu+Pc6/3zmSSTMpkJpPzeZ557tz3\ntvedCeTkraKqOOecc87likbZzoBzzjnnXJwHJ84555zLKR6cOOeccy6neHDinHPOuZziwYlzzjnn\ncooHJ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8WkabYKLDvsZqTc4H3gqAJrK/J\n89iIpSXYMOO+wI3VyJdrQDw4cbkmnb80U80JUdN1TVLd71xsbpFhwHrYaKHf5lhR1cUicgQ2x8l1\n2H++D2HDTF9Iut9ooCf2C/WvWNX4M6paKiKHYb9gws6/i7Ag5bM0ypduuVOeE5ThaGAEFqR8jc0z\nsg1lg5Oa5gFgEta3oxmJo3RCtwBHYUNhm2Kf02XATSmeWVUVXZOyDKr6uYgcj32/N2O/hEditT6j\n03hGec8s73NM99rfjqnq4yJyMnAl9h3OxILkIcAWKe9QwbNVdbmI9MHmZTkdm3dnBnCiqsa/swew\nviRDsKDtByxYHBY7ZyQ2AeEh2Pf5NTaUelSa+XINlNR8ZKFzzrlcE8wOO0tV+1V6snM5Jut9TkTk\nUrFpuJeKTQ/9pIik6oxV3vV7iU2NPT2T+XTOuVwkNuV/o6S0Q7GJ3F7NTq6cq5ms15yIrUVRiM0+\n2ASb7rgH0E1VUw19jF/
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14606872668>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFFXWgN8DIkkFEQEzilkMgGGNqOhiQkVdcTC7ZlaR\nNa0ZxV3DKhhRjIAoqKufYkRBUQQUHZIoGJGgBFFAwhDnfD9OlV3d0z3T3fTM9DTnfZ56qurWrVvn\ndvdMnz73BFFVHMdxHMdx8oVa1S2A4ziO4zhOFFdOHMdxHMfJK1w5cRzHcRwnr3DlxHEcx3GcvMKV\nE8dxHMdx8gpXThzHcRzHyStcOXEcx3EcJ69w5cRxHMdxnLzClRPHcRzHcfIKV06cjBCRUhG5Nct7\nfxKRZyLn5wbjtc2dhNkjItsF8vyzumVZnxGRkSIyOcdjxn328pk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j2w+nSSN86WNTFr5hjLJi/1NYi\nclHizSJSL1C4qpqXMNnLpIYXkdqBBQnMyXYNFsUTpUcazxiPKWhXRcZLxrLgueW+f8FS53vASSIS\nLjchIs2x6JtRqlre0mxeUCjzcAy3nKy/xJlfVfW56hIE2BBzIHwJ8yG4DPtH8mZwfQxmeRgosRTp\nZ5H8l2ExcLqI3I+FyC4NxhmIhXf2DnIejMLChTsAj6pqrpSyVGbtIcA9wGvBHBpiX77fYFFTueZF\nYBD25T8swcEX4GsRGYm9Xr8D+2HOnNEU9J2xKKPzsNevIvYVkZuStH9IZu8hWFTOdSLSEvMhOAPY\nC7goYvl6jliI8RHAaEyp3Q1byvorMUWmSlDVj0WkH/AvEdkH+7JcjVmvTsNCwl8NfEvuC/q9iSni\nbYBjSL708+fnSlVVRC4
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14606eb3f28>"
]
},
"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": [
"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",
2016-11-29 05:56:43 +03:00
" image_data = np.array(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-02-03 04:40:20 +03:00
"\tLabel: truck , confidence: 98.95%\n",
"\tLabel: ship , confidence: 0.46%\n",
"\tLabel: automobile, confidence: 0.26%\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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 2.123667 * 50000, metric = 78.7% * 50000 16.391s (3050.5 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.817045 * 50000, metric = 67.9% * 50000 16.894s (2959.5 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.678272 * 50000, metric = 62.2% * 50000 17.006s (2940.1 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.583182 * 50000, metric = 58.1% * 50000 16.644s (3004.1 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 1.514311 * 50000, metric = 55.3% * 50000 16.790s (2977.9 samples per second);\n",
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 49.2% * 10000\n",
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvDSooRBALiFF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\n5P9CGg3sZWYXE8NSZyf3uZWYT+MSM9uY6PDYEdgGuNrdGysoq6kZ4C7gfODBpAwdiIDwI2LUVGO7\nmxj2Ogx4MqeDL8A4M3ue+HnNADYi5re5InXO7sQoo4OJn19TegI4B3jczG4gapmOIEbRVJsMMI/m\naH45jfi5vmxmtwIrEb+r79OwP0CvJobc32lmVxH9XvYhfh+OTHW8vd3M2hGjwL4kak7+CLyeBE0Q\nfU0eJ0YsfUsMM94ZuKAB+ZJWRMGJlJpC/tLMNyfE4q5rku9+fyTmFvkLsCQxWuinOVbcfYaZ7UTM\ncfI34j/f24hhpk/m3G8E0J/4Qv0TUTX+iLtXmtkOxBdMpvPvN0SQMraA8hVa7rznJGXYDbiECFLG\nE/OM9KZ6cLK4eQB4iOjb0YGqo3QyLgd2JYbCtiN+TqcCF+X5zPqq7Zq8ZXD398xsT+L5Xkx8CV9K\n1PqMKOAzavrMmn6OhV770zF3v9fMDgDOIJ7hR0SQPAzonvcOtXy2u88xs4HEvCyHEPPufADs5+7p\nZ3Yz0ZdkGBG0TSGCxb+kzrmUmIBwMPE8xxNDqS8rMF/SStnijywUEZFSk8wO+z93H1LnySIlpuh9\nTszsFItpuL+zmB76ATPL1xmrpus3s5gae0xT5lNEpBRZTPnfJidte2Iit+eKkyuRxVP0mhOLtShG\nEbMPLkFMd9wP6OPu+YY
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14606e63da0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJztnWeYFNXSgN8iCwiKqBhAFAOIIsGMYr7oVcSMKBcjmBX8\njNeA13DFiAmzAqKiXiOYUMyCioCCKIooIIpKUpActr4f1e30zM7szszO7s7O1vs8/XT36dPddaYn\n1NSpIKqK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nZCShJiUp3umI+sBx7fRNpg/lmVIVIlkIZh4OHEjvYNAqWFOk6zKG0oukrIlFF\n+VzMovB6sL8O+zKOhg3XCfolsozk0zwvYGbf83MhcBb8ADQWkZ3CBhHZDDgq1zdSi3gYjU3tnIhF\nO7wS7SMiTRLOWY5NMdSN9GkkIjuISHQKJlsyeYZgf5zOjvStjUVdzMccY8H8pbYUkT6JJ4tIvUDh\nqmiew2QvlhpeRGoGFiQwJ9u1WBRPlP5p3GMSpqD1i1wvGcuC+5b4/IKpzreA7iISTjchIpti0Tcf\nqWpJU7N5QaGMwzHcclJ9iTO/qurwyhIEqIM5ED6H+RCcg32RvBocH4dZHp6QWIr0XiT/ZzgROEFE\n7sBCZJcG13kCC++8M8h58BEWLnwQMFhVc6WUpTJrPwPcArwcjKEB9uP7HRY1lWueBZ7EfvxHJzj4\nAnwjIu9jr9ciYDfMmTOagv5oLMroVOz1K41dReSqJO3vkdkzBIvKuUxEWmI+BCcC7YA+EcvXcGIh\nxgcAYzGltg02lfUPYopMhaCqH4rIQ8AVItIe+7Fcg1mvjsNCwl8MfEtuD/q9iiniHYBDST718/f7\nSlVVRM4BRgJfiuU0+RX
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14606ebaef0>"
]
},
"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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 1.512835 * 50000, metric = 54.1% * 50000 15.499s (3226.1 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.206524 * 50000, metric = 42.8% * 50000 16.071s (3111.2 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.087695 * 50000, metric = 38.3% * 50000 16.160s (3094.1 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.008182 * 50000, metric = 35.4% * 50000 16.057s (3113.8 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 0.953168 * 50000, metric = 33.4% * 50000 16.247s (3077.4 samples per second);\n",
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 30.8% * 10000\n",
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XecVNX5x/HPFxRUVIgNGxaiKHbBEkXs3QQ0sa29xZ8t\nGmKiMcaoaUZjLFE0drGtGmPBEjv2voiKIBKxISIqsCod9vn98dxx7s7O7s6W2Zndfd6v17xm77nn\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+3Mh2Pz6KpsxhgHm3R/XI2/rm+IOkWYCX8d/VdmvcH6HB8yv0dkq7Ex70cjP8+\nnJAaeHubpO74LLDP8JaTU4BXk6AJfKzJf/EZSzPwacY/Bi5qRrlCJxLBSSg3hfylmW9NiJY+1yTf\n+U7B1xY5H1gcny30/RorZjZd0j74Gid/wv/zvRWfZvpYzvmuAjbFv1B/iTeNP2RmNZL2wr9gMoN/\nv8aDlHcKqF+h9c6bJ6nDvsAleJDyIb7OSD/qBictLQPASHxsRw9qz9LJuBwYgk+F7Y5/Tr8DLs5z\nzaZq6Ji8dTCzsZIOwO/vP/Av4UvxVp+rCrhGfdes73Ms9Njv95nZPZIOB87B7+EEPEg+CVg17xka\nuLaZzZI0GF+X5Wh83Z3xwKFmlr5nN+NjSU7Cg7bP8WDx/FSeS/EFCPfA7+eH+FTqywosV+ik1PKZ\nhSGEEMpNsjrs+2Y2tNHMIZSZko85kXSWfBnub+TLQ98nKd9grPqOHyRfGnt0McsZQgjlSL7kf5ec\ntD3xhdxGlaZUIbRMyVtO5M+iqMRXH1wMX+54I6C/meWb+pg+tifeNz0R6G1mxegjDyGEsiVpPXwm\nVCXetbIhPmV3KrBJM6f
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14607031ac8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXecFFXywL8FIkgUQcCEoiKCCcGsiOjPfOaIAcF0iGdA\n71BRQfHuzHqggBFQVEyYsxhBQJRkAgOCqGTJQdLW74/qdnpmZ3ZnZmd3Z3fr+/n0p7tfv1Cve2a6\n5r2qeqKqOI7jOI7j5AvVylsAx3Ecx3GcKK6cOI7jOI6TV7hy4jiO4zhOXuHKieM4juM4eYUrJ47j\nOI7j5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nb8R+jKNuw5sG+RJZRfJpnpHYsO8/ciFwFswAGojI7mGCiGwFnJzrhtQ8Ht7FpnbOxrwdXo3mEZEt\nEsqsxqYYakby1BeRViISnYLJlkyeIdgfp+6RvDUwr4uFmGEsmL3UtiJySWJhEakVKFxlzfOY7IVC\nw4tI9WAECczIdgPmxROlZxptTMIUtKsj9SVjVdBukc8vmOp8DzhJRMLpJkSkKeZ9M1pVi5qazQsq\nSz8cw0dOqi5xw6+qOry8BAE2xQwIn8dsCC7DfkjeCK6PxUYenpRYiPTzSP7PcCJwpojci7nIrgzq\neRJz77wviHkwGnMXPgIYqKq5UspSDWs/C9wJvBL0oQ728v0e85rKNc8BT2Ev/3cTDHwBvhORj7H7\ntRjYFzPmjIagPwXzMuqK3b/i2EdEbkyS/hGZPUMwr5xeIrIDZkNwNrAncElk5Gs4MRfjTsBnmFLb\nGpvKOoqYIlMmqOqnIvIwcL2ItMVeluux0avTMZfwlwLbknuCfG9givjewDEkn/r563OlqioilwGv\nAVPEYprMxb47bVT12CD
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x146072a3ba8>"
]
},
"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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 2.253115 * 50000, metric = 83.6% * 50000 46.007s (1086.8 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.931100 * 50000, metric = 71.8% * 50000 46.236s (1081.4 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.706618 * 50000, metric = 63.3% * 50000 46.271s (1080.6 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.576171 * 50000, metric = 58.1% * 50000 46.348s (1078.8 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 1.473403 * 50000, metric = 53.7% * 50000 46.386s (1077.9 samples per second);\n",
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 51.2% * 10000\n",
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00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0r0LTnCUkPkLYZ3b1TriXV7lBj2vm/qeh2In9HZwIvJvtxn\n5UQHZ0ieV540XxOj5zoiUgcNJZZSU6O62t1vqy1hC1gReNLM7iE6tx4HPO/uDyfHXyJqHm41s38m\n+w4l/y+kKuBAM7uEGJb6dXKdW4n5NC41sx8THR5XAXYBrnL3pgrKamsGuAv4G3B/UobOREA4iRg1\n1dTuJoa9DgNG53TwBZhgZs8Q39dM4IfE/Db/TKXZnxhldATx/TWnUcD5wH/N7AailuloYhTNMpMB\n5tESzS+nE9/rC2Z2K7AW8bP6Pxr2B+hVxJD7O83sSqLfy8HEz8OxqY63t5tZR2IU2CdEzckJwKtJ\n0ATR1+S/xIilWcQw458DFzUgX9KGKDiRUlPIX5r55oRo7Lom+a53AjG3yDnACsRooe/mWHH3mWa2\nFzHHyV+I/3xvI4aZjs653tXAAOIX6u+IqvGH3b3azPYgfsFkOv9+RQQpbxdQvkLLnTdNUob9gEuJ\nIGUqMc9IX5YNThqbB4AHib4dnak5SifjcmAfYihsR+J7+n/AxXnuubzqOidvGdx9vJn9kni+lxC/\nhC8jan2uLuAetd2ztu+x0HO/O+bu95rZYcAZxDOcRATJw4B18l6hjnu7+3wzG0zMyzKUmHdnInCI\nu6ef2S1EX5JhRNA2nQgWz0mluYyYgHA34nlOJYZS/6PAfEkbZY0fWSgiIqUmmR32XXfft97EIiWm\n6H1OzOw0i2m451pMD32fmeXrjFXb+dtZTI09pjnzKSJSiiym/G+Xs293YiK3p4uTK5HGKXrNicVa\nFJXE7IMdiOmO+wP93D3
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x146072e6860>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnXeYFGXSwH9FNCBgAswioiJG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qouB54DnRGQ9zDR/K+bImWsOJP1nCLC5WG6P+I/HjtjzDZ2XpwG7qeoHVSBvtkzDHGXHaPlhxeG0\nQ1ti/95FZBMqtj5Mwz43uwDlKVHpTlfMB1Zgr28i7TDfjNoQyVIo43DwUGIHm0bBkiLdijmUVjcX\niEhcUb4IsygMDfaLsS/jeNhwo6BfIstJPs3zOmb2vSQXAmfBNKCZiOwSNojIZsCfcn0jtYiH97Cp\nnVOwaIch8T4islHCOSuwKYbGsT5NRWRHEYlPwWRLJs8Q7I/ThbG+DbGoi/mYYyyYv9SWInJ+4ski\nsk6gcFU3r2Kyl0kNLyL1AwsSmJPtWiyKJ06fNO4xDlPQrohdLxnLg/uW+/yCqc7hwPEiEk43ISIt\nseibUapa3tRsXlAo43AMt5zUXUqZX1X1+ZoSBGiEORC+ivkQ9Ma+SN4Jjo/BLA+DJEqR/heS/zMs\nAk4Wkb5YiOyy4DqDsPDOB4OcB6OwcOFDgH6qmiulLJVZ+2XgXuDNYAzrYz++U7CoqVzzCvAC9uP/\nXoKDL8A3IvIh9notBPbGnDnjKehPwKKMzsJev4rYS0RuTNL+AZk9Q7ConGtFZFvMh+AUYDfg/Jjl\n63miEOODgNGYUtsOm8o6nEiRqRZU9SMR6Q9cLyJ7YD+WazDrVQ8sJPyNwLfkgaDfO5gividwJMmn\nfv54X6mqikhv4C3gS7G
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x1460735c908>"
]
},
"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": 26,
"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": 26,
"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",
2017-02-03 04:40:20 +03:00
"execution_count": 27,
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",
2017-02-03 04:40:20 +03:00
"execution_count": 28,
2016-10-25 06:42:43 +03:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def create_resnet_model(input, out_dims):\n",
2016-11-02 04:03:02 +03:00
" conv = convolution_bn(input, (3,3), 16)\n",
2016-11-02 21:29:44 +03:00
" r1_1 = resnet_basic_stack(conv, 16, 3)\n",
2016-10-25 06:42:43 +03:00
"\n",
" r2_1 = resnet_basic_inc(r1_1, 32)\n",
2016-11-02 04:03:02 +03:00
" r2_2 = resnet_basic_stack(r2_1, 32, 2)\n",
2016-10-25 06:42:43 +03:00
"\n",
" r3_1 = resnet_basic_inc(r2_2, 64)\n",
2016-11-02 04:03:02 +03:00
" r3_2 = resnet_basic_stack(r3_1, 64, 2)\n",
2016-10-25 06:42:43 +03:00
"\n",
" # Global average pooling\n",
" 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",
2017-02-03 04:40:20 +03:00
"execution_count": 29,
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-02-03 04:40:20 +03:00
"Finished Epoch[1 of 300]: [Training] loss = 1.859668 * 50000, metric = 69.3% * 50000 47.499s (1052.7 samples per second);\n",
"Finished Epoch[2 of 300]: [Training] loss = 1.583096 * 50000, metric = 58.7% * 50000 48.541s (1030.0 samples per second);\n",
"Finished Epoch[3 of 300]: [Training] loss = 1.453993 * 50000, metric = 53.4% * 50000 48.982s (1020.8 samples per second);\n",
"Finished Epoch[4 of 300]: [Training] loss = 1.347815 * 50000, metric = 49.2% * 50000 48.704s (1026.6 samples per second);\n",
"Finished Epoch[5 of 300]: [Training] loss = 1.269185 * 50000, metric = 45.8% * 50000 48.155s (1038.3 samples per second);\n",
"\n",
2017-02-03 04:40:20 +03:00
"Final Results: Minibatch[1-626]: errs = 44.6% * 10000\n",
"\n"
]
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzt3XeYVOXZx/HvDxAREBQL9i6KYgNrLNhbIqhR49pLNIpG\nxZbXGFsSgzGxK3YBo25ibNhFo8YWG2BHTUBEQEWlIyiy9/vHfcY5O8zuz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Ogb//hrTk8Cf\ngCck3YbXMp2Ij6JZbDLAIpqi+eV8/Ht9SdKdwIr4z+r71O0P0BvwIff3SLoe7/dyKP7zcFKq4+1d\nkpbER4FNwWtOTgVeS4Im8L4mT+Ajlmbgw4x/Blxeh3yFNiSCk5A1pfylWWxOiPqua1Lseqfic4tc\nAiyBjxb6cY4VM5su6af4HCd/wP/z/Rs+zPSpgusNBTbDf6GegVeNP2pmFZL2wX/B5Dr/foMHKe+W\nUL5Sy130mKQM+wNX4kHKJ/g8I71YPDipbx4AHsb7dnSh8iidnGuAAfhQ2CXx7+m3wF+L3LO2qjun\naBnM7D1JB+PP9wr8l/BVeK3P0BLuUdU9q/oeSz33x31mdp+kI4EL8Gf4ER4kDwJWKXqFau5tZvMk\n7YjPy3IsPu/OOOBwM0s/s+F4X5JBeND2OR4sXpI65ip8AsK98Of5CT6U+uoS8xXaKNV/ZGEIIYSs\nSWaH/djMBtZ4cAgZ0+x9TiSdJ5+Ge7Z8eugHJRXrjFV4XkdJl8qnHl8gaYKkY5ogyyGEkBnyKf/b\nFaTtjU/k9lzz5CqE+slCs86O+Hj5N/H8DMGHo/U2s2JDH3P+iXckPBbv1LcyGQi2Qgihia2L9xkq\nx5tWNsaH7H4K3N6cGQu
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x14606ffbd30>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2017-02-03 04:40:20 +03:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAicAAADeCAYAAADmUqAlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAPYQAAD2EBqD+naQAAIABJREFUeJzsnWeYFMXWgN8DCBhRVMSACCoCYgIEwxVzuCbMCqJivMaL\nqNesGK75AzOKegETGFEwopglShBUQFGCSEYQyWnP9+N0072zs7szs7O7s7vnfZ5+uru6qvrU9M72\nmaoTRFVxHMdxHMfJFaqVtwCO4ziO4zhxXDlxHMdxHCencOXEcRzHcZycwpUTx3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uHD4Hw99s847jZcM6iXyHKSL/O8jU37Xp0NgTPgN6COiLQIC0Rke+CUbN9IzeNhMLa0\ncw7m7TAwXkdE6ia0WYEtMdSK1dlCRPYQkfgSTKak8wzBfjhdHqu7EeZ1sQAzjAWzl9pJRC5NbCwi\ntQOFq6x5A5O9QGh4EakezCCBGdmuw7x44nRN4R5jMQXt2lh/yVge3LfI5xcsdX4CtBeRcLkJEdkO\n8775RlWLWprNCSrLOBzDZ06qLvmmX1X15fISBKiJGRC+gdkQXIH9I3k/uD4Mm3l4SaIQ6Z1I/stw\nDHCWiHTHXGSXBf28hLl39ghiHnyDuQsfCTytqtlSygqb1n4NeAh4NxjDptjL92fMayrbvA68gr38\nBycY+AJMFJEvsc9rEbA/ZswZD0F/KuZl1Bn7/IqjtYjclqT8C9J7hmBeOTeKyC6YDcE5wN7ApbGZ\nr5eJXIwPB4ZiSm0zbCnrGCJFpkxQ1a9FpBdws4jsi70s12KzV2dgLuEDAtuS/wvqvY8p4vsBx5F8\n6WfD35WqqohcAQwCvhe
"text/plain": [
2017-02-03 04:40:20 +03:00
"<matplotlib.figure.Figure at 0x146074da400>"
]
},
"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": {
"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",
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
}