blob: 5208ce3d615c047a3682aa36ef222f7c3ae2ebe1 [file] [log] [blame]
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import mxnet as mx\n",
"a = mx.sym.Variable('a')\n",
"b = mx.sym.Variable('b')\n",
"c = a + b\n",
"(a, b, c)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# elemental wise times\n",
"d = a * b \n",
"# matrix multiplication\n",
"e = mx.sym.dot(a, b) \n",
"# reshape\n",
"f = mx.sym.Reshape(d+e, shape=(1,4)) \n",
"# broadcast\n",
"g = mx.sym.broadcast_to(f, shape=(2,4)) \n",
"mx.viz.plot_network(symbol=g)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from __future__ import print_function\n",
"import os\n",
"import time\n",
"# set the number of threads you want to use before importing mxnet\n",
"os.environ['MXNET_CPU_WORKER_NTHREADS'] = '4'\n",
"import mxnet as mx\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# download example images\n",
"proxy = os.popen('cat /etc/profile | grep https_proxy | cut -f2 -d\"=\"').read()[:-1]\n",
"os.popen('wget -e use_proxy=yes -e http_proxy={} http://data.mxnet.io/data/test_images.tar.gz'.format(proxy)).read()\n",
"os.popen('tar -xf test_images.tar.gz').read()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# opencv\n",
"import cv2\n",
"N = 1000\n",
"tic = time.time()\n",
"for i in range(N):\n",
" img = cv2.imread('test_images/ILSVRC2012_val_00000001.JPEG', flags=1)\n",
" img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
"print(N/(time.time()-tic), 'images decoded per second with opencv')\n",
"plt.imshow(img); plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "KERNEL_NAME"
},
"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.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}