singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wan...@apache.org
Subject [5/5] incubator-singa git commit: SINGA-82 Refactor input layers using data store abstraction
Date Wed, 07 Oct 2015 07:26:12 GMT
SINGA-82 Refactor input layers using data store abstraction

* Enable StoreInputLayer to partition on dim = 0.
* Add random skip for StoreInputLayer, which randomly skip some records
at the beginning to make sure workers within the same group and running
in the same process train over different data records.


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

Branch: refs/heads/master
Commit: 4afc7b893816f0fbb3141e72e3921fcd46feb8e4
Parents: 5f010ca
Author: Wei Wang <wangwei@comp.nus.edu.sg>
Authored: Tue Oct 6 22:43:50 2015 +0800
Committer: wang sheng <wangsheng1001@gmail.com>
Committed: Wed Oct 7 15:19:59 2015 +0800

----------------------------------------------------------------------
 include/neuralnet/input_layer.h |  3 ++-
 include/utils/image_transform.h | 29 +++++++++++++++++++++++++++++
 src/neuralnet/input_layer.cc    | 12 ++++++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4afc7b89/include/neuralnet/input_layer.h
----------------------------------------------------------------------
diff --git a/include/neuralnet/input_layer.h b/include/neuralnet/input_layer.h
index 4dfded0..65e42cb 100644
--- a/include/neuralnet/input_layer.h
+++ b/include/neuralnet/input_layer.h
@@ -69,7 +69,8 @@ class StoreInputLayer : virtual public InputLayer {
   virtual bool Parse(int k, int flag, const string& key, const string& val) = 0;
 
  protected:
-  int batchsize_;
+  int batchsize_ = 1;
+  int random_skip_ = 0;
   io::Store* store_ = nullptr;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4afc7b89/include/utils/image_transform.h
----------------------------------------------------------------------
diff --git a/include/utils/image_transform.h b/include/utils/image_transform.h
new file mode 100644
index 0000000..24fe75d
--- /dev/null
+++ b/include/utils/image_transform.h
@@ -0,0 +1,29 @@
+/************************************************************
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*************************************************************/
+#include <glog/logging.h>
+// TODO(wangwei) provide image transformation API, the implementation can be
+// done by opencv, manual transform, or mshadow.
+namespace singa {
+
+void ImageTransform(const float* in, const float* mean, bool mirror, int h_crop,
+    int w_crop, int h_offset, int w_offset, int channel, int height, int width,
+    float scale, float* out);
+} /* singa */

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/4afc7b89/src/neuralnet/input_layer.cc
----------------------------------------------------------------------
diff --git a/src/neuralnet/input_layer.cc b/src/neuralnet/input_layer.cc
index b4743f4..1599def 100644
--- a/src/neuralnet/input_layer.cc
+++ b/src/neuralnet/input_layer.cc
@@ -85,6 +85,11 @@ void StoreInputLayer::Setup(const LayerProto& conf,
     const vector<Layer*>& srclayers) {
   InputLayer::Setup(conf, srclayers);
   batchsize_ = conf.store_conf().batchsize();
+  if (conf.partition_dim() == 0) {
+    batchsize_ /= conf.num_partitions();
+  }
+  if (conf.store_conf().random_skip() > 0)
+    random_skip_ = rand() % conf.store_conf().random_skip();
 }
 
 void StoreInputLayer::ComputeFeature(int flag,
@@ -94,6 +99,13 @@ void StoreInputLayer::ComputeFeature(int flag,
     store_ = io::OpenStore(layer_conf_.store_conf().backend(),
                              layer_conf_.store_conf().path(),
                              io::kRead);
+    while (random_skip_ > 0) {
+      if (!store_->Read(&key, &val)) {
+        store_->SeekToFirst();
+        CHECK(store_->Read(&key, &val));
+      }
+      random_skip_ --;
+    }
   }
   for (int k = 0; k < batchsize_; k++){
     if (!store_->Read(&key, &val)) {


Mime
View raw message