[tfldump] dump operand quantization (#2495)
author박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 5 Dec 2018 03:39:38 +0000 (12:39 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 5 Dec 2018 03:39:38 +0000 (12:39 +0900)
* [tfldump] dump operand quantization

This will add dump to dump operand quantization information.
For this, add dump of flatbuffers::Vector type.

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
* remove unused

contrib/tfldump/src/Dump.cpp

index dcf546f..345a392 100644 (file)
@@ -72,6 +72,26 @@ std::ostream &operator<<(std::ostream &os, const std::vector<int> &vect)
   return os;
 }
 
+template <typename T> void dump_fbvect(std::ostream &os, const flatbuffers::Vector<T> *fbvect)
+{
+  if (fbvect == nullptr)
+    return;
+
+  for (uint32_t q = 0; q < fbvect->size(); q++)
+  {
+    if (q)
+      os << ", ";
+    os << fbvect->Get(q);
+  }
+}
+
+template <typename T>
+std::ostream &operator<<(std::ostream &os, const flatbuffers::Vector<T> *fbvect)
+{
+  dump_fbvect(os, fbvect);
+  return os;
+}
+
 void dump_model(std::ostream &os, const tflite::Model *model)
 {
   tflread::Reader reader(model);
@@ -124,6 +144,25 @@ void dump_model(std::ostream &os, const tflite::Model *model)
     os << "(" << dims << ") ";
     os << "B(" << tensor->buffer() << ") ";
     os << tflread::tensor_name(tensor) << std::endl;
+
+    if (auto q_params = tensor->quantization())
+    {
+      if (q_params->min() && q_params->max() || q_params->scale() && q_params->zero_point())
+      {
+        os << "    Quantization: ";
+
+        if (q_params->min())
+          os << "min(" << q_params->min() << ") ";
+        if (q_params->max())
+          os << "max(" << q_params->max() << ") ";
+        if (q_params->scale())
+          os << "scale(" << q_params->scale() << ") ";
+        if (q_params->zero_point())
+          os << "zeropt(" << q_params->zero_point() << ") ";
+
+        os << std::endl;
+      }
+    }
   }
   os << std::endl;