From 89939c617191828b8172836341780ab7be8ceb7b Mon Sep 17 00:00:00 2001 From: sunilmallya Date: Thu, 2 Mar 2017 18:04:36 -0800 Subject: [PATCH 1/8] fix mod.score call with metric parameter (#43) --- python/how_to/finetune.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/how_to/finetune.ipynb b/python/how_to/finetune.ipynb index 246582d0a..8eb5e529b 100644 --- a/python/how_to/finetune.ipynb +++ b/python/how_to/finetune.ipynb @@ -21,7 +21,7 @@ "\n", "## Prepare data\n", "\n", - "We follow the standard protocal to sample 60 images from each class as the training set, and the rest for the validation set. We resize images into 256x256 size and pack them into the rec file. The scripts to prepare the data is as following. \n", + "We follow the standard protocol to sample 60 images from each class as the training set, and the rest for the validation set. We resize images into 256x256 size and pack them into the rec file. The scripts to prepare the data is as following. \n", "\n", "\n", "```sh\n", @@ -192,7 +192,8 @@ " optimizer='sgd',\n", " optimizer_params={'learning_rate':0.01},\n", " eval_metric='acc')\n", - " return mod.score(val)" + " metric = mx.metric.Accuracy()\n", + " return mod.score(val, metric)" ] }, { @@ -521,7 +522,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.6" + "version": "2.7.11" } }, "nbformat": 4, From 90c9667d15c8d829179b4a1f30f9d8fbd86f967f Mon Sep 17 00:00:00 2001 From: ik_vision Date: Fri, 7 Apr 2017 11:24:38 -0700 Subject: [PATCH 2/8] read binary file in python 3 (#48) open('test_images/ILSVRC2012_val_00000001.JPEG').read() Creates the following error in python 3 as it decodes it wrongly: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte Proposed fixed: mx.image.imdecode(open('test_images/ILSVRC2012_val_00000001.JPEG','rb').read()) --- python/basic/advanced_img_io.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/basic/advanced_img_io.ipynb b/python/basic/advanced_img_io.ipynb index ac9405a4c..de44e5fd7 100644 --- a/python/basic/advanced_img_io.ipynb +++ b/python/basic/advanced_img_io.ipynb @@ -136,7 +136,7 @@ "# mx.image\n", "tic = time.time()\n", "for i in range(N):\n", - " img = mx.image.imdecode(open('test_images/ILSVRC2012_val_00000001.JPEG').read())\n", + " img = mx.image.imdecode(open('test_images/ILSVRC2012_val_00000001.JPEG','rb').read())\n", "mx.nd.waitall()\n", "print(N/(time.time()-tic), 'images decoded per second with mx.image')\n", "plt.imshow(img.asnumpy()); plt.show()" From f2df272fb2d8aa5aa830ce43648b4d86a65de405 Mon Sep 17 00:00:00 2001 From: Zack Chase Lipton Date: Mon, 24 Apr 2017 14:36:00 -0400 Subject: [PATCH 3/8] language rewrite (#54) * language rewrite * revision pass for typos --- python/how_to/finetune.ipynb | 108 +++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 25 deletions(-) diff --git a/python/how_to/finetune.ipynb b/python/how_to/finetune.ipynb index 8eb5e529b..3def9b0ac 100644 --- a/python/how_to/finetune.ipynb +++ b/python/how_to/finetune.ipynb @@ -2,15 +2,41 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "# Fine-tune with Pre-trained Models\n", "\n", - "In practice the dataset we use is relative small, so that we do not train an neural network from scratch, namely staring from random initialized parameters. Instead, it is common to train a neural network on a large-scale dataset and then use it either as an initialization or a fixed feature extractor. On [predict.ipynb](./predict.ipynb) we explained how to do the feature extraction, this tutorial will focus on how to use pre-trained model to fine tune a new network.\n", + "Many of the exciting deep learning algorithms for computer vision \n", + "require massive datasets for training. \n", + "The most popular benchmark dataset, [ImageNet](http://www.image-net.org/), for example,\n", + "contains one million images from one thousand categories.\n", + "But for any practical problem, we typically have access to comparatively small datasets.\n", + "In these cases, if we were to train a neural network's weights from scratch, \n", + "starting from random initialized parameters, we would overfit the training set badly. \n", "\n", - "The idea of fine-tune is that, we take a pre-trained model, replace the last fully-connected layer with new one, which outputs the desired number of classes and initializes with random values. Then we train as normal except that we may often use a smaller learning rate since we may already very close the final result. \n", + "One approach to get around this problem is to first pretrain a deep net on a large-scale dataset, like ImageNet.\n", + "Then, given a new dataset, we can start with these pretrained weights when training on our new task.\n", + "This process commonly called \"fine-tuning\". \n", + "There are anumber of variations of fine-tuning. \n", + "Sometimes, the initial neural network is used only as a _feature extractor_. \n", + "That means that we freeze every layer prior to the output layer and simply learn a new output layer. \n", + "In [another document](./predict.ipynb), \n", + "we explained how to do this kind of feature extraction.\n", + "Another approach is to update all of networks weights for the new task, \n", + "and that's the appraoch we demonstrate in this document.\n", "\n", - "We will use pre-trained models on the Imagenet dataset to fine-tune the smaller caltech-256 dataset as an example. But note that it can be used to other datasets as well, even for quite different applications such as face identification. \n", + "To fine-tune a network, we must first replace the last fully-connected layer \n", + "with a new one that outputs the desired number of classes. \n", + "We initialize its weights randomly.\n", + "Then we continue training as normal. \n", + "Sometimes it's common use a smaller learning rate \n", + "based on the intuition that we may already be close to a good result. \n", + "\n", + "In this demonstration, we'll fine-tune a model pre-trained on ImageNet to the smaller caltech-256 dataset. \n", + "Following this example, you can finetune to other datasets, even for strikingly different applications such as face identification. \n", "\n", "We will show that, even with simple hyper-parameters setting, we can match and even outperform state-of-the-art results on caltech-256.\n", "\n", @@ -50,7 +76,9 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [], "source": [ @@ -66,17 +94,21 @@ { "cell_type": "markdown", "metadata": { - "collapsed": true + "collapsed": true, + "deletable": true, + "editable": true }, "source": [ - "Next we define the function which returns the data iterators." + "Next we define the function which returns the data iterators:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [], "source": [ @@ -105,18 +137,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ - "We then download a pretrained 50-layer ResNet model and load into memory. \n", - "\n", - "Note. If `load_checkpoint` reports error, we can remove the downloaded files and try `get_model` again." + "We then download a pretrained 50-layer ResNet model and load into memory. Note that if `load_checkpoint` reports an error, we can remove the downloaded files and try `get_model` again." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [], "source": [ @@ -130,7 +165,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "## Train\n", "\n", @@ -141,7 +179,9 @@ "cell_type": "code", "execution_count": 4, "metadata": { - "collapsed": true + "collapsed": true, + "deletable": true, + "editable": true }, "outputs": [], "source": [ @@ -162,7 +202,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "Now we create a module. We first call `init_params` to randomly initialize parameters, next use `set_params` to replace all parameters except for the last fully-connected layer with pre-trained model. " ] @@ -171,7 +214,9 @@ "cell_type": "code", "execution_count": 5, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [], "source": [ @@ -198,7 +243,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "Then we can start training. We use AWS EC2 g2.8xlarge, which has 8 GPUs." ] @@ -207,7 +255,9 @@ "cell_type": "code", "execution_count": 6, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [ { @@ -350,19 +400,24 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "\n", - "As can be seen, even for 8 data epochs, we can get 78% validation accuracy. It matches the state-of-the-art results training on caltech-256 alone, e.g. [VGG](http://www.robots.ox.ac.uk/~vgg/research/deep_eval/). \n", + "As you can see, after only 8 epochs, we can get 78% validation accuracy. This matches the state-of-the-art results training on caltech-256 alone, e.g. [VGG](http://www.robots.ox.ac.uk/~vgg/research/deep_eval/). \n", "\n", - "Next we try to use another pretrained model. It uses the complete Imagenet dataset, which is 10x larger than the Imagenet 1K classes one, and is trained with a 3x deeper Resnet network. " + "Next, we try to use another pretrained model. This model was trained on the complete Imagenet dataset, which is 10x larger than the Imagenet 1K classes version, and uses a 3x deeper Resnet architecture. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { - "collapsed": false + "collapsed": false, + "deletable": true, + "editable": true }, "outputs": [ { @@ -500,7 +555,10 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "deletable": true, + "editable": true + }, "source": [ "As can be seen, even for a single data epoch, it reaches 83% validation accuracy. After 8 epoches, the validation accuracy increases to 86.4%. " ] @@ -522,7 +580,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.13" } }, "nbformat": 4, From 8c15b09c31f9a74feb6bcd45c8176c23ccdecf4f Mon Sep 17 00:00:00 2001 From: Wang Date: Wed, 3 May 2017 17:03:24 -0700 Subject: [PATCH 4/8] Fix tutorial warning --- python/basic/record_io.ipynb | 2 +- python/how_to/finetune.ipynb | 9 +++++---- python/how_to/predict.ipynb | 4 ++-- python/tutorials/char_lstm.ipynb | 18 +++++++++--------- python/tutorials/matrix_factorization.ipynb | 19 +++++++++---------- python/tutorials/predict_imagenet.ipynb | 10 +++++----- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/python/basic/record_io.ipynb b/python/basic/record_io.ipynb index 957f58a4e..8cd31e52b 100644 --- a/python/basic/record_io.ipynb +++ b/python/basic/record_io.ipynb @@ -82,7 +82,7 @@ " item = record.read()\n", " if not item:\n", " break\n", - " print item\n", + " print(item)\n", "record.close()" ] }, diff --git a/python/how_to/finetune.ipynb b/python/how_to/finetune.ipynb index 3def9b0ac..06768d232 100644 --- a/python/how_to/finetune.ipynb +++ b/python/how_to/finetune.ipynb @@ -207,7 +207,7 @@ "editable": true }, "source": [ - "Now we create a module. We first call `init_params` to randomly initialize parameters, next use `set_params` to replace all parameters except for the last fully-connected layer with pre-trained model. " + "Now we create a module. We pass the argument parameters of the pre-trained model to replace all parameters except for the last fully-connected layer. For the last fully-connected layer, we use an initializer to initialize. " ] }, { @@ -227,15 +227,16 @@ "def fit(symbol, arg_params, aux_params, train, val, batch_size, num_gpus):\n", " devs = [mx.gpu(i) for i in range(num_gpus)]\n", " mod = mx.mod.Module(symbol=new_sym, context=devs)\n", - " mod.bind(data_shapes=train.provide_data, label_shapes=train.provide_label)\n", - " mod.init_params(initializer=mx.init.Xavier(rnd_type='gaussian', factor_type=\"in\", magnitude=2))\n", - " mod.set_params(new_args, aux_params, allow_missing=True)\n", " mod.fit(train, val, \n", " num_epoch=8,\n", + " arg_params=arg_params,\n", + " aux_params=aux_params,\n", + " allow_missing=True,\n", " batch_end_callback = mx.callback.Speedometer(batch_size, 10), \n", " kvstore='device',\n", " optimizer='sgd',\n", " optimizer_params={'learning_rate':0.01},\n", + " initializer=mx.init.Xavier(rnd_type='gaussian', factor_type=\"in\", magnitude=2),\n", " eval_metric='acc')\n", " metric = mx.metric.Accuracy()\n", " return mod.score(val, metric)" diff --git a/python/how_to/predict.ipynb b/python/how_to/predict.ipynb index 9d0e01d9d..06de337ec 100644 --- a/python/how_to/predict.ipynb +++ b/python/how_to/predict.ipynb @@ -3425,7 +3425,7 @@ "source": [ "mod.bind(for_training = False,\n", " data_shapes=[('data', (1,3,224,224))])\n", - "mod.set_params(arg_params, aux_params)" + "mod.set_params(arg_params, aux_params, allow_missing=True)" ] }, { @@ -3611,7 +3611,7 @@ "batch_size = 32\n", "mod2 = mx.mod.Module(symbol=sym, context=mx.gpu())\n", "mod2.bind(for_training=False, data_shapes=[('data', (batch_size,3,224,224))])\n", - "mod2.set_params(arg_params, aux_params)" + "mod2.set_params(arg_params, aux_params, allow_missing=True)" ] }, { diff --git a/python/tutorials/char_lstm.ipynb b/python/tutorials/char_lstm.ipynb index 3f950403c..a891d68d9 100644 --- a/python/tutorials/char_lstm.ipynb +++ b/python/tutorials/char_lstm.ipynb @@ -245,16 +245,16 @@ " loss += -np.log(max(1e-10, pred[i][int(label[i])]))\n", " return np.exp(loss / label.size)\n", "\n", - "model = mx.model.FeedForward(\n", - " ctx=mx.gpu(0),\n", - " symbol=symbol,\n", - " num_epoch=num_epoch,\n", - " learning_rate=learning_rate,\n", - " momentum=0,\n", - " wd=0.0001,\n", - " initializer=mx.init.Xavier(factor_type=\"in\", magnitude=2.34))\n", + "model = mx.mod.Module(symbol=symbol,\n", + " data_names=[x[0] for x in data_train.provide_data],\n", + " label_names=[y[0] for y in data_train.provide_label],\n", + " context=[mx.gpu(0)])\n", "\n", - "model.fit(X=data_train,\n", + "model.fit(train_data=data_train,\n", + " num_epoch=num_epoch,\n", + " optimizer='sgd',\n", + " optimizer_params={'learning_rate':learning_rate, 'momentum':0, 'wd':0.0001},\n", + " initializer=mx.init.Xavier(factor_type=\"in\", magnitude=2.34),\n", " eval_metric=mx.metric.np(Perplexity),\n", " batch_end_callback=mx.callback.Speedometer(batch_size, 20),\n", " epoch_end_callback=mx.callback.do_checkpoint(\"obama\"))" diff --git a/python/tutorials/matrix_factorization.ipynb b/python/tutorials/matrix_factorization.ipynb index 7df6cee49..5b8fa2d87 100644 --- a/python/tutorials/matrix_factorization.ipynb +++ b/python/tutorials/matrix_factorization.ipynb @@ -228,23 +228,22 @@ "outputs": [], "source": [ "def train(network, batch_size, num_epoch, learning_rate):\n", - " model = mx.model.FeedForward(\n", - " ctx = mx.gpu(0), \n", - " symbol = network,\n", - " num_epoch = num_epoch,\n", - " learning_rate = learning_rate,\n", - " wd = 0.0001,\n", - " momentum = 0.9)\n", - "\n", - " batch_size = 64\n", + " batch_size = batch_size\n", " train, test = get_data(batch_size)\n", + " model = mx.mod.Module(symbol = network, \n", + " data_names=[x[0] for x in train.provide_data],\n", + " label_names=[y[0] for y in train.provide_label],\n", + " context=[mx.gpu(0)])\n", "\n", " import logging\n", " head = '%(asctime)-15s %(message)s'\n", " logging.basicConfig(level=logging.DEBUG)\n", "\n", - " model.fit(X = train, \n", + " model.fit(train_data = train, \n", " eval_data = test,\n", + " num_epoch=num_epoch,\n", + " optimizer='sgd',\n", + " optimizer_params={'learning_rate':learning_rate, 'momentum':0.9, 'wd':0.0001},\n", " eval_metric = RMSE,\n", " batch_end_callback=mx.callback.Speedometer(batch_size, 20000/batch_size),)" ] diff --git a/python/tutorials/predict_imagenet.ipynb b/python/tutorials/predict_imagenet.ipynb index 68baafe5d..61e6c31dc 100644 --- a/python/tutorials/predict_imagenet.ipynb +++ b/python/tutorials/predict_imagenet.ipynb @@ -52,10 +52,10 @@ }, "outputs": [], "source": [ - "mod = mx.mod.Module(symbol=sym, context=mx.gpu())\n", - "mod.bind(for_training=False, data_shapes=[('data', (1,3,224,224))])\n", - "mod.set_params(arg_params, aux_params)" - ] + "mod = mx.mod.Module(symbol=sym, label_names=None, context=mx.gpu())\n", + "mod.bind(for_training=False, data_shapes=[('data', (1,3,224,224))], label_shapes=mod._label_shapes)\n", + "mod.set_params(arg_params, aux_params, allow_missing=True)" + ] }, { "cell_type": "markdown", @@ -101,7 +101,7 @@ " img = np.swapaxes(img, 1, 2) \n", " img = img[np.newaxis, :] \n", " \n", - " mod.forward(Batch([mx.nd.array(img)]))\n", + " mod.forward(Batch(data=[mx.nd.array(img)]))\n", " prob = mod.get_outputs()[0].asnumpy()\n", " prob = np.squeeze(prob)\n", "\n", From ed8f4081c1b5f696b1cac05abac35236d8050092 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 4 May 2017 04:30:03 +0000 Subject: [PATCH 5/8] heavy revision of NDArrary tutorial --- python/basic/ndarray.ipynb | 358 +++++++++++++++++-------------------- 1 file changed, 161 insertions(+), 197 deletions(-) diff --git a/python/basic/ndarray.ipynb b/python/basic/ndarray.ipynb index 50cd76a81..fccd0f515 100644 --- a/python/basic/ndarray.ipynb +++ b/python/basic/ndarray.ipynb @@ -7,32 +7,55 @@ "# NDArray Tutorial\n", "\n", "\n", - "One of the main object in MXNet is the multidimensional array provided by the package `mxnet.ndarray`, or `mxnet.nd` for short. If you familiar with the scientific computing python package [NumPy](http://www.numpy.org/), `mxnet.ndarray` is similar to `numpy.ndarray` in many aspects. \n", + "In _MXNet_, `NDArray` is the core datastructure for all mathematical computations.\n", + "An `NDArray` represents a multidimensional, fixed-size homogenous array.\n", + "If you're familiar with the scientific computing python package [NumPy](http://www.numpy.org/),\n", + "you might notice that `mxnet.ndarray` is similar to `numpy.ndarray`. \n", + "Like the corresponding NumPy data sctructure, MXNet's `NDArray` enables imperative computation.\n", + "This means that we can instantly compute upon NDArrays, i.e., \n", + "we don't have to explicitly define a compute graph to execute code.\n", "\n", - "## The basic\n", + "So you might wonder, why not just use NumPy? \n", + "MXNet offers two compelling advantages. \n", + "First, MXNet's `NDArray` supports fast execution \n", + "on a wide range of hardware configurations, \n", + "including CPU, GPU, multi-GPU machines, \n", + "and distributed computation on the cloud. \n", + "Second, MXNet's NDArray executes code lazily, \n", + "allowing it to automatically parallelize multiple operations \n", + "across the available hardware.\n", "\n", - "A multidimensional array is a table of numbers with the same type. For example, the coordinates of a point in 3D space `[1, 2, 3]` is a 1-dimensional array with that dimension has a length of 3. The following picture shows a 2-dimensional array. The length of the first dimension is 2, and the second dimension has a length of 3\n", + "## The basics\n", + "\n", + "An `NDArray` is a multidimensional array of numbers with the same type. \n", + "We could represent the coordinates of a point in 3D space, \n", + "e.g. `[2, 1, 6]` as a 1D array with shape (3). \n", + "Similarly, we could represent a 2D array. \n", + "Below we present an array with length 2 along the first axis and length 3 along the second axis.\n", "```\n", "[[0, 1, 2]\n", " [3, 4, 5]]\n", "```\n", - "The array class is called `NDArray`. Some important attributes of a `NDArray` object are:\n", + "Note that here the use of \"dimension\" is overloaded. \n", + "When we say a 2D array, we mean an array with 2 axes, not an array with two components. \n", + "\n", + "EAch NDArray supports some important attributes that you'll often want to query:\n", "\n", - "- **ndarray.shape** the dimensions of the array. It is a tuple of integers indicating the length of the array in each dimension. For a matrix with `n` rows and `m` columns, the `shape` will be `(n, m)`. \n", - "- **ndarray.dtype** an `numpy` object describing the type of the elements.\n", - "- **ndarray.size** the total number of numbers in the array, which equals to the product of the elements of `shape`\n", - "- **ndarray.context** the device this array is stored. A device can be the CPU or the i-th GPU.\n", + "- **ndarray.shape**: The dimensions of the array. It is a tuple of integers indicating the length of the array along each axis. For a matrix with `n` rows and `m` columns, its `shape` will be `(n, m)`. \n", + "- **ndarray.dtype**: A `numpy` _type_ object describing the type of its elements.\n", + "- **ndarray.size**: the total number of components in the array - equal to the product of the components of its `shape`\n", + "- **ndarray.context**: The device on which this array is stored, e.g. `cpu()` or `gpu(1)`.\n", "\n", "### Array Creation \n", - "An array can be created in multiple ways. For example, we can create an array from a regular Python list or tuple by using the `array` function" + "There are a few different ways to create an `NDArray`. \n", + "\n", + "* We can create an NDArray from a regular Python list or tuple by using the `array` function" ] }, { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -58,15 +81,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "or from an `numpy.ndarray` object" + "* We can also create an MXNet NDArray from an `numpy.ndarray` object" ] }, { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -92,15 +113,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can specify the element type with the option `dtype`, which accepts a numpy type. In default, `float32` is used. " + "We can specify the element type with the option `dtype`, which accepts a numpy type. By default, `float32` is used. " ] }, { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -127,14 +146,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If we only know the size but not the element values, there are several functions to create arrays with initial placeholder content. " + "If we know the size of the desired NDArray, but not the element values, \n", + "MXNet offers several functions to create arrays with placeholder content:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { - "collapsed": false + "collapsed": true }, "outputs": [], "source": [ @@ -154,33 +174,40 @@ "metadata": {}, "source": [ "### Printing Arrays\n", - "We often first convert `NDArray` to `numpy.ndarray` by the function `asnumpy` for printing. Numpy uses the following layout:\n", - "- the last axis is printed from left to right,\n", - "- the second-to-last is printed from top to bottom,\n", - "- the rest are also printed from top to bottom, with each slice separated from the next by an empty line." + "\n", + "When inspecting the contents of an `NDArray`, it's often convenient \n", + "to first extract its contents as a `numpy.ndarray` using the `asnumpy` function. \n", + "Numpy uses the following layout:\n", + "- The last axis is printed from left to right,\n", + "- The second-to-last is printed from top to bottom,\n", + "- The rest are also printed from top to bottom, with each slice separated from the next by an empty line." ] }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": false - }, + "execution_count": 39, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[ 1., 1., 1.],\n", - " [ 1., 1., 1.]], dtype=float32)" + "array([[[ 0., 1., 2.],\n", + " [ 3., 4., 5.]],\n", + "\n", + " [[ 6., 7., 8.],\n", + " [ 9., 10., 11.]],\n", + "\n", + " [[ 12., 13., 14.],\n", + " [ 15., 16., 17.]]], dtype=float32)" ] }, - "execution_count": 5, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "b = mx.nd.ones((2,3))\n", + "b = mx.nd.arange(18).reshape((3,2,3))\n", "b.asnumpy()" ] }, @@ -189,15 +216,13 @@ "metadata": {}, "source": [ "### Basic Operations\n", - "Arithmetic operators on arrays apply *elementwise*. A new array is created and filled with the result." + "When applied to NDArrays, the standard arithmetic operators apply *elementwise* calculations. The returned value is a new array whose content contains the result." ] }, { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -227,53 +252,45 @@ }, { "cell_type": "markdown", - "metadata": { - "collapsed": false - }, + "metadata": {}, "source": [ - "Simiar to `NumPy`, `*` is used for elementwise multiply, while matrix-matrix multiplication is left for `dot`" + "As in `NumPy`, `*` represents element-wise multiplication. For matrix-matrix multiplication, use `dot`." ] }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": false - }, + "execution_count": 45, + "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "{'b': array([[ 1., 1.],\n", - " [ 1., 1.]], dtype=float32), 'c': array([[ 2., 2.],\n", - " [ 2., 2.]], dtype=float32)}" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "b: [[ 0. 1.]\n", + " [ 4. 9.]], \n", + " c: [[ 2. 3.]\n", + " [ 6. 11.]]\n" + ] } ], "source": [ - "a = mx.nd.ones((2,2))\n", + "a = mx.nd.arange(4).reshape((2,2))\n", "b = a * a\n", "c = mx.nd.dot(a,a)\n", - "{'b':b.asnumpy(), 'c':c.asnumpy()}" + "print(\"b: %s, \\n c: %s\" % (b.asnumpy(), c.asnumpy()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The assignment operators such as `+=` and `*=` act in place to modify an existing array rather than create a new one." + "The assignment operators such as `+=` and `*=` modify arrays in place, and thus don't allocate new memory to create a new array." ] }, { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -305,9 +322,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -338,9 +353,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -365,15 +378,13 @@ "metadata": {}, "source": [ "### Shape Manipulation \n", - "The shape of the array can be changed as long as the size remaining the same " + "Using `reshape`, we can manipulate any arrays shape as long as the size remains unchanged." ] }, { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -402,15 +413,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Method `concatenate` stacks multiple arrays along the first dimension. (Their shapes must be the same)." + "The `concatenate` method stacks multiple arrays along the first axis. (Their shapes must be the same along the other axes)." ] }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, + "execution_count": 47, + "metadata": {}, "outputs": [ { "data": { @@ -421,7 +430,7 @@ " [ 2., 2., 2.]], dtype=float32)" ] }, - "execution_count": 12, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -439,15 +448,13 @@ "source": [ "### Reduce\n", "\n", - "We can reduce the array to a scalar" + "Some functions, like `sum` and `mean` reduce arrays to scalars." ] }, { "cell_type": "code", "execution_count": 13, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -470,15 +477,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "or along a particular axis" + "We can also reduce an array along a particular axis:" ] }, { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -501,35 +506,34 @@ "metadata": {}, "source": [ "### Broadcast\n", - "We can also broadcast an array by duplicating. The following codes broadcast along axis 1" + "\n", + "We can also broadcast an array. Broadcasting operations, duplicate an array's value along an axis with length 1. The following code broadcasts along axis 1:" ] }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": false - }, + "execution_count": 48, + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[ 0., 0.],\n", - " [ 1., 1.],\n", - " [ 2., 2.],\n", - " [ 3., 3.],\n", - " [ 4., 4.],\n", - " [ 5., 5.]], dtype=float32)" + "array([[ 0., 0., 0., 0.],\n", + " [ 1., 1., 1., 1.],\n", + " [ 2., 2., 2., 2.],\n", + " [ 3., 3., 3., 3.],\n", + " [ 4., 4., 4., 4.],\n", + " [ 5., 5., 5., 5.]], dtype=float32)" ] }, - "execution_count": 15, + "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "a = mx.nd.array(np.arange(6).reshape(6,1))\n", - "b = a.broadcast_to((6,2)) # \n", + "b = a.broadcast_to((6,4)) # \n", "b.asnumpy()" ] }, @@ -537,15 +541,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "or broadcast along axes 1 and 2" + "It's possible to simultaneously broadcast along multiple axes. In the following example, we broadcast along axes 1 and 2:" ] }, { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -579,15 +581,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Broadcast can be applied to operations such as `*` and `+`. " + "Broadcasting can be applied automatically when executing some operations, e.g. `*` and `+` on arrays of different shapes." ] }, { "cell_type": "code", "execution_count": 17, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -614,15 +614,14 @@ "metadata": {}, "source": [ "### Copies\n", - "Data is *NOT* copied in normal assignment. " + "\n", + "When assigning an NDArray to another Python variable, we copy a reference to the *same* NDArray. However, we often need to maek a copy of the data, so that we can manipulate the new array without overwriting the original values. " ] }, { "cell_type": "code", "execution_count": 18, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -645,46 +644,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "similar for function arguments passing." - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def f(x): \n", - " return x\n", - "a is f(a)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The `copy` method makes a deep copy of the array and its data" + "The `copy` method makes a deep copy of the array and its data:" ] }, { "cell_type": "code", "execution_count": 20, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -706,15 +672,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The above code allocate a new NDArray and then assign to *b*. We can use the `copyto` method or the slice operator `[]` to avoid additional memory allocation" + "The above code allocates a new NDArray and then assigns to *b*. When we do not want to allocate additional memory, we can use the `copyto` method or the slice operator `[]` instead." ] }, { "cell_type": "code", "execution_count": 21, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -740,20 +704,18 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## The Advanced \n", - "There are some advanced features in `mxnet.ndarray` which make mxnet different from other libraries. \n", + "## Advanced Topics\n", + "MXNet's NDArray offers some advanced features that differentiate it from the offerings you'll find in most other libraries. \n", "\n", "### GPU Support\n", "\n", - "In default operators are executed on CPU. It is easy to switch to another computation resource, such as GPU, if available. The device information is stored in `ndarray.context`. When MXNet is compiled with flag `USE_CUDA=1` and there is at least one Nvidia GPU card, we can make all computations run on GPU 0 by using context `mx.gpu(0)`, or simply `mx.gpu()`. If there are more than two GPUs, the 2nd GPU is represented by `mx.gpu(1)`." + "By default, NDArray operators are executed on CPU. But with MXNet, it's easy to switch to another computation resource, such as GPU, when available. Each NDArray's device information is stored in `ndarray.context`. When MXNet is compiled with flag `USE_CUDA=1` and the machine has at least one NVIDIA GPU, we can cause all computations to run on GPU 0 by using context `mx.gpu(0)`, or simply `mx.gpu()`. When we have access to two or more GPUs, the 2nd GPU is represented by `mx.gpu(1)`, etc." ] }, { "cell_type": "code", "execution_count": 22, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -781,15 +743,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can also explicitly specify the context when creating an array" + "We can also explicitly specify the context when creating an array:" ] }, { "cell_type": "code", "execution_count": 23, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -811,15 +771,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Currently MXNet requires two arrays to sit on the same device for computation. There are several methods for copying data between devices." + "Currently, MXNet requires two arrays to sit on the same device for computation. There are several methods for copying data between devices." ] }, { "cell_type": "code", "execution_count": 24, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -846,16 +804,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Serialize From/To (Distributed) Filesystems \n", - "There are two ways to save data to (load from) disks easily. The first way uses `pickle`. `NDArray` is pickle compatible." + "### Serialize From/To (Distributed) Filesystems\n", + "\n", + "MXNet offers two simple ways to save (load) data to (from) disk. The first way is to use `pickle`, as you might with any other Python objects. `NDArray` is pickle-compatible." ] }, { "cell_type": "code", "execution_count": 25, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -885,15 +842,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The second way is to directly dump into disk in binary format by method `save` and `load`. Besides single NDArray, we can load/save a list" + "The second way is to directly dump to disk in binary format by using the `save` and `load` methods. We can save/load a single NDArray, or a list of NDArrays:" ] }, { "cell_type": "code", "execution_count": 26, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -918,15 +873,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "or a dict" + "It's also possible to save or load a dict of NDArrays in this fashion:" ] }, { "cell_type": "code", "execution_count": 27, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -950,13 +903,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The load/save is better than pickle in two aspects\n", - "1. The data saved with the Python interface can be used by another lanuage binding. For example, if we save the data in python:\n", + "The `load` and `save` methods are preferable to pickle in two respects\n", + "1. When using these methods, you can save data from within the Python interface and then use it later from another lanuage's binding. For example, if we save the data in Python:\n", "```python\n", "a = mx.nd.ones((2, 3))\n", "mx.save(\"temp.ndarray\", [a,])\n", "```\n", - "then we can load it into R:\n", + "we can later load it from R:\n", "```R\n", "a <- mx.nd.load(\"temp.ndarray\")\n", "as.array(a[[1]])\n", @@ -964,7 +917,7 @@ "## [1,] 1 1 1\n", "## [2,] 1 1 1\n", "```\n", - "2. If a distributed filesystem such as Amazon S3 or Hadoop HDFS is set up, we can directly save to and load from it. \n", + "2. When a distributed filesystem such as Amazon S3 or Hadoop HDFS is set up, we can directly save to and load from it. \n", "```python\n", "mx.nd.save('s3://mybucket/mydata.ndarray', [a,]) # if compiled with USE_S3=1\n", "mx.nd.save('hdfs///users/myname/mydata.bin', [a,]) # if compiled with USE_HDFS=1\n", @@ -975,20 +928,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Lazy Evaluation and Auto Parallelization *\n", + "### Lazy Evaluation and Automatic Parallelization *\n", "\n", - "MXNet uses lazy evaluation for better performance. When we run `a=b+1` in python, the python thread just pushs the operation into the backend engine and then returns. There are two benefits for such optimization:\n", - "1. The main python thread can continue to execute other computations once the previous one is pushed. It is useful for frontend languages with heavy overheads. \n", - "2. It is easier for the backend engine to explore further optimization, such as auto parallelization that will be discussed shortly. \n", + "MXNet uses lazy evaluation to achieve superior performance. \n", + "When we run `a=b+1` in Python, the Python thread \n", + "just pushes this operation into the backend engine and then returns. \n", + "There are two benefits for to this approach:\n", + "1. The main Python thread can continue to execute other computations once the previous one is pushed. It is useful for frontend languages with heavy overheads. \n", + "2. It is easier for the backend engine to explore further optimization, such as auto parallelization. \n", "\n", - "The backend engine is able to resolve the data dependencies and schedule the computations correctly. It is transparent to frontend users. We can explicitly call the method `wait_to_read` on the result array to wait the computation finished. Operations that copy data from an array to other packages, such as `asnumpy`, will implicitly call `wait_to_read`. \n" + "The backend engine can resolve data dependencies and schedule the computations correctly. It is transparent to frontend users. We can explicitly call the method `wait_to_read` on the result array to wait until the computation finishes. Operations that copy data from an array to other packages, such as `asnumpy`, will implicitly call `wait_to_read`. \n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -1027,21 +982,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Besides analyzing data read and write dependencies, the backend engine is able to schedule computations with no dependency in parallel. For example, in the following codes\n", + "Besides analyzing data read and write dependencies, the backend engine is able to schedule computations with no dependency in parallel. For example, in the following code:\n", "```python\n", "a = mx.nd.ones((2,3))\n", "b = a + 1\n", "c = a + 2\n", "d = b * c\n", "```\n", - "the second and third sentences can be executed in parallel. The following example first run on CPU and then on GPU." + "the second and third lines can be executed in parallel. The following example first runs on CPU and then on GPU:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { - "collapsed": false, "scrolled": true }, "outputs": [ @@ -1078,9 +1032,7 @@ { "cell_type": "code", "execution_count": 30, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -1106,18 +1058,30 @@ "source": [ "## Current Status\n", "\n", - "We try our best to keep the NDArray API as the same numpy's. But it is not fully numpy compatible yet. Here we summary some major difference, which we hope to be fixed in a short time. We are also welcome to any contribution.\n", + "Whenever possible, we try to keep the NDArray API as similar as possible to the NumPy API. \n", + "But you should note that NDArray is not fully yet fully NumPy-compatible. \n", + "Here we summary the major differences, which we hope to be resolve quickly. \n", + "(If you'd like to contribute, [fork us on Github](https://github.com/dmlc/mxnet))\n", "\n", "- Slice and Index. \n", - " - NDArray can only slice one dimension at each time, namely we cannot use `x[:, 1]` to slice both dimensions.\n", - " - Only continues indexes are supported, we cannot do `x[1:2:3]`\n", - " - boolean indices are not supported, such as `x[y==1]`.\n", + " - NDArray can only slice along one dimension at a time. Namely, we cannot use `x[:, 1]` to slice both dimensions.\n", + " - Only continuous indices are supported, we cannot do `x[1:2:3]`\n", + " - Boolean indices are not supported, e.g. `x[y==1]`.\n", "- Lack of reduce functions such as `max`, `min`...\n", "\n", "## Futher Readings\n", "- [NDArray API](http://mxnet.dmlc.ml/en/latest/packages/python/ndarray.html) Documents for all NDArray methods.\n", "- [MinPy](https://github.com/dmlc/minpy) on-going project, fully numpy compatible with GPU and auto differentiation supports " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { From 18344e30a0c3f1e3f70ab760db56d0f0ed644bf7 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 4 May 2017 04:40:42 +0000 Subject: [PATCH 6/8] fixing typos --- python/basic/ndarray.ipynb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python/basic/ndarray.ipynb b/python/basic/ndarray.ipynb index fccd0f515..e6679e8f5 100644 --- a/python/basic/ndarray.ipynb +++ b/python/basic/ndarray.ipynb @@ -11,16 +11,14 @@ "An `NDArray` represents a multidimensional, fixed-size homogenous array.\n", "If you're familiar with the scientific computing python package [NumPy](http://www.numpy.org/),\n", "you might notice that `mxnet.ndarray` is similar to `numpy.ndarray`. \n", - "Like the corresponding NumPy data sctructure, MXNet's `NDArray` enables imperative computation.\n", - "This means that we can instantly compute upon NDArrays, i.e., \n", - "we don't have to explicitly define a compute graph to execute code.\n", + "Like the corresponding NumPy data structure, MXNet's `NDArray` enables imperative computation.\n", "\n", "So you might wonder, why not just use NumPy? \n", "MXNet offers two compelling advantages. \n", "First, MXNet's `NDArray` supports fast execution \n", "on a wide range of hardware configurations, \n", - "including CPU, GPU, multi-GPU machines, \n", - "and distributed computation on the cloud. \n", + "including CPU, GPU, and multi-GPU machines.\n", + "_MXNet_ also scales to distribute systems in the cloud. \n", "Second, MXNet's NDArray executes code lazily, \n", "allowing it to automatically parallelize multiple operations \n", "across the available hardware.\n", @@ -31,7 +29,7 @@ "We could represent the coordinates of a point in 3D space, \n", "e.g. `[2, 1, 6]` as a 1D array with shape (3). \n", "Similarly, we could represent a 2D array. \n", - "Below we present an array with length 2 along the first axis and length 3 along the second axis.\n", + "Below, we present an array with length 2 along the first axis and length 3 along the second axis.\n", "```\n", "[[0, 1, 2]\n", " [3, 4, 5]]\n", @@ -39,7 +37,7 @@ "Note that here the use of \"dimension\" is overloaded. \n", "When we say a 2D array, we mean an array with 2 axes, not an array with two components. \n", "\n", - "EAch NDArray supports some important attributes that you'll often want to query:\n", + "Each NDArray supports some important attributes that you'll often want to query:\n", "\n", "- **ndarray.shape**: The dimensions of the array. It is a tuple of integers indicating the length of the array along each axis. For a matrix with `n` rows and `m` columns, its `shape` will be `(n, m)`. \n", "- **ndarray.dtype**: A `numpy` _type_ object describing the type of its elements.\n", @@ -54,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -63,7 +61,7 @@ "{'a.shape': (3L,), 'b.shape': (2L, 3L)}" ] }, - "execution_count": 1, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } From 1ea548e2a992e5abc44babe452ab09e53b02542b Mon Sep 17 00:00:00 2001 From: Zachary Lipton Date: Thu, 4 May 2017 04:45:42 +0000 Subject: [PATCH 7/8] fixing typos --- python/basic/ndarray.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/basic/ndarray.ipynb b/python/basic/ndarray.ipynb index e6679e8f5..048345549 100644 --- a/python/basic/ndarray.ipynb +++ b/python/basic/ndarray.ipynb @@ -47,7 +47,7 @@ "### Array Creation \n", "There are a few different ways to create an `NDArray`. \n", "\n", - "* We can create an NDArray from a regular Python list or tuple by using the `array` function" + "* We can create an NDArray from a regular Python list or tuple by using the `array` function:" ] }, { @@ -79,7 +79,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "* We can also create an MXNet NDArray from an `numpy.ndarray` object" + "* We can also create an MXNet NDArray from an `numpy.ndarray` object:" ] }, { @@ -111,7 +111,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can specify the element type with the option `dtype`, which accepts a numpy type. By default, `float32` is used. " + "We can specify the element type with the option `dtype`, which accepts a numpy type. By default, `float32` is used: " ] }, { From 3b785541de910b8951cee46e3e404cafa8d3af4e Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 4 May 2017 18:21:51 +0000 Subject: [PATCH 8/8] More fix --- python/how_to/predict.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/how_to/predict.ipynb b/python/how_to/predict.ipynb index 06de337ec..5c30e8ec4 100644 --- a/python/how_to/predict.ipynb +++ b/python/how_to/predict.ipynb @@ -3405,7 +3405,7 @@ }, "outputs": [], "source": [ - "mod = mx.mod.Module(symbol=sym, context=mx.gpu())" + "mod = mx.mod.Module(symbol=sym, label_names=None, context=mx.gpu())" ] }, { @@ -3609,7 +3609,7 @@ "outputs": [], "source": [ "batch_size = 32\n", - "mod2 = mx.mod.Module(symbol=sym, context=mx.gpu())\n", + "mod2 = mx.mod.Module(symbol=sym, label_names=None, context=mx.gpu())\n", "mod2.bind(for_training=False, data_shapes=[('data', (batch_size,3,224,224))])\n", "mod2.set_params(arg_params, aux_params, allow_missing=True)" ] @@ -3725,7 +3725,7 @@ "source": [ "all_layers = sym.get_internals()\n", "sym3 = all_layers['flatten0_output']\n", - "mod3 = mx.mod.Module(symbol=sym3, context=mx.gpu())\n", + "mod3 = mx.mod.Module(symbol=sym3, label_names=None, context=mx.gpu())\n", "mod3.bind(for_training=False, data_shapes=[('data', (1,3,224,224))])\n", "mod3.set_params(arg_params, aux_params)\n" ]