{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# DeepLearning\n", "\n", "## MNIST Dataset using DeepWater and Custom MXNet Model\n", "\n", "The MNIST database is a well-known academic dataset used to benchmark\n", "classification performance. The data consists of 60,000 training images and\n", "10,000 test images. Each image is a standardized $28^2$ pixel greyscale image of\n", "a single handwritten digit. An example of the scanned handwritten digits is\n", "shown\n", "![Example MNIST digit images](images/mnist.png)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Checking whether there is an H2O instance running at http://localhost:54321. connected.\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
H2O cluster uptime:2 hours 6 mins
H2O cluster version:3.11.0.99999
H2O cluster version age:9 hours and 12 minutes
H2O cluster name:arno
H2O cluster total nodes:1
H2O cluster free memory:13.65 Gb
H2O cluster total cores:12
H2O cluster allowed cores:12
H2O cluster status:locked, healthy
H2O connection url:http://localhost:54321
H2O connection proxy:None
Python version:2.7.12 final
" ], "text/plain": [ "-------------------------- ----------------------\n", "H2O cluster uptime: 2 hours 6 mins\n", "H2O cluster version: 3.11.0.99999\n", "H2O cluster version age: 9 hours and 12 minutes\n", "H2O cluster name: arno\n", "H2O cluster total nodes: 1\n", "H2O cluster free memory: 13.65 Gb\n", "H2O cluster total cores: 12\n", "H2O cluster allowed cores: 12\n", "H2O cluster status: locked, healthy\n", "H2O connection url: http://localhost:54321\n", "H2O connection proxy:\n", "Python version: 2.7.12 final\n", "-------------------------- ----------------------" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import h2o\n", "h2o.init()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import os.path\n", "PATH = os.path.expanduser(\"~/h2o-3/\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse progress: |█████████████████████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "test_df = h2o.import_file(PATH + \"bigdata/laptop/mnist/test.csv.gz\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse progress: |█████████████████████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "train_df = h2o.import_file(PATH + \"/bigdata/laptop/mnist/train.csv.gz\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Specify the response and predictor columns" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "y = \"C785\"\n", "x = train_df.names[0:784]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Convert the number to a class" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "train_df[y] = train_df[y].asfactor()\n", "test_df[y] = test_df[y].asfactor()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Train Deep Learning model and validate on test set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### LeNET 1989\n", "\n", "![lenet](./images/lenet.jpg)\n", "\n", "In this demo you will learn how to build a simple LeNET Model usix MXNET." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def lenet(num_classes):\n", " import mxnet as mx\n", " data = mx.symbol.Variable('data')\n", " # first conv\n", " conv1 = mx.symbol.Convolution(data=data, kernel=(5,5), num_filter=20)\n", " tanh1 = mx.symbol.Activation(data=conv1, act_type=\"tanh\")\n", " pool1 = mx.symbol.Pooling(data=tanh1, pool_type=\"max\", kernel=(2,2), stride=(2,2))\n", " # second conv\n", " conv2 = mx.symbol.Convolution(data=pool1, kernel=(5,5), num_filter=50)\n", " tanh2 = mx.symbol.Activation(data=conv2, act_type=\"tanh\")\n", " pool2 = mx.symbol.Pooling(data=tanh2, pool_type=\"max\", kernel=(2,2), stride=(2,2))\n", " # first fullc\n", " flatten = mx.symbol.Flatten(data=pool2)\n", " fc1 = mx.symbol.FullyConnected(data=flatten, num_hidden=500)\n", " tanh3 = mx.symbol.Activation(data=fc1, act_type=\"tanh\")\n", " # second fullc\n", " fc2 = mx.symbol.FullyConnected(data=tanh3, num_hidden=num_classes)\n", " # loss\n", " lenet = mx.symbol.SoftmaxOutput(data=fc2, name='softmax')\n", " return lenet" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "nclasses = 10 " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we instantiate our lenet model using 10 classes" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mxnet_model = lenet(nclasses)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To import the model inside the DeepWater training engine we need to save the model to a file:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "model_filename=\"/tmp/symbol_lenet-py.json\"\n", "mxnet_model.save(model_filename)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "plot\n", "\n", "\n", "convolution0\n", "\n", "Convolution\n", "5x5/1, 20\n", "\n", "\n", "activation0\n", "\n", "Activation\n", "tanh\n", "\n", "\n", "activation0->convolution0\n", "\n", "\n", "20x24x24\n", "\n", "\n", "pooling0\n", "\n", "Pooling\n", "max, 2x2/2\n", "\n", "\n", "pooling0->activation0\n", "\n", "\n", "20x24x24\n", "\n", "\n", "convolution1\n", "\n", "Convolution\n", "5x5/1, 50\n", "\n", "\n", "convolution1->pooling0\n", "\n", "\n", "20x12x12\n", "\n", "\n", "activation1\n", "\n", "Activation\n", "tanh\n", "\n", "\n", "activation1->convolution1\n", "\n", "\n", "50x8x8\n", "\n", "\n", "pooling1\n", "\n", "Pooling\n", "max, 2x2/2\n", "\n", "\n", "pooling1->activation1\n", "\n", "\n", "50x8x8\n", "\n", "\n", "flatten0\n", "\n", "Flatten\n", "\n", "\n", "flatten0->pooling1\n", "\n", "\n", "50x4x4\n", "\n", "\n", "fullyconnected0\n", "\n", "FullyConnected\n", "500\n", "\n", "\n", "fullyconnected0->flatten0\n", "\n", "\n", "800\n", "\n", "\n", "activation2\n", "\n", "Activation\n", "tanh\n", "\n", "\n", "activation2->fullyconnected0\n", "\n", "\n", "500\n", "\n", "\n", "fullyconnected1\n", "\n", "FullyConnected\n", "10\n", "\n", "\n", "fullyconnected1->activation2\n", "\n", "\n", "500\n", "\n", "\n", "softmax\n", "\n", "SoftmaxOutput\n", "\n", "\n", "softmax->fullyconnected1\n", "\n", "\n", "10\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# pip install graphviz\n", "# sudo apt-get install graphviz\n", "import mxnet as mx\n", "import graphviz\n", "mx.viz.plot_network(mxnet_model, shape={\"data\":(1, 1, 28, 28)}, node_attrs={\"shape\":'rect',\"fixedsize\":'false'})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The model is just the structure of the network expressed as a json dict" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\r\n", " \"nodes\": [\r\n", " {\r\n", " \"op\": \"null\", \r\n", " \"param\": {}, \r\n", " \"name\": \"data\", \r\n", " \"inputs\": [], \r\n", " \"backward_source_id\": -1\r\n", " }, \r\n", " {\r\n", " \"op\": \"null\", \r\n", " \"param\": {}, \r\n", " \"name\": \"convolution0_weight\", \r\n", " \"inputs\": [], \r\n", " \"backward_source_id\": -1\r\n", " }, \r\n", " {\r\n", " \"op\": \"null\", \r\n", " \"param\": {}, \r\n", " \"name\": \"convolution0_bias\", \r\n" ] } ], "source": [ "!head -n 20 $model_filename" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing the LeNET model architecture for training in H2O\n", "\n", "We have defined the model and saved the structure to a file. We are ready to start the training procedure." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from h2o.estimators.deepwater import H2ODeepWaterEstimator" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [], "source": [ "lenet_model = H2ODeepWaterEstimator(\n", " epochs=10,\n", " learning_rate=1e-3, \n", " mini_batch_size=64,\n", " network_definition_file=model_filename,\n", "# network='lenet', ## equivalent pre-configured model\n", " image_shape=[28,28],\n", " problem_type='dataset', ## Not 'image' since we're not passing paths to image files, but raw numbers\n", " ignore_const_cols=False, ## We need to keep all 28x28=784 pixel values, even if some are always 0\n", " channels=1\n", ")" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deepwater Model Build progress: |█████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "lenet_model.train(x=train_df.names, y=y, training_frame=train_df, validation_frame=test_df)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "model error: 0.0200332124248\n" ] } ], "source": [ "error = lenet_model.model_performance(valid=True).mean_per_class_error()\n", "print \"model error:\", error" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A More powerful Architecture\n", "\n", "the beauty of deeplearning is that we can compose a new model with even more \"capacity\" to try to get a higher accuracy." ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def cnn(num_classes):\n", " import mxnet as mx\n", " data = mx.symbol.Variable('data')\n", "\n", " inputdropout = mx.symbol.Dropout(data=data, p=0.1)\n", "\n", " # first convolution\n", " conv1 = mx.symbol.Convolution(data=data, kernel=(5,5), num_filter=50)\n", " tanh1 = mx.symbol.Activation(data=conv1, act_type=\"relu\")\n", " pool1 = mx.symbol.Pooling(data=tanh1, pool_type=\"max\", pad=(1,1), kernel=(3,3), stride=(2,2))\n", " \n", " # second convolution\n", " conv2 = mx.symbol.Convolution(data=pool1, kernel=(5,5), num_filter=100)\n", " tanh2 = mx.symbol.Activation(data=conv2, act_type=\"relu\")\n", " pool2 = mx.symbol.Pooling(data=tanh2, pool_type=\"max\", pad=(1,1), kernel=(3,3), stride=(2,2))\n", " \n", " # first fully connected layer \n", " flatten = mx.symbol.Flatten(data=pool2)\n", " fc1 = mx.symbol.FullyConnected(data=flatten, num_hidden=1024)\n", " relu3 = mx.symbol.Activation(data=fc1, act_type=\"relu\")\n", " inputdropout = mx.symbol.Dropout(data=fc1, p=0.5)\n", " \n", " # second fully connected layer\n", " flatten = mx.symbol.Flatten(data=relu3)\n", " fc2 = mx.symbol.FullyConnected(data=flatten, num_hidden=1024)\n", " relu4 = mx.symbol.Activation(data=fc2, act_type=\"relu\")\n", " inputdropout = mx.symbol.Dropout(data=fc2, p=0.5)\n", " \n", " # third fully connected layer\n", " fc3 = mx.symbol.FullyConnected(data=relu4, num_hidden=num_classes)\n", " # loss\n", " cnn = mx.symbol.SoftmaxOutput(data=fc3, name='softmax')\n", " return cnn" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [], "source": [ "nclasses = 10" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mxnet_model = cnn(nclasses)" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": true }, "outputs": [], "source": [ "model_filename=\"/tmp/symbol_cnn-py.json\"\n", "mxnet_model.save(model_filename)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from h2o.estimators.deepwater import H2ODeepWaterEstimator" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Importing the lenet model architecture for training in H2O\n" ] } ], "source": [ "print(\"Importing the lenet model architecture for training in H2O\")" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": true }, "outputs": [], "source": [ "model = H2ODeepWaterEstimator(\n", " epochs=20, \n", " learning_rate=1e-3, \n", " mini_batch_size=64,\n", " network_definition_file=model_filename,\n", " image_shape=[28,28], \n", " channels=1,\n", " ignore_const_cols=False ## We need to keep all 28x28=784 pixel values, even if some are always 0\n", ")" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deepwater Model Build progress: |█████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "model.train(x=train_df.names, y=y, training_frame=train_df, validation_frame=test_df)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "model error: 0.0111236907698\n" ] } ], "source": [ "error = model.model_performance(valid=True).mean_per_class_error()\n", "print \"model error:\", error" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing the results" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import matplotlib\n", "import numpy as np\n", "import scipy.io\n", "import matplotlib.pyplot as plt\n", "from IPython.display import Image, display\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [], "source": [ "df = test_df.as_data_frame()" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n", "image = df.T[int(np.random.random()*784)]" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "(785,)" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image.shape" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWEAAAF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ndrEF1EX6OL0n6gtbnc5Sk24d/8n7dzB40sx8rfUAz\nuEGDSv9FaS0/u7H3F1iaz26pQliDf7Uakq5F269p8Iux6j4v6R4NzhB8u6SbJf25mV0oeVALcJMG\nv/jr+jlKgz9n75b0byX9jqQ3SnrEzKzoUU1heKwPSHrcOefHJtbms8u8P2nJPrtmiRfdVM65q8Hq\nV8zsSUl/L+ktGvyJhBXhnHs4WP2qmX1Z0jcl3S7pc0UOanoPSnq1pDeUPpAFSb6/Zfvslq0S/p6k\nngYN89BlSc+f/+EslnPuB5KekrQSI89TeF6DXv5GfI6S5Jx7WoPf35X4LM3sQ5LulHS7c+654Ftr\n8dlVvL9TSn92SxXCzrmupC9KusNvG/6JcIekJ0od16KY2UUNPvjKX5JVM/ylfl7jn+MlDUas1+5z\nlCQze4WkG7UCn+UwoN4s6eedc98Kv7cOn13V+8vsX/SzW8Z2xB9I+oiZfVHSk5LeJWlf0kdKHtQ8\nmNnvS/rfGrQg/omk/ySpK+ljJY9rFsM+9hUNqiZJepWZvUbSi865b2vQi3uvmX1Dgyvk3a/BLJdP\nFjjcqVUDDt7bAAAA5UlEQVS9v+Fyr6SPaxBYVyT9ngZ/1Vw9/WzLw8we1GA61l2SDszMV7w/cM75\nqxiu7Gc36f0NP9fl+uxKT8/ITCt5hwYf/pGkv5T02tLHNKf39TENfpmPJH1L0kcl3Vz6uGZ8L2/U\nYOpPL1r+W7DPfRpMdzrU4Bf8Sunjnsf70+AyhY9p8D9xW9LfSfovkv5R6eOu8b5S76kn6e5ov5X8\n7Ca9v2X87LiUJQAUtFQ9YQDYNIQwABRECANAQYQwABRECANAQYQwABRECANAQYQwABRECANAQYQw\nABRECANAQYQwABT0/wFz9Domr91UeAAAAABJRU5ErkJggg==\n", "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.imshow(image[:-1].reshape(28, 28), plt.cm.gray);" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1\n" ] } ], "source": [ "print image[-1]" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse progress: |█████████████████████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "image_hf = h2o.H2OFrame.from_python(image.to_dict())" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "deepwater prediction progress: |██████████████████████████████████████████████████████████████| 100%\n" ] } ], "source": [ "prediction = model.predict(image_hf)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
predict
1
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "prediction['predict']" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 1 }