From 6e9d0e048b48712f4f72d4b0a5b94a277391a357 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Fri, 3 Jan 2020 15:02:04 +0000 Subject: COMPMID-2856 Add PrintLayer at graph level Signed-off-by: Giorgio Arena Change-Id: I8f02bb67adae8cc7d884f2417cc9c408985f0d5a Reviewed-on: https://review.mlplatform.org/c/2546 Reviewed-by: Manuel Bottini Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas --- arm_compute/graph/frontend/Layers.h | 59 ++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'arm_compute/graph/frontend/Layers.h') diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h index ec69350f86..2b44d0e844 100644 --- a/arm_compute/graph/frontend/Layers.h +++ b/arm_compute/graph/frontend/Layers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019 ARM Limited. + * Copyright (c) 2018-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -902,6 +902,63 @@ private: PoolingLayerInfo _pool_info; }; +/** Print Layer */ +class PrintLayer final : public ILayer +{ +public: + /** Construct a print layer. + * + * Example usage to locally dequantize and print a tensor: + * + * Tensor *output = new Tensor(); + * const auto transform = [output](ITensor *input) + * { + * output->allocator()->init(*input->info()); + * output->info()->set_data_type(DataType::F32); + * output->allocator()->allocate(); + * + * Window win; + * win.use_tensor_dimensions(input->info()->tensor_shape()); + * Iterator in(input, win); + * Iterator out(output, win); + * execute_window_loop(win, [&](const Coordinates &) + * { + * *(reinterpret_cast(out.ptr())) = dequantize_qasymm8(*in.ptr(), input->info()->quantization_info().uniform()); + * }, in, out); + * + * return output; + * }; + * + * graph << InputLayer(input_descriptor.set_quantization_info(in_quant_info), get_input_accessor(common_params, nullptr, false)) + * << ... + * << \\ CNN Layers + * << ... + * << PrintLayer(std::cout, IOFormatInfo(), transform) + * << ... + * << OutputLayer(get_output_accessor(common_params, 5)); + * + * @param[in] stream Output stream. + * @param[in] format_info (Optional) Format info. + * @param[in] transform (Optional) Input transform function. + */ + PrintLayer(std::ostream &stream, const IOFormatInfo &format_info = IOFormatInfo(), const std::function transform = nullptr) + : _stream(stream), _format_info(format_info), _transform(transform) + { + } + + NodeID create_layer(IStream &s) override + { + NodeParams common_params = { name(), s.hints().target_hint }; + NodeIdxPair input = { s.tail_node(), 0 }; + return GraphBuilder::add_print_node(s.graph(), common_params, input, _stream, _format_info, _transform); + } + +private: + std::ostream &_stream; + const IOFormatInfo &_format_info; + const std::function _transform; +}; + /** PriorBox Layer */ class PriorBoxLayer final : public ILayer { -- cgit v1.2.1