singa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wan...@apache.org
Subject [1/4] incubator-singa git commit: SINGA-85 Add functions for extracting features and test new data
Date Sun, 11 Oct 2015 10:19:07 GMT
Repository: incubator-singa
Updated Branches:
  refs/heads/master f90e4dcdc -> 288a2ab94


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/test/test_csv_input_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_csv_input_layer.cc b/src/test/test_csv_input_layer.cc
new file mode 100644
index 0000000..ce5847d
--- /dev/null
+++ b/src/test/test_csv_input_layer.cc
@@ -0,0 +1,92 @@
+/************************************************************
+*
+* 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 <string>
+#include <vector>
+#include <fstream>
+
+#include "gtest/gtest.h"
+#include "singa/neuralnet/input_layer/csv.h"
+#include "singa/proto/job.pb.h"
+
+class CSVInputLayerTest : public ::testing::Test {
+ protected:
+  virtual void SetUp() {
+    std::string path ="src/test/test.csv";
+    std::ofstream ofs(path, std::ofstream::out);
+    ASSERT_TRUE(ofs.is_open());
+    ofs << "12,3.2,1,14.1\n";
+    ofs << "2,0.2,0,1.1\n";
+    ofs << "1,2.2,1,4.1\n";
+    ofs.close();
+    auto conf = csv_conf.mutable_store_conf();
+    conf->set_path(path);
+    conf->set_batchsize(2);
+    conf->add_shape(3);
+    conf->set_backend("textfile");
+  }
+  singa::LayerProto csv_conf;
+};
+
+TEST_F(CSVInputLayerTest, Setup) {
+  singa::CSVInputLayer layer;
+  layer.Setup(csv_conf, std::vector<singa::Layer*>{});
+  EXPECT_EQ(2, static_cast<int>(layer.aux_data().size()));
+  EXPECT_EQ(6, layer.data(nullptr).count());
+}
+
+TEST_F(CSVInputLayerTest, ComputeFeature) {
+  singa::CSVInputLayer csv;
+  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
+  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+
+  EXPECT_EQ(12, csv.aux_data()[0]);
+  EXPECT_EQ(2, csv.aux_data()[1]);
+  auto data = csv.data(nullptr);
+  EXPECT_EQ(3.2f, data.cpu_data()[0]);
+  EXPECT_EQ(14.1f, data.cpu_data()[2]);
+  EXPECT_EQ(0.2f, data.cpu_data()[3]);
+  EXPECT_EQ(1.1f, data.cpu_data()[5]);
+}
+TEST_F(CSVInputLayerTest, ComputeFeatureDeploy) {
+  singa::CSVInputLayer csv;
+  csv_conf.mutable_store_conf()->set_shape(0, 4);
+  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
+  csv.ComputeFeature(singa::kDeploy, std::vector<singa::Layer*>{});
+
+  auto data = csv.data(nullptr);
+  EXPECT_EQ(12.f, data.cpu_data()[0]);
+  EXPECT_EQ(1.f, data.cpu_data()[2]);
+  EXPECT_EQ(14.1f, data.cpu_data()[3]);
+  EXPECT_EQ(0.2f, data.cpu_data()[5]);
+}
+
+TEST_F(CSVInputLayerTest, SeekToFirst) {
+  singa::CSVInputLayer csv;
+  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
+  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+
+  auto data = csv.data(nullptr);
+  EXPECT_EQ(2.2f, data.cpu_data()[0]);
+  EXPECT_EQ(4.1f, data.cpu_data()[2]);
+  EXPECT_EQ(3.2f, data.cpu_data()[3]);
+  EXPECT_EQ(14.1f, data.cpu_data()[5]);
+}

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/test/test_csv_record_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_csv_record_layer.cc b/src/test/test_csv_record_layer.cc
deleted file mode 100644
index 3f55e9f..0000000
--- a/src/test/test_csv_record_layer.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-/************************************************************
-*
-* 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 <string>
-#include <vector>
-#include <fstream>
-
-#include "gtest/gtest.h"
-#include "singa/neuralnet/input_layer/csv_record.h"
-#include "singa/proto/job.pb.h"
-
-class CSVRecordLayerTest : public ::testing::Test {
- protected:
-  virtual void SetUp() {
-    std::string path ="src/test/test.csv";
-    std::ofstream ofs(path, std::ofstream::out);
-    ASSERT_TRUE(ofs.is_open());
-    ofs << "12,3.2,1,14.1\n";
-    ofs << "2,0.2,0,1.1\n";
-    ofs << "1,2.2,1,4.1\n";
-    ofs.close();
-    auto conf = csv_conf.mutable_store_conf();
-    conf->set_path(path);
-    conf->set_batchsize(2);
-    conf->add_shape(3);
-    conf->set_backend("textfile");
-  }
-  singa::LayerProto csv_conf;
-};
-
-TEST_F(CSVRecordLayerTest, Setup) {
-  singa::CSVRecordLayer layer;
-  layer.Setup(csv_conf, std::vector<singa::Layer*>{});
-  EXPECT_EQ(2, static_cast<int>(layer.aux_data().size()));
-  EXPECT_EQ(6, layer.data(nullptr).count());
-}
-
-TEST_F(CSVRecordLayerTest, ComputeFeature) {
-  singa::CSVRecordLayer csv;
-  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
-  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-
-  EXPECT_EQ(12, csv.aux_data()[0]);
-  EXPECT_EQ(2, csv.aux_data()[1]);
-  auto data = csv.data(nullptr);
-  EXPECT_EQ(3.2f, data.cpu_data()[0]);
-  EXPECT_EQ(14.1f, data.cpu_data()[2]);
-  EXPECT_EQ(0.2f, data.cpu_data()[3]);
-  EXPECT_EQ(1.1f, data.cpu_data()[5]);
-}
-TEST_F(CSVRecordLayerTest, ComputeFeatureDeploy) {
-  singa::CSVRecordLayer csv;
-  csv_conf.mutable_store_conf()->set_shape(0, 4);
-  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
-  csv.ComputeFeature(singa::kDeploy, std::vector<singa::Layer*>{});
-
-  auto data = csv.data(nullptr);
-  EXPECT_EQ(12.f, data.cpu_data()[0]);
-  EXPECT_EQ(1.f, data.cpu_data()[2]);
-  EXPECT_EQ(14.1f, data.cpu_data()[3]);
-  EXPECT_EQ(0.2f, data.cpu_data()[5]);
-}
-
-TEST_F(CSVRecordLayerTest, SeekToFirst) {
-  singa::CSVRecordLayer csv;
-  csv.Setup(csv_conf, std::vector<singa::Layer*>{});
-  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-  csv.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-
-  auto data = csv.data(nullptr);
-  EXPECT_EQ(2.2f, data.cpu_data()[0]);
-  EXPECT_EQ(4.1f, data.cpu_data()[2]);
-  EXPECT_EQ(3.2f, data.cpu_data()[3]);
-  EXPECT_EQ(14.1f, data.cpu_data()[5]);
-}

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/test/test_kvfile.cc
----------------------------------------------------------------------
diff --git a/src/test/test_kvfile.cc b/src/test/test_kvfile.cc
index 9c30734..5707ca9 100644
--- a/src/test/test_kvfile.cc
+++ b/src/test/test_kvfile.cc
@@ -7,9 +7,9 @@
 * 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
@@ -37,48 +37,47 @@ std::string tuple[] = {"firsttuple",
 namespace singa {
 namespace io {
 TEST(KVFileTest, CreateKVFile) {
-  std::string path = "src/test/shard_test";
-  mkdir(path.c_str(), 0755);
-  KVFile shard(path, KVFile::kCreate, 50);
-  shard.Insert(key[0], tuple[0]);
-  shard.Insert(key[1], tuple[1]);
-  shard.Insert(key[2], tuple[2]);
-  shard.Flush();
+  std::string path = "src/test/kvfile.bin";
+  KVFile kvfile(path, KVFile::kCreate, 50);
+  kvfile.Insert(key[0], tuple[0]);
+  kvfile.Insert(key[1], tuple[1]);
+  kvfile.Insert(key[2], tuple[2]);
+  kvfile.Flush();
 }
 
 TEST(KVFileTest, AppendKVFile) {
-  std::string path = "src/test/shard_test";
-  KVFile shard(path, KVFile::kAppend, 50);
-  shard.Insert(key[3], tuple[3]);
-  shard.Insert(key[4], tuple[4]);
-  shard.Flush();
+  std::string path = "src/test/kvfile.bin";
+  KVFile kvfile(path, KVFile::kAppend, 50);
+  kvfile.Insert(key[3], tuple[3]);
+  kvfile.Insert(key[4], tuple[4]);
+  kvfile.Flush();
 }
 
 TEST(KVFileTest, CountKVFile) {
-  std::string path = "src/test/shard_test";
-  KVFile shard(path, KVFile::kRead, 50);
-  int count = shard.Count();
+  std::string path = "src/test/kvfile.bin";
+  KVFile kvfile(path, KVFile::kRead, 50);
+  int count = kvfile.Count();
   ASSERT_EQ(5, count);
 }
 
 TEST(KVFileTest, ReadKVFile) {
-  std::string path = "src/test/shard_test";
-  KVFile shard(path, KVFile::kRead, 50);
+  std::string path = "src/test/kvfile.bin";
+  KVFile kvfile(path, KVFile::kRead, 50);
   std::string k, t;
-  ASSERT_TRUE(shard.Next(&k, &t));
+  ASSERT_TRUE(kvfile.Next(&k, &t));
   ASSERT_STREQ(key[0].c_str(), k.c_str());
   ASSERT_STREQ(tuple[0].c_str(), t.c_str());
-  ASSERT_TRUE(shard.Next(&k, &t));
+  ASSERT_TRUE(kvfile.Next(&k, &t));
   ASSERT_STREQ(key[1].c_str(), k.c_str());
   ASSERT_STREQ(tuple[1].c_str(), t.c_str());
-  ASSERT_TRUE(shard.Next(&k, &t));
-  ASSERT_TRUE(shard.Next(&k, &t));
-  ASSERT_TRUE(shard.Next(&k, &t));
+  ASSERT_TRUE(kvfile.Next(&k, &t));
+  ASSERT_TRUE(kvfile.Next(&k, &t));
+  ASSERT_TRUE(kvfile.Next(&k, &t));
   ASSERT_STREQ(key[4].c_str(), k.c_str());
   ASSERT_STREQ(tuple[4].c_str(), t.c_str());
-  ASSERT_FALSE(shard.Next(&k, &t));
-  shard.SeekToFirst();
-  ASSERT_TRUE(shard.Next(&k, &t));
+  ASSERT_FALSE(kvfile.Next(&k, &t));
+  kvfile.SeekToFirst();
+  ASSERT_TRUE(kvfile.Next(&k, &t));
   ASSERT_STREQ(key[0].c_str(), k.c_str());
   ASSERT_STREQ(tuple[0].c_str(), t.c_str());
 }

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/test/test_proto_record_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_proto_record_layer.cc b/src/test/test_proto_record_layer.cc
deleted file mode 100644
index b1fb1ee..0000000
--- a/src/test/test_proto_record_layer.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-/************************************************************
-*
-* 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 <string>
-#include <vector>
-
-#include "gtest/gtest.h"
-#include "singa/neuralnet/input_layer/proto_record.h"
-#include "singa/proto/job.pb.h"
-#include "singa/proto/common.pb.h"
-
-class ProtoRecordLayerTest : public ::testing::Test {
- protected:
-  virtual void SetUp() {
-    std::string path ="src/test/test.bin";
-    auto* store = singa::io::CreateStore("kvfile");
-    store->Open(path, singa::io::kCreate);
-    {
-    singa::SingleLabelImageRecord image;
-    image.add_data(3.2);
-    image.add_data(1);
-    image.add_data(14.1);
-    image.set_label(12);
-    std::string val;
-    image.SerializeToString(&val);
-    store->Write("0", val);
-    }
-
-    {
-    singa::SingleLabelImageRecord image;
-    image.add_data(0.2);
-    image.add_data(0);
-    image.add_data(1.1);
-    image.set_label(2);
-    std::string val;
-    image.SerializeToString(&val);
-    store->Write("1", val);
-    }
-
-    {
-    singa::SingleLabelImageRecord image;
-    image.add_data(2.2);
-    image.add_data(1);
-    image.add_data(4.1);
-    image.set_label(1);
-    std::string val;
-    image.SerializeToString(&val);
-    store->Write("2", val);
-    }
-    store->Flush();
-    store->Close();
-
-    auto conf = image_conf.mutable_store_conf();
-    conf->set_path(path);
-    conf->set_batchsize(2);
-    conf->add_shape(3);
-    conf->set_backend("kvfile");
-  }
-  singa::LayerProto image_conf;
-};
-
-TEST_F(ProtoRecordLayerTest, Setup) {
-  singa::ProtoRecordLayer layer;
-  layer.Setup(image_conf, std::vector<singa::Layer*>{});
-  EXPECT_EQ(2, static_cast<int>(layer.aux_data().size()));
-  EXPECT_EQ(6, layer.data(nullptr).count());
-}
-
-TEST_F(ProtoRecordLayerTest, ComputeFeature) {
-  singa::ProtoRecordLayer image;
-  image.Setup(image_conf, std::vector<singa::Layer*>{});
-  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-
-  EXPECT_EQ(12, image.aux_data()[0]);
-  EXPECT_EQ(2, image.aux_data()[1]);
-  auto data = image.data(nullptr);
-  EXPECT_EQ(3.2f, data.cpu_data()[0]);
-  EXPECT_EQ(14.1f, data.cpu_data()[2]);
-  EXPECT_EQ(0.2f, data.cpu_data()[3]);
-  EXPECT_EQ(1.1f, data.cpu_data()[5]);
-}
-TEST_F(ProtoRecordLayerTest, ComputeFeatureDeploy) {
-  singa::ProtoRecordLayer image;
-  image.Setup(image_conf, std::vector<singa::Layer*>{});
-  image.ComputeFeature(singa::kDeploy, std::vector<singa::Layer*>{});
-
-  auto data = image.data(nullptr);
-  EXPECT_EQ(3.2f, data.cpu_data()[0]);
-  EXPECT_EQ(14.1f, data.cpu_data()[2]);
-  EXPECT_EQ(0.2f, data.cpu_data()[3]);
-  EXPECT_EQ(1.1f, data.cpu_data()[5]);
-}
-
-TEST_F(ProtoRecordLayerTest, SeekToFirst) {
-  singa::ProtoRecordLayer image;
-  image.Setup(image_conf, std::vector<singa::Layer*>{});
-  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
-
-  auto data = image.data(nullptr);
-  EXPECT_EQ(2.2f, data.cpu_data()[0]);
-  EXPECT_EQ(4.1f, data.cpu_data()[2]);
-  EXPECT_EQ(3.2f, data.cpu_data()[3]);
-  EXPECT_EQ(14.1f, data.cpu_data()[5]);
-}

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/test/test_record_input_layer.cc
----------------------------------------------------------------------
diff --git a/src/test/test_record_input_layer.cc b/src/test/test_record_input_layer.cc
new file mode 100644
index 0000000..78e6047
--- /dev/null
+++ b/src/test/test_record_input_layer.cc
@@ -0,0 +1,122 @@
+/************************************************************
+*
+* 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 <string>
+#include <vector>
+
+#include "gtest/gtest.h"
+#include "singa/neuralnet/input_layer/record.h"
+#include "singa/proto/job.pb.h"
+#include "singa/proto/common.pb.h"
+
+class RecordInputLayerTest : public ::testing::Test {
+ protected:
+  virtual void SetUp() {
+    std::string path ="src/test/test.bin";
+    auto* store = singa::io::CreateStore("kvfile");
+    store->Open(path, singa::io::kCreate);
+    {
+    singa::RecordProto image;
+    image.add_data(3.2);
+    image.add_data(1);
+    image.add_data(14.1);
+    image.set_label(12);
+    std::string val;
+    image.SerializeToString(&val);
+    store->Write("0", val);
+    }
+
+    {
+    singa::SingleLabelImageRecord image;
+    image.add_data(0.2);
+    image.add_data(0);
+    image.add_data(1.1);
+    image.set_label(2);
+    std::string val;
+    image.SerializeToString(&val);
+    store->Write("1", val);
+    }
+
+    {
+    singa::SingleLabelImageRecord image;
+    image.add_data(2.2);
+    image.add_data(1);
+    image.add_data(4.1);
+    image.set_label(1);
+    std::string val;
+    image.SerializeToString(&val);
+    store->Write("2", val);
+    }
+    store->Flush();
+    store->Close();
+
+    auto conf = image_conf.mutable_store_conf();
+    conf->set_path(path);
+    conf->set_batchsize(2);
+    conf->add_shape(3);
+    conf->set_backend("kvfile");
+  }
+  singa::LayerProto image_conf;
+};
+
+TEST_F(RecordInputLayerTest, Setup) {
+  singa::RecordInputLayer layer;
+  layer.Setup(image_conf, std::vector<singa::Layer*>{});
+  EXPECT_EQ(2, static_cast<int>(layer.aux_data().size()));
+  EXPECT_EQ(6, layer.data(nullptr).count());
+}
+
+TEST_F(RecordInputLayerTest, ComputeFeature) {
+  singa::RecordInputLayer image;
+  image.Setup(image_conf, std::vector<singa::Layer*>{});
+  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+
+  EXPECT_EQ(12, image.aux_data()[0]);
+  EXPECT_EQ(2, image.aux_data()[1]);
+  auto data = image.data(nullptr);
+  EXPECT_EQ(3.2f, data.cpu_data()[0]);
+  EXPECT_EQ(14.1f, data.cpu_data()[2]);
+  EXPECT_EQ(0.2f, data.cpu_data()[3]);
+  EXPECT_EQ(1.1f, data.cpu_data()[5]);
+}
+TEST_F(RecordInputLayerTest, ComputeFeatureDeploy) {
+  singa::RecordInputLayer image;
+  image.Setup(image_conf, std::vector<singa::Layer*>{});
+  image.ComputeFeature(singa::kDeploy, std::vector<singa::Layer*>{});
+
+  auto data = image.data(nullptr);
+  EXPECT_EQ(3.2f, data.cpu_data()[0]);
+  EXPECT_EQ(14.1f, data.cpu_data()[2]);
+  EXPECT_EQ(0.2f, data.cpu_data()[3]);
+  EXPECT_EQ(1.1f, data.cpu_data()[5]);
+}
+
+TEST_F(RecordInputLayerTest, SeekToFirst) {
+  singa::RecordInputLayer image;
+  image.Setup(image_conf, std::vector<singa::Layer*>{});
+  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+  image.ComputeFeature(singa::kTrain, std::vector<singa::Layer*>{});
+
+  auto data = image.data(nullptr);
+  EXPECT_EQ(2.2f, data.cpu_data()[0]);
+  EXPECT_EQ(4.1f, data.cpu_data()[2]);
+  EXPECT_EQ(3.2f, data.cpu_data()[3]);
+  EXPECT_EQ(14.1f, data.cpu_data()[5]);
+}

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/e928ebba/src/worker.cc
----------------------------------------------------------------------
diff --git a/src/worker.cc b/src/worker.cc
index 431654a..e6c2279 100644
--- a/src/worker.cc
+++ b/src/worker.cc
@@ -78,32 +78,24 @@ void Worker::InitNetParams(const JobProto& job_conf, NeuralNet* net)
{
         }
       }
     }
-    // load from checkpoints. get param blob based on param name.
-    // the param from previous checkpoint files will be overwritten by
-    // the param with the same name in later checkpoint files.
-    for (const auto path : job_conf.checkpoint_path()) {
-      LOG(ERROR) << "Load from checkpoint file " << path;
-      BlobProtos bps;
-      ReadProtoFromBinaryFile(path.c_str(), &bps);
-      for (int i = 0; i < bps.name_size(); i++) {
-        if (name2param.find(bps.name(i)) != name2param.end()) {
-          name2param.at(bps.name(i))->FromProto(bps.blob(i));
-          //  if load from pre-training params, reset version to start step
-          if (job_conf.reset_param_version())
-            name2param.at(bps.name(i))->set_version(job_conf.step());
-          else  // if resume training, use the same version as last checkpoint
-            name2param.at(bps.name(i))->set_version(bps.version(i));
-        }
-      }
-    }
+    vector<string> paths;
+    for (const auto& p : job_conf_.checkpoint_path())
+      paths.push_back(p);
+    net->Load(paths, name2param);
     // init other params who do not have checkpoint version
-    for (auto entry : name2param)
-      if (entry.second->version() < 0) {
+    for (auto entry : name2param) {
+      if (entry.second->version() > 0) {
+        //  if load from pre-training params, reset version to start step
+        if (job_conf.reset_param_version()) {
+          entry.second->set_version(job_conf.step());
+        }
+      } else {
         entry.second->InitValues(job_conf.step());
         if (!job_conf.reset_param_version())
           LOG(ERROR) << "better reset version of params from checkpoints "
             << "to the same as other newly initialized params!";
       }
+    }
 
     // warmup training before put params to servers
     for (; step_ < job_conf.warmup_steps(); step_++)
@@ -131,6 +123,12 @@ void ConnectStub(int grp, int id, Dealer* dealer, EntityType entity)
{
   dealer->Send(&ping);
 }
 
+void Worker::Test(int steps, Phase phase, NeuralNet* net) {
+  for (int step = 0; step < steps; step++)
+    TestOneBatch(step, phase, net);
+  Display(phase, " ", net);
+}
+
 void Worker::Run() {
   LOG(ERROR) << "Worker (group = " << grp_id_ <<", id = " << id_
<< ") start";
   auto cluster = Cluster::Get();
@@ -156,15 +154,13 @@ void Worker::Run() {
   while (!StopNow(step_)) {
     if (ValidateNow(step_) && val_net_ != nullptr) {
       CollectAll(step_, val_net_);
-      for (int step = 0; step < job_conf_.validate_steps(); step++)
-        TestOneBatch(step, kVal, val_net_);
-      Display(kVal, "Validation @ step " + std::to_string(step_), val_net_);
+      LOG(ERROR) << "Validation @ step " + std::to_string(step_);
+      Test(job_conf_.validate_steps(), kVal, val_net_);
     }
     if (TestNow(step_) && test_net_ != nullptr) {
       CollectAll(step_, test_net_);
-      for (int step = 0; step < job_conf_.test_steps(); step++)
-        TestOneBatch(step, kTest, test_net_);
-      Display(kTest, "Test @ step " + std::to_string(step_), test_net_);
+      LOG(ERROR) << "Test @ step " + std::to_string(step_);
+      Test(job_conf_.test_steps(), kTest, test_net_);
     }
     if (CheckpointNow(step_) && grp_id_ == 0) {
       CollectAll(step_, train_net_);
@@ -212,7 +208,7 @@ void Worker::Checkpoint(int step, const std::string& folder, NeuralNet*
net) {
 
 int Worker::Put(int step, Param* param) {
   if (dealer_ == nullptr) {
-    LOG(ERROR) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
+    LOG(WARNING) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
     return 1;
   }
   Msg* msg = new Msg(Addr(grp_id_, id_, kWorkerParam), Addr(-1, -1, kStub));
@@ -226,7 +222,7 @@ int Worker::Get(int step, Param* param) {
   if (param->version() >= step)
     return 1;
   if (dealer_ == nullptr) {
-    LOG(ERROR) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
+    LOG(WARNING) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
     return 1;
   }
   Msg* msg = new Msg(Addr(grp_id_, id_, kWorkerParam), Addr(-1, -1, kStub));
@@ -239,7 +235,7 @@ int Worker::Get(int step, Param* param) {
 int Worker::Update(int step, Param* param) {
   param->set_local_version(param->version());
   if (dealer_ == nullptr) {
-    LOG(ERROR) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
+    LOG(WARNING) << "Null dealer in worker (" << grp_id_ << ", " <<
id_ << ")";
     return 1;
   }
   Msg* msg = new Msg(Addr(grp_id_, id_, kWorkerParam), Addr(-1, -1, kStub));
@@ -272,7 +268,7 @@ void Worker::Display(int flag, const std::string& prefix, NeuralNet*
net) {
     if (layer->partition_id() == id_) {
       const string& disp = layer->ToString(false, flag);
       if (disp.length())
-        LOG(ERROR) << prefix << ": " << disp;
+        LOG(ERROR) << prefix << "  " << disp;
       if (job_conf_.debug()) {
         const string& info = layer->ToString(true, flag);
         if (info.length()) {


Mime
View raw message