singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang...@apache.org
Subject [07/15] incubator-singa git commit: SINGA-290 Upgrade to Python 3
Date Fri, 04 Aug 2017 08:32:51 GMT
http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/bfeb6127/doc/en/docs/notebook/model.ipynb
----------------------------------------------------------------------
diff --git a/doc/en/docs/notebook/model.ipynb b/doc/en/docs/notebook/model.ipynb
index 23a5553..6888435 100644
--- a/doc/en/docs/notebook/model.ipynb
+++ b/doc/en/docs/notebook/model.ipynb
@@ -29,7 +29,7 @@
    "cell_type": "code",
    "execution_count": 1,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -50,7 +50,7 @@
    "cell_type": "code",
    "execution_count": 2,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -67,9 +67,7 @@
   {
    "cell_type": "code",
    "execution_count": 3,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -83,14 +81,14 @@
     "dense = Dense('dense', 3, input_sample_shape=(2,))\n",
     "#dense.param_names()\n",
     "w, b = dense.param_values()\n",
-    "print w.shape, b.shape"
+    "print(w.shape, b.shape)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 4,
    "metadata": {
-    "collapsed": false
+    "collapsed": true
    },
    "outputs": [],
    "source": [
@@ -101,15 +99,13 @@
   {
    "cell_type": "code",
    "execution_count": 5,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
        "array([[ 0.02440065, -0.03396009,  0.01396658],\n",
-       "       [ 0.00771775,  0.07841966, -0.05931653]], dtype=float32)"
+       "       [ 0.00771775,  0.07841966, -0.05931654]], dtype=float32)"
       ]
      },
      "execution_count": 5,
@@ -127,9 +123,7 @@
   {
    "cell_type": "code",
    "execution_count": 6,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -141,7 +135,7 @@
    ],
    "source": [
     "gx, [gw, gb] = dense.backward(True, y)\n",
-    "print gx.shape, gw.shape, gb.shape"
+    "print(gx.shape, gw.shape, gb.shape)"
    ]
   },
   {
@@ -154,9 +148,7 @@
   {
    "cell_type": "code",
    "execution_count": 7,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -168,7 +160,7 @@
    ],
    "source": [
     "conv = Conv2D('conv', 4, 3, 1, input_sample_shape=(3, 6, 6))\n",
-    "print conv.get_output_sample_shape()"
+    "print(conv.get_output_sample_shape())"
    ]
   },
   {
@@ -181,9 +173,7 @@
   {
    "cell_type": "code",
    "execution_count": 8,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -195,7 +185,7 @@
    ],
    "source": [
     "pool = MaxPooling2D('pool', 3, 2, input_sample_shape=(4, 6, 6))\n",
-    "print pool.get_output_sample_shape()"
+    "print(pool.get_output_sample_shape())"
    ]
   },
   {
@@ -219,9 +209,7 @@
   {
    "cell_type": "code",
    "execution_count": 10,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -233,15 +221,13 @@
    ],
    "source": [
     "split = Split('split', 2, input_sample_shape=(4, 6, 6))\n",
-    "print split.get_output_sample_shape()"
+    "print(split.get_output_sample_shape())"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 11,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -253,15 +239,13 @@
    ],
    "source": [
     "merge = Merge('merge', input_sample_shape=(4, 6, 6))\n",
-    "print merge.get_output_sample_shape()"
+    "print(merge.get_output_sample_shape())"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 12,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -273,15 +257,13 @@
    ],
    "source": [
     "sli = Slice('slice', 1, [2], input_sample_shape=(4, 6, 6))\n",
-    "print sli.get_output_sample_shape()"
+    "print(sli.get_output_sample_shape())"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 13,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -293,7 +275,7 @@
    ],
    "source": [
     "concat = Concat('concat', 1, input_sample_shapes=[(3, 6, 6), (1, 6, 6)])\n",
-    "print concat.get_output_sample_shape()"
+    "print(concat.get_output_sample_shape())"
    ]
   },
   {
@@ -306,9 +288,7 @@
   {
    "cell_type": "code",
    "execution_count": 14,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
@@ -328,26 +308,24 @@
     "x = tensor.Tensor((3, 5))\n",
     "x.uniform(0, 1)  # randomly genearte the prediction activation\n",
     "x = tensor.softmax(x)  # normalize the prediction into probabilities\n",
-    "print tensor.to_numpy(x)\n",
+    "print(tensor.to_numpy(x))\n",
     "y = tensor.from_numpy(np.array([0, 1, 3], dtype=np.int))  # set the truth\n",
     "\n",
     "f = metric.Accuracy()\n",
     "acc = f.evaluate(x, y)  # averaged accuracy over all 3 samples in x\n",
-    "print acc"
+    "print(acc)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 15,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "1.80309379101\n",
+      "1.8030937910079956\n",
       "[[-0.78104687  0.18748793  0.16346708  0.24803984  0.18205206]\n",
       " [ 0.21501946 -0.83683592  0.19003348  0.20714596  0.22463693]\n",
       " [ 0.20000091  0.23285127  0.26842937 -0.87474263  0.17346108]]\n"
@@ -364,8 +342,8 @@
     "f = loss.SoftmaxCrossEntropy()\n",
     "l = f.forward(True, x, y)  # l is tensor with 3 loss values\n",
     "g = f.backward()  # g is a tensor containing all gradients of x w.r.t l\n",
-    "print l.l1()\n",
-    "print tensor.to_numpy(g)"
+    "print(l.l1())\n",
+    "print(tensor.to_numpy(g))"
    ]
   },
   {
@@ -378,14 +356,12 @@
   {
    "cell_type": "code",
    "execution_count": 16,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "<singa.tensor.Tensor at 0x7f6a0c7cfe90>"
+       "<singa.tensor.Tensor at 0x7f539260f710>"
       ]
      },
      "execution_count": 16,
@@ -416,20 +392,18 @@
   {
    "cell_type": "code",
    "execution_count": 17,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "conv1 (32, 32, 32)\n",
-      "relu1 (32, 32, 32)\n",
-      "pool1 (32, 16, 16)\n",
-      "flat (8192,)\n",
-      "dense (10,)\n",
-      "[u'conv1_weight', u'conv1_bias', u'dense_weight', u'dense_bias']\n"
+      "('conv1', (32, 32, 32))\n",
+      "('relu1', (32, 32, 32))\n",
+      "('pool1', (32, 16, 16))\n",
+      "('flat', (8192,))\n",
+      "('dense', (10,))\n",
+      "['conv1/weight', 'conv1/bias', 'dense/weight', 'dense/bias']\n"
      ]
     }
    ],
@@ -449,25 +423,23 @@
     "        p.set_value(0)\n",
     "    else:\n",
     "        p.gaussian(0, 0.01)\n",
-    "print net.param_names()"
+    "print(net.param_names())"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": 18,
-   "metadata": {
-    "collapsed": false
-   },
+   "metadata": {},
    "outputs": [
     {
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "conv1 (32, 32, 32)\n",
-      "relu1 (32, 32, 32)\n",
-      "pool1 (32, 16, 16)\n",
-      "flat (8192,)\n",
-      "dense (10,)\n"
+      "('conv1', (32, 32, 32))\n",
+      "('relu1', (32, 32, 32))\n",
+      "('pool1', (32, 16, 16))\n",
+      "('flat', (8192,))\n",
+      "('dense', (10,))\n"
      ]
     }
    ],
@@ -514,21 +486,21 @@
  "metadata": {
   "anaconda-cloud": {},
   "kernelspec": {
-   "display_name": "Python [conda env:conda]",
+   "display_name": "py3",
    "language": "python",
-   "name": "conda-env-conda-py"
+   "name": "py3"
   },
   "language_info": {
    "codemirror_mode": {
     "name": "ipython",
-    "version": 2
+    "version": 3
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
-   "pygments_lexer": "ipython2",
-   "version": "2.7.13"
+   "pygments_lexer": "ipython3",
+   "version": "3.5.3"
   }
  },
  "nbformat": 4,


Mime
View raw message