Validate Your MXNet Installation

Python

Start the python terminal.

$ python

Run a short MXNet python program to create a 2X3 matrix of ones, multiply each element in the matrix by 2 followed by adding 1. We expect the output to be a 2X3 matrix with all elements being 3.

>>> import mxnet as mx
>>> a = mx.nd.ones((2, 3))
>>> b = a * 2 + 1
>>> b.asnumpy()
array([[ 3.,  3.,  3.],
       [ 3.,  3.,  3.]], dtype=float32)

Python with GPU

This is similar to the previous example, but this time we use mx.gpu(), to set MXNet context to be GPUs.

>>> import mxnet as mx
>>> a = mx.nd.ones((2, 3), mx.gpu())
>>> b = a * 2 + 1
>>> b.asnumpy()
array([[ 3.,  3.,  3.],
       [ 3.,  3.,  3.]], dtype=float32)

Verify GPU Training

From the MXNet root directory run: python example/image-classification/train_mnist.py --network lenet --gpus 0 to test GPU training.

Virtualenv

Activate the virtualenv environment created for MXNet.

$ source ~/mxnet/bin/activate

After activating the environment, you should see the prompt as below.

(mxnet)$

Start the python terminal.

$ python

Run the previous Python example.

Docker with CPU

Launch a Docker container with mxnet/python image and run example MXNet python program on the terminal.

$ docker run -it mxnet/python bash # Use sudo if you skip Step 2 in the installation instruction

# Start a python terminal
root@4919c4f58cac:/# python

Run the previous Python example.

Docker with GPU

Launch a NVIDIA Docker container with mxnet/python:gpu image and run example MXNet python program on the terminal.

$ nvidia-docker run -it mxnet/python:gpu bash # Use sudo if you skip Step 2 in the installation instruction

# Start a python terminal
root@4919c4f58cac:/# python

Run the previous Python example and run the previous GPU examples.

Cloud

Login to the cloud instance you launched, with pre-installed MXNet, following the guide by corresponding cloud provider.

Start the python terminal.

$ python

Run the previous Python example, and for GPU instances run the previous GPU example.

Alternative Language Bindings

C++

Please contribute an example!

Clojure

Please contribute an example!

Julia

Please contribute an example!

Perl

Please contribute an example!

R

Run a short MXNet R program to create a 2X3 matrix of ones, multiply each element in the matrix by 2 followed by adding 1. We expect the output to be a 2X3 matrix with all elements being 3.

library(mxnet)
a <- mx.nd.ones(c(2,3), ctx = mx.cpu())
b <- a * 2 + 1
b

You should see the following output:

[,1] [,2] [,3]
[1,]    3    3    3
[2,]    3    3    3

R with GPU

This is similar to the previous example, but this time we use mx.gpu(), to set MXNet context to be GPUs.

library(mxnet)
a <- mx.nd.ones(c(2,3), ctx = mx.gpu())
b <- a * 2 + 1
b

You should see the following output:

[,1] [,2] [,3]
[1,]    3    3    3
[2,]    3    3    3

Scala

Run the MXNet-Scala demo project to validate your Maven package installation.