diff options
author | Michele Di Giorgio <michele.digiorgio@arm.com> | 2021-02-01 10:39:06 +0000 |
---|---|---|
committer | Michele Di Giorgio <michele.digiorgio@arm.com> | 2021-02-15 10:47:53 +0000 |
commit | c22eb1b2a4c68735e01d64cfb83efae5375901b0 (patch) | |
tree | 1a9cd083a485ea0c71c27f69ce6f7474509c0422 | |
parent | 6413e493b15b04d27304c0e52ccf2ecd2ec9c302 (diff) | |
download | ComputeLibrary-c22eb1b2a4c68735e01d64cfb83efae5375901b0.tar.gz |
Provide utlity function to print ITensorInfo
Initial version of this function will print the tensor shape, its data
type, its data layout and the quantization parameters in case of quantized
data type.
Change-Id: Idaf3531ccecd8d655f9597121935540ee8371fa5
Signed-off-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5035
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Giorgio Arena <giorgio.arena@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r-- | utils/TypePrinter.h | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index bf5b64a1eb..53a8902dd4 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -1074,6 +1074,47 @@ inline ::std::ostream &operator<<(::std::ostream &os, const SamplingPolicy &poli return os; } +/** Formatted output of the ITensorInfo type. + * + * @param[out] os Output stream. + * @param[in] info Tensor information. + * + * @return Modified output stream. + */ +inline ::std::ostream &operator<<(std::ostream &os, const ITensorInfo *info) +{ + const DataType data_type = info->data_type(); + const DataLayout data_layout = info->data_layout(); + + os << "Shape=" << info->tensor_shape() << "," + << "DataLayout=" << string_from_data_layout(data_layout) << "," + << "DataType=" << string_from_data_type(data_type) << ","; + + if(is_data_type_quantized(data_type)) + { + const QuantizationInfo qinfo = info->quantization_info(); + os << "QuantizationInfo="; + if(is_data_type_quantized_per_channel(data_type)) + { + os << "["; + const auto scales = qinfo.scale(); + const auto offsets = qinfo.offset(); + os << "(" << scales[0] << ", " << offsets[0] << ")"; + for(size_t i = 1; i < scales.size(); ++i) + { + os << ",(" << scales[i] << ", " << offsets[i] << ")"; + } + os << "]"; + } + else + { + os << "(" << qinfo.uniform().scale << ", " + << qinfo.uniform().offset << ")"; + } + } + return os; +} + /** Formatted output of the TensorInfo type. * * @param[out] os Output stream. @@ -1083,11 +1124,10 @@ inline ::std::ostream &operator<<(::std::ostream &os, const SamplingPolicy &poli */ inline ::std::ostream &operator<<(::std::ostream &os, const TensorInfo &info) { - os << "{Shape=" << info.tensor_shape() << "," - << "Type=" << info.data_type() << "," - << "Channels=" << info.num_channels() << "}"; - return os; + os << &info; + return os; } + /** Formatted output of the TensorInfo type. * * @param[in] info Type to output. @@ -1097,7 +1137,7 @@ inline ::std::ostream &operator<<(::std::ostream &os, const TensorInfo &info) inline std::string to_string(const TensorInfo &info) { std::stringstream str; - str << info; + str << &info; return str.str(); } |