This adds Relu6Converter and TFL/CircleOperationExporter for TFLRelu6.
Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
void visit(locoex::TFLMaxPool2D *) final;
void visit(locoex::TFLMul *) final;
void visit(locoex::TFLRelu *) final;
- // TODO TFLRelu6
+ void visit(locoex::TFLRelu6 *) final;
// TODO TFLReshape
// TODO TFLSoftmax
// TODO TFLSqrt
gd._operators.push_back(op_offset);
}
-// TODO TFLRelu6
+void OperationExporter::visit(locoex::TFLRelu6 *node)
+{
+ uint32_t op_idx = gd.registerBuiltinOpcode(circle::BuiltinOperator_RELU6);
+ std::vector<int32_t> inputs_vec{get_tensor_index(node->features())};
+ std::vector<int32_t> outputs_vec{get_tensor_index(static_cast<loco::Node *>(node))};
+ auto inputs = builder.CreateVector(inputs_vec);
+ auto outputs = builder.CreateVector(outputs_vec);
+ auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
+ gd._operators.push_back(op_offset);
+}
// TODO TFLReshape
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Relu6Converter.h"
+
+#include "GraphBlock.h"
+#include "Check.h"
+
+#include "Dialect/IR/TFLNodes.h"
+
+#include <loco/Service/ShapeInference.h>
+
+namespace exo
+{
+
+bool Relu6Converter::convert(loco::ReLU6 *origin)
+{
+ if (!loco::shape_known(origin))
+ {
+ return false;
+ }
+
+ if (loco::shape_get(origin).domain() == loco::Domain::Tensor)
+ {
+ auto tfl_relu6 = origin->graph()->nodes()->create<locoex::TFLRelu6>();
+ tfl_relu6->features(origin->input());
+
+ loco::replace(origin).with(tfl_relu6);
+ origin->input(nullptr);
+
+ return true;
+ }
+ else if (loco::shape_get(origin).domain() == loco::Domain::Feature)
+ {
+ auto graph = origin->graph();
+ auto dec = make_feature_decode<FeatureLayout::NHWC>(origin->input());
+ auto tfl_relu6 = graph->nodes()->create<locoex::TFLRelu6>();
+ {
+ tfl_relu6->features(dec);
+ }
+ auto enc = make_feature_encode<FeatureLayout::NHWC>(tfl_relu6);
+
+ loco::replace(origin).with(enc);
+ origin->input(nullptr);
+
+ return true;
+ }
+ else
+ EXO_THROW("Not yet supported loco::Domain");
+}
+
+} // namespace exo
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONVERSION_RELU6_CONVERTER_H__
+#define __CONVERSION_RELU6_CONVERTER_H__
+
+#include "CanonicalNodeConverter.h"
+
+#include <loco.h>
+
+namespace exo
+{
+
+/**
+ * @brief Convert loco::Relu6 to TFLRelu6
+ */
+class Relu6Converter : public CanonicalNodeConverter<loco::ReLU6>
+{
+public:
+ const char *name(void) const final { return "exo::Relu6Converter"; }
+
+public:
+ bool convert(loco::ReLU6 *origin) final;
+};
+
+} // namespace exo
+
+#endif // __CONVERSION_RELU6_CONVERTER_H__
void visit(locoex::TFLMaxPool2D *) final;
void visit(locoex::TFLMul *) final;
void visit(locoex::TFLRelu *) final;
- // TODO TFLRelu6
+ void visit(locoex::TFLRelu6 *) final;
// TODO TFLReshape
// TODO TFLSoftmax
// TODO TFLSqrt
gd._operators.push_back(op_offset);
}
-// TODO TFLRelu6
+void OperationExporter::visit(locoex::TFLRelu6 *node)
+{
+ uint32_t op_idx = gd.registerBuiltinOpcode(tflite::BuiltinOperator_RELU6);
+ std::vector<int32_t> inputs_vec{get_tensor_index(node->features())};
+ std::vector<int32_t> outputs_vec{get_tensor_index(static_cast<loco::Node *>(node))};
+ auto inputs = builder.CreateVector(inputs_vec);
+ auto outputs = builder.CreateVector(outputs_vec);
+ auto op_offset = CreateOperator(builder, op_idx, inputs, outputs);
+ gd._operators.push_back(op_offset);
+}
// TODO TFLReshape