#include "Op/Shape.h"
#include "Op/Sigmoid.h"
#include "Op/Softmax.h"
+#include "Op/Sub.h"
#include "Op/Sum.h"
#include "Op/Transpose.h"
#include "Op/Unsqueeze.h"
registry.registerConverter("Shape", stdex::make_unique<ShapeNodeConverter>());
registry.registerConverter("Sigmoid", stdex::make_unique<SigmoidNodeConverter>());
registry.registerConverter("Softmax", stdex::make_unique<SoftmaxNodeConverter>());
+ registry.registerConverter("Sub", stdex::make_unique<SubNodeConverter>());
registry.registerConverter("Sum", stdex::make_unique<SumNodeConverter>());
registry.registerConverter("Transpose", stdex::make_unique<TransposeNodeConverter>());
registry.registerConverter("Unsqueeze", stdex::make_unique<UnsqueezeNodeConverter>());
--- /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 "Sub.h"
+
+#include "ONNXHelpers.h"
+#include "AttributeHelpers.h"
+
+#include "mir/ops/SubOp.h"
+
+namespace mir_onnx
+{
+
+void SubNodeConverter::convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+ const auto opset_version = context->getOpsetVersion(onnx_node.domain());
+ if (opset_version >= 7)
+ convertV7(onnx_node, context);
+ else if (opset_version >= 6)
+ convertV6(onnx_node, context);
+ else if (opset_version >= 1)
+ convertV1(onnx_node, context);
+ else
+ throw std::runtime_error("Not supported opset version on Sub operation!");
+}
+
+void SubNodeConverter::convertV1(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+ // consumed_inputs attribute not used
+ convertV6(onnx_node, context);
+}
+
+void SubNodeConverter::convertV6(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+ // broadcast attribute not used
+ const auto *axis = findAttribute(onnx_node, "axis");
+ if (axis != nullptr)
+ throw std::runtime_error("Not supported axis attribute in Sub operation!");
+
+ convertV7(onnx_node, context);
+}
+
+void SubNodeConverter::convertV7(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+ std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
+ mir::Graph *graph = context->getGraph();
+
+ auto result = createOp<mir::ops::SubOp>(graph, inputs[0], inputs[1])->getOutput(0);
+
+ context->setNodeOutputs(onnx_node, {result});
+}
+
+} // namespace mir_onnx
--- /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 MIR_ONNX_OP_SUB_H
+#define MIR_ONNX_OP_SUB_H
+
+#include "ONNXNodeConverterRegistry.h"
+
+namespace mir_onnx
+{
+
+class SubNodeConverter : public NodeConverter
+{
+public:
+ void convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const override;
+
+private:
+ void convertV1(const onnx::NodeProto &onnx_node, ConverterContext *context) const;
+ void convertV6(const onnx::NodeProto &onnx_node, ConverterContext *context) const;
+ void convertV7(const onnx::NodeProto &onnx_node, ConverterContext *context) const;
+};
+
+} // namespace mir_onnx
+
+#endif // MIR_ONNX_OP_SUB_H