*/
#include "DumpOp.h"
+#include "Read.h"
+
+#include <stdex/Memory.h>
+
+using stdex::make_unique;
namespace tfldump
{
+// TODO move to some header
+std::ostream &operator<<(std::ostream &os, const std::vector<int32_t> &vect);
+
+class DumpOpConv2D : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto conv_params = op->builtin_options_as_Conv2DOptions())
+ {
+ os << " ";
+ os << "Padding(" << conv_params->padding() << ") ";
+ os << "Stride.W(" << conv_params->stride_w() << ") ";
+ os << "Stride.H(" << conv_params->stride_h() << ") ";
+ os << "Activation(" << conv_params->fused_activation_function() << ")";
+ os << std::endl;
+ }
+ }
+};
+
+class DumpOpPool2D : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto pool_params = op->builtin_options_as_Pool2DOptions())
+ {
+ os << " ";
+ os << "Padding(" << pool_params->padding() << ") ";
+ os << "Stride.W(" << pool_params->stride_w() << ") ";
+ os << "Stride.H(" << pool_params->stride_h() << ") ";
+ os << "Filter.W(" << pool_params->filter_width() << ") ";
+ os << "Filter.H(" << pool_params->filter_height() << ") ";
+ os << "Activation(" << pool_params->fused_activation_function() << ")";
+ os << std::endl;
+ }
+ }
+};
+
+class DumpOpConcatenation : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto *concatenation_params = op->builtin_options_as_ConcatenationOptions())
+ {
+ os << " ";
+ os << "Activation(" << concatenation_params->fused_activation_function() << ") ";
+ os << "Axis(" << concatenation_params->axis() << ")";
+ os << std::endl;
+ }
+ }
+};
+
+class DumpOpReshape : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto *reshape_params = op->builtin_options_as_ReshapeOptions())
+ {
+ auto new_shape = tflread::as_index_vector(reshape_params->new_shape());
+ os << " ";
+ os << "NewShape(" << new_shape << ")";
+ os << std::endl;
+ }
+ }
+};
+
+class DumpOpDepthwiseConv2D : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto conv_params = op->builtin_options_as_DepthwiseConv2DOptions())
+ {
+ os << " ";
+ os << "Padding(" << conv_params->padding() << ") ";
+ os << "Stride.W(" << conv_params->stride_w() << ") ";
+ os << "Stride.H(" << conv_params->stride_h() << ") ";
+ os << "DepthMultiplier(" << conv_params->depth_multiplier() << ") ";
+ os << "Activation(" << conv_params->fused_activation_function() << ") ";
+ os << "Dilation.W(" << conv_params->dilation_w_factor() << ") ";
+ os << "Dilation.H(" << conv_params->dilation_h_factor() << ")";
+ os << std::endl;
+ }
+ }
+};
+
+class DumpOpSoftmax : public DumpOp
+{
+public:
+ void options(const tflite::Operator *op, std::ostream &os) const override
+ {
+ if (auto *softmax_params = op->builtin_options_as_SoftmaxOptions())
+ {
+ os << " ";
+ os << "Beta(" << softmax_params->beta() << ")";
+ os << std::endl;
+ }
+ }
+};
+
DumpOpRegistry::DumpOpRegistry()
{
- // TODO fill map
+ _dumpop_map[tflite::BuiltinOperator_AVERAGE_POOL_2D] = make_unique<DumpOpPool2D>();
+ _dumpop_map[tflite::BuiltinOperator_CONCATENATION] = make_unique<DumpOpConcatenation>();
+ _dumpop_map[tflite::BuiltinOperator_CONV_2D] = make_unique<DumpOpConv2D>();
+ _dumpop_map[tflite::BuiltinOperator_DEPTHWISE_CONV_2D] = make_unique<DumpOpDepthwiseConv2D>();
+ _dumpop_map[tflite::BuiltinOperator_MAX_POOL_2D] = make_unique<DumpOpPool2D>();
+ // There is no Option for ReLU and ReLU6
+ _dumpop_map[tflite::BuiltinOperator_RESHAPE] = make_unique<DumpOpReshape>();
+ _dumpop_map[tflite::BuiltinOperator_SOFTMAX] = make_unique<DumpOpSoftmax>();
}
} // namespace tfldump