You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2018/12/03 02:55:39 UTC
[incubator-singa] 03/03: SINGA-411 Local variable 'params'
referenced before assignment
This is an automated email from the ASF dual-hosted git repository.
wangwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-singa.git
commit 73f963727cf8bd1bfe6e8ec65cd1fedda35cf8fc
Author: xuewanqi <xu...@outlook.com>
AuthorDate: Sat Dec 1 09:38:48 2018 +0000
SINGA-411 Local variable 'params' referenced before assignment
- fix bug.
---
python/singa/net.py | 4 ++--
src/io/snapshot.cc | 9 +++++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/python/singa/net.py b/python/singa/net.py
index 561a6cb..e92d560 100755
--- a/python/singa/net.py
+++ b/python/singa/net.py
@@ -471,8 +471,8 @@ class FeedForwardNet(object):
if f.endswith('.bin'):
f = f[0:-4]
sp = snapshot.Snapshot(f, True, buffer_size)
- #v = tensor.from_numpy(np.array([__version__]))
- #sp.write('SINGA_VERSION', v)
+ v = tensor.from_numpy(np.array([__version__]))
+ sp.write('SINGA_VERSION', v)
for (name, val) in zip(self.param_names(), self.param_values()):
val.to_host()
sp.write(name, val)
diff --git a/src/io/snapshot.cc b/src/io/snapshot.cc
index a95f2c7..86c5ccd 100755
--- a/src/io/snapshot.cc
+++ b/src/io/snapshot.cc
@@ -42,8 +42,11 @@ Snapshot::Snapshot(const std::string& prefix, Mode mode, int max_param_size /*in
text_writer_ptr_->Open(prefix + ".desc", io::kCreate);
// write the current version ids
- text_writer_ptr_->Write("SINGA_VERSION", std::to_string(SINGA_VERSION));
+ //text_writer_ptr_->Write("SINGA_VERSION", std::to_string(SINGA_VERSION));
+ text_writer_ptr_->Write("", "SINGA VERSION: " + std::to_string(SINGA_VERSION));
} else if (mode == kRead) {
+
+ /*
auto text_reader_ptr = new io::TextFileReader();
text_reader_ptr->Open(prefix + ".desc");
std::string key, val;
@@ -52,7 +55,8 @@ Snapshot::Snapshot(const std::string& prefix, Mode mode, int max_param_size /*in
version_ = std::stoi(val);
}
delete text_reader_ptr;
-
+ */
+ std::string key, val;
if (!bin_reader_ptr_->Open(prefix + ".bin", max_param_size << 20))
CHECK(bin_reader_ptr_->Open(prefix + ".model", max_param_size << 20))
<< "Cannot open the checkpoint bin file:" << prefix + ".bin (>=1.0.1) "
@@ -72,6 +76,7 @@ Snapshot::Snapshot(const std::string& prefix, Mode mode, int max_param_size /*in
CHECK(tp.ParseFromString(val));
param_map_[key].FromProto(tp);
}
+ //need ro set version_ by getting data form param_map_["SINGA_VERSION"]?
} else {
LOG(FATAL)
<< "Mode for snapshot should be Snapshot::kWrite or Snapshot::kRead";