You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by du...@apache.org on 2017/04/26 22:34:25 UTC

incubator-systemml git commit: [MINOR] Naming updates in the MNIST LeNet & softmax examples, and README fix.

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 43c321d18 -> 2a4e4f8b3


[MINOR] Naming updates in the MNIST LeNet & softmax examples, and README fix.


Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/2a4e4f8b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/2a4e4f8b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/2a4e4f8b

Branch: refs/heads/master
Commit: 2a4e4f8b30fce0ea8a4a6cfec9c0cced377534ad
Parents: 43c321d
Author: Mike Dusenberry <mw...@us.ibm.com>
Authored: Wed Apr 26 15:32:25 2017 -0700
Committer: Mike Dusenberry <mw...@us.ibm.com>
Committed: Wed Apr 26 15:32:25 2017 -0700

----------------------------------------------------------------------
 scripts/nn/README.md                        |  2 +-
 scripts/nn/examples/mnist_lenet-train.dml   | 12 ++++-----
 scripts/nn/examples/mnist_lenet.dml         | 34 ++++++++++++------------
 scripts/nn/examples/mnist_softmax-train.dml | 12 ++++-----
 scripts/nn/examples/mnist_softmax.dml       | 34 ++++++++++++------------
 5 files changed, 47 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/2a4e4f8b/scripts/nn/README.md
----------------------------------------------------------------------
diff --git a/scripts/nn/README.md b/scripts/nn/README.md
index b80f2c6..3943765 100644
--- a/scripts/nn/README.md
+++ b/scripts/nn/README.md
@@ -22,7 +22,7 @@ limitations under the License.
 ### A deep learning library for [Apache SystemML](https://github.com/apache/incubator-systemml).
 
 ## Examples:
-#### Please see the [`examples`](nn/examples) folder for more detailed examples, or view the following two quick examples.
+#### Please see the [`examples`](examples) folder for more detailed examples, or view the following two quick examples.
 ### Neural net for regression with vanilla SGD:
 ```python
 # Imports

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/2a4e4f8b/scripts/nn/examples/mnist_lenet-train.dml
----------------------------------------------------------------------
diff --git a/scripts/nn/examples/mnist_lenet-train.dml b/scripts/nn/examples/mnist_lenet-train.dml
index 0fc733e..5064eab 100644
--- a/scripts/nn/examples/mnist_lenet-train.dml
+++ b/scripts/nn/examples/mnist_lenet-train.dml
@@ -81,7 +81,7 @@ out_dir = ifdef($out_dir, ".")
 images = train[,2:ncol(train)]
 labels = train[,1]
 X_test = test[,2:ncol(test)]
-y_test = test[,1]
+Y_test = test[,1]
 
 # Scale images to [-1,1], and one-hot encode the labels
 n = nrow(train)
@@ -89,16 +89,16 @@ n_test = nrow(test)
 images = (images / 255.0) * 2 - 1
 labels = table(seq(1, n), labels+1, n, 10)
 X_test = (X_test / 255.0) * 2 - 1
-y_test = table(seq(1, n_test), y_test+1, n_test, 10)
+Y_test = table(seq(1, n_test), Y_test+1, n_test, 10)
 
 # Split into training (55,000 examples) and validation (5,000 examples)
 X = images[5001:nrow(images),]
 X_val = images[1:5000,]
-y = labels[5001:nrow(images),]
-y_val = labels[1:5000,]
+Y = labels[5001:nrow(images),]
+Y_val = labels[1:5000,]
 
 # Train
-[W1, b1, W2, b2, W3, b3, W4, b4] = mnist_lenet::train(X, y, X_val, y_val, C, Hin, Win, epochs)
+[W1, b1, W2, b2, W3, b3, W4, b4] = mnist_lenet::train(X, Y, X_val, Y_val, C, Hin, Win, epochs)
 
 # Write model out
 write(W1, out_dir+"/W1")
@@ -112,7 +112,7 @@ write(b4, out_dir+"/b4")
 
 # Eval on test set
 probs = mnist_lenet::predict(X_test, C, Hin, Win, W1, b1, W2, b2, W3, b3, W4, b4)
-[loss, accuracy] = mnist_lenet::eval(probs, y_test)
+[loss, accuracy] = mnist_lenet::eval(probs, Y_test)
 
 # Output results
 print("Test Accuracy: " + accuracy)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/2a4e4f8b/scripts/nn/examples/mnist_lenet.dml
----------------------------------------------------------------------
diff --git a/scripts/nn/examples/mnist_lenet.dml b/scripts/nn/examples/mnist_lenet.dml
index e5755c4..986d797 100644
--- a/scripts/nn/examples/mnist_lenet.dml
+++ b/scripts/nn/examples/mnist_lenet.dml
@@ -33,8 +33,8 @@ source("nn/layers/relu.dml") as relu
 source("nn/layers/softmax.dml") as softmax
 source("nn/optim/sgd_nesterov.dml") as sgd_nesterov
 
-train = function(matrix[double] X, matrix[double] y,
-                 matrix[double] X_val, matrix[double] y_val,
+train = function(matrix[double] X, matrix[double] Y,
+                 matrix[double] X_val, matrix[double] Y_val,
                  int C, int Hin, int Win, int epochs)
     return (matrix[double] W1, matrix[double] b1,
             matrix[double] W2, matrix[double] b2,
@@ -44,14 +44,14 @@ train = function(matrix[double] X, matrix[double] y,
    * Trains a convolutional net using the "LeNet" architecture.
    *
    * The input matrix, X, has N examples, each represented as a 3D
-   * volume unrolled into a single vector.  The targets, y, have K
+   * volume unrolled into a single vector.  The targets, Y, have K
    * classes, and are one-hot encoded.
    *
    * Inputs:
    *  - X: Input data matrix, of shape (N, C*Hin*Win).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *  - X_val: Input validation data matrix, of shape (N, C*Hin*Win).
-   *  - y_val: Target validation matrix, of shape (N, K).
+   *  - Y_val: Target validation matrix, of shape (N, K).
    *  - C: Number of input channels (dimensionality of input depth).
    *  - Hin: Input height.
    *  - Win: Input width.
@@ -68,7 +68,7 @@ train = function(matrix[double] X, matrix[double] y,
    *  - b4: 4th layer biases vector, of shape (1, K).
    */
   N = nrow(X)
-  K = ncol(y)
+  K = ncol(Y)
 
   # Create network:
   # conv1 -> relu1 -> pool1 -> conv2 -> relu2 -> pool2 -> affine3 -> relu3 -> affine4 -> softmax
@@ -110,7 +110,7 @@ train = function(matrix[double] X, matrix[double] y,
       beg = ((i-1) * batch_size) %% N + 1
       end = min(N, beg + batch_size - 1)
       X_batch = X[beg:end,]
-      y_batch = y[beg:end,]
+      y_batch = Y[beg:end,]
 
       # Compute forward pass
       ## layer 1: conv1 -> relu1 -> pool1
@@ -146,8 +146,8 @@ train = function(matrix[double] X, matrix[double] y,
 
         # Compute validation loss & accuracy
         probs_val = predict(X_val, C, Hin, Win, W1, b1, W2, b2, W3, b3, W4, b4)
-        loss_val = cross_entropy_loss::forward(probs_val, y_val)
-        accuracy_val = mean(rowIndexMax(probs_val) == rowIndexMax(y_val))
+        loss_val = cross_entropy_loss::forward(probs_val, Y_val)
+        accuracy_val = mean(rowIndexMax(probs_val) == rowIndexMax(Y_val))
 
         # Output results
         print("Epoch: " + e + ", Iter: " + i + ", Train Loss: " + loss + ", Train Accuracy: "
@@ -283,37 +283,37 @@ predict = function(matrix[double] X, int C, int Hin, int Win,
   }
 }
 
-eval = function(matrix[double] probs, matrix[double] y)
+eval = function(matrix[double] probs, matrix[double] Y)
     return (double loss, double accuracy) {
   /*
    * Evaluates a convolutional net using the "LeNet" architecture.
    *
    * The probs matrix contains the class probability predictions
-   * of K classes over N examples.  The targets, y, have K classes,
+   * of K classes over N examples.  The targets, Y, have K classes,
    * and are one-hot encoded.
    *
    * Inputs:
    *  - probs: Class probabilities, of shape (N, K).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *
    * Outputs:
    *  - loss: Scalar loss, of shape (1).
    *  - accuracy: Scalar accuracy, of shape (1).
    */
   # Compute loss & accuracy
-  loss = cross_entropy_loss::forward(probs, y)
-  correct_pred = rowIndexMax(probs) == rowIndexMax(y)
+  loss = cross_entropy_loss::forward(probs, Y)
+  correct_pred = rowIndexMax(probs) == rowIndexMax(Y)
   accuracy = mean(correct_pred)
 }
 
 generate_dummy_data = function()
-    return (matrix[double] X, matrix[double] y, int C, int Hin, int Win) {
+    return (matrix[double] X, matrix[double] Y, int C, int Hin, int Win) {
   /*
    * Generate a dummy dataset similar to the MNIST dataset.
    *
    * Outputs:
    *  - X: Input data matrix, of shape (N, D).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *  - C: Number of input channels (dimensionality of input depth).
    *  - Hin: Input height.
    *  - Win: Input width.
@@ -326,6 +326,6 @@ generate_dummy_data = function()
   K = 10  # num target classes
   X = rand(rows=N, cols=C*Hin*Win, pdf="normal")
   classes = round(rand(rows=N, cols=1, min=1, max=K, pdf="uniform"))
-  y = table(seq(1, N), classes)  # one-hot encoding
+  Y = table(seq(1, N), classes)  # one-hot encoding
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/2a4e4f8b/scripts/nn/examples/mnist_softmax-train.dml
----------------------------------------------------------------------
diff --git a/scripts/nn/examples/mnist_softmax-train.dml b/scripts/nn/examples/mnist_softmax-train.dml
index 09970f0..e0c6867 100644
--- a/scripts/nn/examples/mnist_softmax-train.dml
+++ b/scripts/nn/examples/mnist_softmax-train.dml
@@ -73,7 +73,7 @@ out_dir = ifdef($out_dir, ".")
 images = train[,2:ncol(train)]
 labels = train[,1]
 X_test = test[,2:ncol(test)]
-y_test = test[,1]
+Y_test = test[,1]
 
 # Scale images to [0,1], and one-hot encode the labels
 n = nrow(train)
@@ -82,16 +82,16 @@ classes = 10
 images = images / 255.0
 labels = table(seq(1, n), labels+1, n, classes)
 X_test = X_test / 255.0
-y_test = table(seq(1, n_test), y_test+1, n_test, classes)
+Y_test = table(seq(1, n_test), Y_test+1, n_test, classes)
 
 # Split into training (55,000 examples) and validation (5,000 examples)
 X = images[5001:nrow(images),]
 X_val = images[1:5000,]
-y = labels[5001:nrow(images),]
-y_val = labels[1:5000,]
+Y = labels[5001:nrow(images),]
+Y_val = labels[1:5000,]
 
 # Train
-[W, b] = mnist_softmax::train(X, y, X_val, y_val, epochs)
+[W, b] = mnist_softmax::train(X, Y, X_val, Y_val, epochs)
 
 # Write model out
 write(W, out_dir+"/W")
@@ -99,7 +99,7 @@ write(b, out_dir+"/b")
 
 # Eval on test set
 probs = mnist_softmax::predict(X_test, W, b)
-[loss, accuracy] = mnist_softmax::eval(probs, y_test)
+[loss, accuracy] = mnist_softmax::eval(probs, Y_test)
 
 # Output results
 print("Test Accuracy: " + accuracy)

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/2a4e4f8b/scripts/nn/examples/mnist_softmax.dml
----------------------------------------------------------------------
diff --git a/scripts/nn/examples/mnist_softmax.dml b/scripts/nn/examples/mnist_softmax.dml
index a529a12..4a0664f 100644
--- a/scripts/nn/examples/mnist_softmax.dml
+++ b/scripts/nn/examples/mnist_softmax.dml
@@ -28,21 +28,21 @@ source("nn/layers/cross_entropy_loss.dml") as cross_entropy_loss
 source("nn/layers/softmax.dml") as softmax
 source("nn/optim/sgd_nesterov.dml") as sgd_nesterov
 
-train = function(matrix[double] X, matrix[double] y,
-                 matrix[double] X_val, matrix[double] y_val,
+train = function(matrix[double] X, matrix[double] Y,
+                 matrix[double] X_val, matrix[double] Y_val,
                  int epochs)
     return (matrix[double] W, matrix[double] b) {
   /*
    * Trains a softmax classifier.
    *
    * The input matrix, X, has N examples, each with D features.
-   * The targets, y, have K classes, and are one-hot encoded.
+   * The targets, Y, have K classes, and are one-hot encoded.
    *
    * Inputs:
    *  - X: Input data matrix, of shape (N, D).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *  - X_val: Input validation data matrix, of shape (N, C*Hin*Win).
-   *  - y_val: Target validation matrix, of shape (N, K).
+   *  - Y_val: Target validation matrix, of shape (N, K).
    *  - epochs: Total number of full training loops over the full data set.
    *
    * Outputs:
@@ -51,7 +51,7 @@ train = function(matrix[double] X, matrix[double] y,
    */
   N = nrow(X)  # num examples
   D = ncol(X)  # num features
-  K = ncol(y)  # num classes
+  K = ncol(Y)  # num classes
 
   # Create softmax classifier:
   # affine -> softmax
@@ -75,7 +75,7 @@ train = function(matrix[double] X, matrix[double] y,
       beg = ((i-1) * batch_size) %% N + 1
       end = min(N, beg + batch_size - 1)
       X_batch = X[beg:end,]
-      y_batch = y[beg:end,]
+      y_batch = Y[beg:end,]
 
       # Compute forward pass
       ## affine & softmax:
@@ -86,8 +86,8 @@ train = function(matrix[double] X, matrix[double] y,
       loss = cross_entropy_loss::forward(probs, y_batch)
       accuracy = mean(rowIndexMax(probs) == rowIndexMax(y_batch))
       probs_val = predict(X_val, W, b)
-      loss_val = cross_entropy_loss::forward(probs_val, y_val)
-      accuracy_val = mean(rowIndexMax(probs_val) == rowIndexMax(y_val))
+      loss_val = cross_entropy_loss::forward(probs_val, Y_val)
+      accuracy_val = mean(rowIndexMax(probs_val) == rowIndexMax(Y_val))
       print("Epoch: " + e + ", Iter: " + i + ", Train Loss: " + loss + ", Train Accuracy: " +
             accuracy + ", Val Loss: " + loss_val + ", Val Accuracy: " + accuracy_val)
 
@@ -130,37 +130,37 @@ predict = function(matrix[double] X, matrix[double] W, matrix[double] b)
   probs = softmax::forward(out)
 }
 
-eval = function(matrix[double] probs, matrix[double] y)
+eval = function(matrix[double] probs, matrix[double] Y)
     return (double loss, double accuracy) {
   /*
    * Evaluates a softmax classifier.
    *
    * The probs matrix contains the class probability predictions
-   * of K classes over N examples.  The targets, y, have K classes,
+   * of K classes over N examples.  The targets, Y, have K classes,
    * and are one-hot encoded.
    *
    * Inputs:
    *  - probs: Class probabilities, of shape (N, K).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *
    * Outputs:
    *  - loss: Scalar loss, of shape (1).
    *  - accuracy: Scalar accuracy, of shape (1).
    */
   # Compute loss & accuracy
-  loss = cross_entropy_loss::forward(probs, y)
-  correct_pred = rowIndexMax(probs) == rowIndexMax(y)
+  loss = cross_entropy_loss::forward(probs, Y)
+  correct_pred = rowIndexMax(probs) == rowIndexMax(Y)
   accuracy = mean(correct_pred)
 }
 
 generate_dummy_data = function()
-    return (matrix[double] X, matrix[double] y, int C, int Hin, int Win) {
+    return (matrix[double] X, matrix[double] Y, int C, int Hin, int Win) {
   /*
    * Generate a dummy dataset similar to the MNIST dataset.
    *
    * Outputs:
    *  - X: Input data matrix, of shape (N, D).
-   *  - y: Target matrix, of shape (N, K).
+   *  - Y: Target matrix, of shape (N, K).
    *  - C: Number of input channels (dimensionality of input depth).
    *  - Hin: Input height.
    *  - Win: Input width.
@@ -173,6 +173,6 @@ generate_dummy_data = function()
   T = 10  # num targets
   X = rand(rows=N, cols=C*Hin*Win, pdf="normal")
   classes = round(rand(rows=N, cols=1, min=1, max=T, pdf="uniform"))
-  y = table(seq(1, N), classes)  # one-hot encoding
+  Y = table(seq(1, N), classes)  # one-hot encoding
 }