You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by zh...@apache.org on 2015/11/12 14:15:47 UTC

[2/3] incubator-singa git commit: SINGA-87 Replace exclude field to inlcude field for layer configuration (still support exclude field).

SINGA-87 Replace exclude field to inlcude field for layer configuration (still support exclude field).

Exclude field is deprecated, please use include field instead.
Notice that include field only includes the specified layer.

neuralnet.cc
 - add flag to indicate state, e.g., flag=0, no exclude and no include
 - add checks for exclude and include field, they cannot appear in the same .conf file
job.proto
 - add include field definition in LayerProto


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

Branch: refs/heads/master
Commit: e1a6f14b38674f0d54b5ca020ecc0ae221601c91
Parents: 3f80cca
Author: jixin <ji...@comp.nus.edu.sg>
Authored: Fri Nov 6 15:15:47 2015 +0800
Committer: jixin <ji...@comp.nus.edu.sg>
Committed: Sat Nov 7 14:19:30 2015 +0800

----------------------------------------------------------------------
 examples/cifar10/job.conf     | 21 +++++++++++++++++++--
 examples/mnist/conv.conf      |  4 ++--
 examples/mnist/job.conf       |  4 ++--
 examples/mnist/rbm_job.conf   |  4 ++--
 examples/rbm/autoencoder.conf |  4 ++--
 examples/rbm/rbm1.conf        |  4 ++--
 examples/rbm/rbm2.conf        |  4 ++--
 examples/rbm/rbm3.conf        |  4 ++--
 examples/rbm/rbm4.conf        |  4 ++--
 examples/rnnlm/job.conf       |  4 ++--
 src/neuralnet/neuralnet.cc    | 26 ++++++++++++++++++++++++++
 src/proto/job.proto           |  4 ++++
 12 files changed, 67 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/cifar10/job.conf
----------------------------------------------------------------------
diff --git a/examples/cifar10/job.conf b/examples/cifar10/job.conf
index d69238e..a7540a2 100644
--- a/examples/cifar10/job.conf
+++ b/examples/cifar10/job.conf
@@ -2,6 +2,8 @@ name: "cifar10-convnet"
 train_steps: 1000
 test_steps: 100
 test_freq: 300
+#validate_steps: 100
+#validate_freq: 300
 disp_freq: 30
 #checkpoint_path: "examples/cifar10/checkpoint/step1000-worker0"
 train_one_batch {
@@ -37,8 +39,23 @@ neuralnet {
       shape: 32
       shape: 32
     }
-    exclude: kTest
+    include: kTrain
   }
+#  layer{
+#    name: "data"
+#    type: kRecordInput
+#    store_conf {
+#      backend: "kvfile"
+#      path: "examples/cifar10/val_data.bin"
+#      mean_file: "examples/cifar10/image_mean.bin"
+#      batchsize: 64
+#      random_skip: 5000
+#      shape: 3
+#      shape: 32
+#      shape: 32
+#    }
+#    include: kVal
+#  }
   layer{
     name: "data"
     type: kRecordInput
@@ -51,7 +68,7 @@ neuralnet {
       shape: 32
       shape: 32
     }
-    exclude: kTrain
+    include: kTest
   }
 
   layer {

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/mnist/conv.conf
----------------------------------------------------------------------
diff --git a/examples/mnist/conv.conf b/examples/mnist/conv.conf
index f655cc9..7818af1 100644
--- a/examples/mnist/conv.conf
+++ b/examples/mnist/conv.conf
@@ -33,7 +33,7 @@ neuralnet {
       shape: 28
       shape: 28
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -48,7 +48,7 @@ neuralnet {
       shape: 28
       shape: 28
     }
-    exclude: kTrain
+    include: kTest
   }
 
   layer {

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/mnist/job.conf
----------------------------------------------------------------------
diff --git a/examples/mnist/job.conf b/examples/mnist/job.conf
index 63f59d2..41d6b6f 100644
--- a/examples/mnist/job.conf
+++ b/examples/mnist/job.conf
@@ -31,7 +31,7 @@ neuralnet {
       std_value: 127.5
       mean_value: 127.5
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -45,7 +45,7 @@ neuralnet {
       std_value: 127.5
       mean_value: 127.5
     }
-    exclude: kTrain
+    include: kTest
   }
 
   layer{

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/mnist/rbm_job.conf
----------------------------------------------------------------------
diff --git a/examples/mnist/rbm_job.conf b/examples/mnist/rbm_job.conf
index 87df1b3..59a58dd 100644
--- a/examples/mnist/rbm_job.conf
+++ b/examples/mnist/rbm_job.conf
@@ -28,7 +28,7 @@ model {
       path: "examples/mnist/mnist_train_shard"
       batchsize: 20
     }
-    exclude: kTest
+    include: kTrain
   }
 
 
@@ -39,7 +39,7 @@ model {
       path: "examples/mnist/mnist_test_shard"
       batchsize: 20
     }
-    exclude: kTrain
+    include: kTest
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rbm/autoencoder.conf
----------------------------------------------------------------------
diff --git a/examples/rbm/autoencoder.conf b/examples/rbm/autoencoder.conf
index 87f10f0..b4dfc64 100644
--- a/examples/rbm/autoencoder.conf
+++ b/examples/rbm/autoencoder.conf
@@ -29,7 +29,7 @@ neuralnet {
       std_value: 255
       shape: 784
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -42,7 +42,7 @@ neuralnet {
       batchsize: 100
       shape: 784
     }
-    exclude: kTrain
+    include: kTest
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rbm/rbm1.conf
----------------------------------------------------------------------
diff --git a/examples/rbm/rbm1.conf b/examples/rbm/rbm1.conf
index ef7b875..696a8cb 100644
--- a/examples/rbm/rbm1.conf
+++ b/examples/rbm/rbm1.conf
@@ -27,7 +27,7 @@ neuralnet {
       std_value: 255
       shape: 784
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -40,7 +40,7 @@ neuralnet {
       batchsize: 100
       shape: 784
     }
-    exclude: kTrain
+    include: kTest
   }
 
 layer{

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rbm/rbm2.conf
----------------------------------------------------------------------
diff --git a/examples/rbm/rbm2.conf b/examples/rbm/rbm2.conf
index c5e9f2e..ddb9681 100644
--- a/examples/rbm/rbm2.conf
+++ b/examples/rbm/rbm2.conf
@@ -28,7 +28,7 @@ neuralnet {
       std_value: 255
       shape: 784
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -41,7 +41,7 @@ neuralnet {
       batchsize: 100
       shape: 784
     }
-    exclude: kTrain
+    include: kTest
   }
 
 layer{

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rbm/rbm3.conf
----------------------------------------------------------------------
diff --git a/examples/rbm/rbm3.conf b/examples/rbm/rbm3.conf
index 798cf02..245cafc 100644
--- a/examples/rbm/rbm3.conf
+++ b/examples/rbm/rbm3.conf
@@ -30,7 +30,7 @@ neuralnet {
       std_value: 255
       shape: 784
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -43,7 +43,7 @@ neuralnet {
       batchsize: 100
       shape: 784
     }
-    exclude: kTrain
+    include: kTest
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rbm/rbm4.conf
----------------------------------------------------------------------
diff --git a/examples/rbm/rbm4.conf b/examples/rbm/rbm4.conf
index ae64648..cd4d40a 100644
--- a/examples/rbm/rbm4.conf
+++ b/examples/rbm/rbm4.conf
@@ -28,7 +28,7 @@ neuralnet {
       std_value: 255
       shape: 784
     }
-    exclude: kTest
+    include: kTrain
   }
 
   layer {
@@ -41,7 +41,7 @@ neuralnet {
       batchsize: 100
       shape: 784
     }
-    exclude: kTrain
+    include: kTest
   }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/examples/rnnlm/job.conf
----------------------------------------------------------------------
diff --git a/examples/rnnlm/job.conf b/examples/rnnlm/job.conf
index a1f803d..aca1166 100644
--- a/examples/rnnlm/job.conf
+++ b/examples/rnnlm/job.conf
@@ -37,7 +37,7 @@ layer {
     path: "examples/rnnlm/train_data.bin"
     max_window: 10
   }
-  exclude: kVal
+  include: kTrain
 }
 
 layer {
@@ -47,7 +47,7 @@ layer {
     path: "examples/rnnlm/valid_data.bin"
     max_window: 10
   }
-  exclude: kTrain
+  include: kVal
 }
 
 layer{

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/src/neuralnet/neuralnet.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/neuralnet.cc b/src/neuralnet/neuralnet.cc
index dc85674..8ae1805 100644
--- a/src/neuralnet/neuralnet.cc
+++ b/src/neuralnet/neuralnet.cc
@@ -39,12 +39,38 @@ NeuralNet* NeuralNet::Create(const NetProto& net_conf, Phase phase,
   // for sharing param conf
   std::unordered_map<string, ParamProto*> name2param;
   std::vector<ParamProto*> shares;
+  // flag=0: neither exclude nor include field appears
+  // flag=1: exclude field appears
+  // flag=2: include field appears
+  int flag = 0;
   // exclude layers according to phase
+  // exclude field is deprecated
+  // please use include field instead
   for (const auto& layer : net_conf.layer()) {
     bool include = true;
     for (auto p : layer.exclude()) {
+      // check whether both exclude and include field
+      // appear in the same .conf file
+      CHECK(flag == 0 || flag == 1)
+        << "include and exclude field should not simultaneously"
+        << " appear in the same .conf file";
       if (p == phase)
         include = false;
+      flag = 1;
+    }
+    // neural net only include the specified layer in the include field
+    for (auto p : layer.include()) {
+      // check whether both exclude and include field
+      // appear in the same .conf file
+      CHECK(flag == 0 || flag == 2)
+        << "include and exclude field should not simultaneously"
+        << " appear in the same .conf file";
+      if (p == phase) {
+        include = true;
+        break;
+      }
+      include = false;
+      flag = 2;
     }
     if (include == false) continue;
     LayerProto* layer_conf = conf.add_layer();

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e1a6f14b/src/proto/job.proto
----------------------------------------------------------------------
diff --git a/src/proto/job.proto b/src/proto/job.proto
index eb1b876..6308c2e 100644
--- a/src/proto/job.proto
+++ b/src/proto/job.proto
@@ -178,6 +178,10 @@ message LayerProto {
   // some layers like data layer for loading test data are not used by training
   // phase should be removed by setting the exclude field.
   repeated Phase exclude = 15;
+  // exclude field is deprecated, please use include field instead!!!
+  // some layers like data layer for loading test data are not used by training
+  // in this case, only test phase should be included by setting the include field.
+  repeated Phase include = 14;
   // type of built-in layer
   optional LayerType type = 20 [default = kUserLayer];
   // type of user layer