SINGA-115 - Print layer debug information in the neural net graph file Overrride the ToString function in SliceLayer and SplitLayer. These two layers need to print the norm of multiple blobs as they have multiple out-going connections.
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/c8cb9137 Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/c8cb9137 Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/c8cb9137 Branch: refs/heads/master Commit: c8cb913732a4ca861fda1d1667ca56ed5e3b5001 Parents: 1f977b1 Author: Wei Wang <[email protected]> Authored: Fri Dec 25 12:34:33 2015 +0800 Committer: Wei Wang <[email protected]> Committed: Fri Dec 25 12:34:33 2015 +0800 ---------------------------------------------------------------------- include/singa/neuralnet/connection_layer.h | 2 ++ src/neuralnet/connection_layer/slice.cc | 16 +++++++++++++++- src/neuralnet/connection_layer/split.cc | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c8cb9137/include/singa/neuralnet/connection_layer.h ---------------------------------------------------------------------- diff --git a/include/singa/neuralnet/connection_layer.h b/include/singa/neuralnet/connection_layer.h index 0cbe940..c9b0caf 100644 --- a/include/singa/neuralnet/connection_layer.h +++ b/include/singa/neuralnet/connection_layer.h @@ -97,6 +97,7 @@ class SliceLayer : public ConnectionLayer { void Setup(const LayerProto& proto, const vector<Layer*>& srclayers) override; void ComputeFeature(int flag, const vector<Layer*>& srclayers) override; void ComputeGradient(int flag, const vector<Layer*>& srclayers) override; + const std::string ToString(bool debug, int flag) override; const Blob<float>& data(const Layer* from) const override; const Blob<float>& grad(const Layer* from) const override; Blob<float>* mutable_data(const Layer* from) override; @@ -116,6 +117,7 @@ class SplitLayer : public ConnectionLayer { void Setup(const LayerProto& proto, const vector<Layer*>& srclayers) override; void ComputeFeature(int flag, const vector<Layer*>& srclayers) override; void ComputeGradient(int flag, const vector<Layer*>& srclayers) override; + const std::string ToString(bool debug, int flag) override; const Blob<float>& grad(const Layer* from) const override; Blob<float>* mutable_grad(const Layer* from) override; }; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c8cb9137/src/neuralnet/connection_layer/slice.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/connection_layer/slice.cc b/src/neuralnet/connection_layer/slice.cc index a607a95..b28d4c4 100644 --- a/src/neuralnet/connection_layer/slice.cc +++ b/src/neuralnet/connection_layer/slice.cc @@ -20,6 +20,7 @@ *************************************************************/ #include "singa/neuralnet/connection_layer.h" +#include "singa/utils/math_blob.h" namespace singa { @@ -118,5 +119,18 @@ Blob<float>* SliceLayer::mutable_grad(const Layer* from) { CHECK_LT(from->partition_id(), num_partitions()); return gradvec_[from->partition_id()]; } - +const std::string SliceLayer::ToString(bool debug, int flag) { + if (!debug) + return ""; + string ret = ""; + if ((flag & kForward) == kForward && data_.count() !=0) { + for (unsigned k = 0; k < datavec_.size(); k++) + ret += StringPrintf("data-%u :%13.9f ", k, Asum(*datavec_.at(k))); + } + if ((flag & kBackward) == kBackward && grad_.count() != 0) { + for (unsigned k = 0; k < gradvec_.size(); k++) + ret += StringPrintf("grad-%u:%13.9f ", k, Asum(*gradvec_.at(k))); + } + return ret; +} } // namespace singa http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/c8cb9137/src/neuralnet/connection_layer/split.cc ---------------------------------------------------------------------- diff --git a/src/neuralnet/connection_layer/split.cc b/src/neuralnet/connection_layer/split.cc index 5b9db5b..d2af59d 100644 --- a/src/neuralnet/connection_layer/split.cc +++ b/src/neuralnet/connection_layer/split.cc @@ -20,6 +20,7 @@ *************************************************************/ #include "singa/neuralnet/connection_layer.h" +#include "singa/utils/math_blob.h" namespace singa { @@ -72,5 +73,17 @@ Blob<float>* SplitLayer::mutable_grad(const Layer* from) { CHECK_LT(from->partition_id(), num_partitions()); return gradvec_[from->partition_id()]; } - +const std::string SplitLayer::ToString(bool debug, int flag) { + if (!debug) + return ""; + string ret = ""; + if ((flag & kForward) == kForward && data_.count() !=0) { + ret += StringPrintf("data:%13.9f ", Asum(data_)); + } + if ((flag & kBackward) == kBackward && grad_.count() != 0) { + for (unsigned k = 0; k < gradvec_.size(); k++) + ret += StringPrintf("grad-%u:%13.9f ", k, Asum(*gradvec_.at(k))); + } + return ret; +} } // namespace singa
