提交 948218da 编写于 作者: Y Yu Yang

Unify PrintLogic in PrintLayer/ValuePrinter.

上级 2c07dd50
...@@ -888,19 +888,10 @@ Evaluator* Evaluator::create(const EvaluatorConfig& config) { ...@@ -888,19 +888,10 @@ Evaluator* Evaluator::create(const EvaluatorConfig& config) {
*/ */
class ValuePrinter : public Evaluator { class ValuePrinter : public Evaluator {
public: public:
ValuePrinter() {}
virtual void eval(const NeuralNetwork& nn) { virtual void eval(const NeuralNetwork& nn) {
for (const std::string& name : config_.input_layers()) { for (const std::string& name : config_.input_layers()) {
auto& argu = nn.getLayer(name)->getOutput(); nn.getLayer(name)->getOutput().printValueString(LOG(INFO),
std::unordered_map<std::string, std::string> out; "layer=" + name + " ");
argu.getValueString(&out);
for (auto field : {"value", "id", "sequence pos", "sub-sequence pos"}) {
auto it = out.find(field);
if (it != out.end()) {
LOG(INFO) << "layer=" << name << " " << field << ":\n" << it->second;
}
}
} }
} }
......
...@@ -19,25 +19,17 @@ namespace paddle { ...@@ -19,25 +19,17 @@ namespace paddle {
class PrintLayer : public Layer { class PrintLayer : public Layer {
public: public:
explicit PrintLayer(const LayerConfig& config) : Layer(config) {} explicit PrintLayer(const LayerConfig& config) : Layer(config) {}
void forward(PassType passType) override;
void backward(const UpdateCallback& callback) override {}
};
void PrintLayer::forward(PassType passType) { void forward(PassType passType) override {
Layer::forward(passType); Layer::forward(passType);
for (size_t i = 0; i != inputLayers_.size(); ++i) { for (size_t i = 0; i != inputLayers_.size(); ++i) {
auto& argu = getInput(i); getInput(i).printValueString(LOG(INFO),
const std::string& name = inputLayers_[i]->getName(); "layer=" + inputLayers_[i]->getName() + " ");
std::unordered_map<std::string, std::string> out;
argu.getValueString(&out);
for (auto field : {"value", "id", "sequence pos", "sub-sequence pos"}) {
auto it = out.find(field);
if (it != out.end()) {
LOG(INFO) << "layer=" << name << " " << field << ":\n" << it->second;
}
} }
} }
}
void backward(const UpdateCallback& callback) override {}
};
REGISTER_LAYER(print, PrintLayer); REGISTER_LAYER(print, PrintLayer);
......
...@@ -628,6 +628,18 @@ void Argument::getValueString( ...@@ -628,6 +628,18 @@ void Argument::getValueString(
} }
} }
void Argument::printValueString(std::ostream& stream,
const std::string& prefix) const {
std::unordered_map<std::string, std::string> out;
getValueString(&out);
for (auto field : {"value", "id", "sequence pos", "sub-sequence pos"}) {
auto it = out.find(field);
if (it != out.end()) {
stream << prefix << field << ":\n" << it->second;
}
}
}
void Argument::subArgFrom(const Argument& input, void Argument::subArgFrom(const Argument& input,
size_t offset, size_t offset,
size_t height, size_t height,
......
...@@ -305,6 +305,9 @@ struct Argument { ...@@ -305,6 +305,9 @@ struct Argument {
* @param out [out]: the return values. * @param out [out]: the return values.
*/ */
void getValueString(std::unordered_map<std::string, std::string>* out) const; void getValueString(std::unordered_map<std::string, std::string>* out) const;
void printValueString(std::ostream& stream,
const std::string& prefix = "") const;
}; };
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册