#include "Op/MaxPool.h"
#include "Op/Mul.h"
#include "Op/Pad.h"
+#include "Op/ReduceMean.h"
#include "Op/Relu.h"
#include "Op/Reshape.h"
#include "Op/Shape.h"
registry.registerConverter("MaxPool", stdex::make_unique<MaxPoolNodeConverter>());
registry.registerConverter("Mul", stdex::make_unique<MulNodeConverter>());
registry.registerConverter("Pad", stdex::make_unique<PadNodeConverter>());
+ registry.registerConverter("ReduceMean", stdex::make_unique<ReduceMeanNodeConverter>());
registry.registerConverter("Relu", stdex::make_unique<ReluNodeConverter>());
registry.registerConverter("Reshape", stdex::make_unique<ReshapeNodeConverter>());
registry.registerConverter("Shape", stdex::make_unique<ShapeNodeConverter>());
--- /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 "ReduceMean.h"
+
+#include "ONNXHelpers.h"
+#include "AttributeHelpers.h"
+
+#include "mir/ops/ReduceOp.h"
+
+#include <numeric>
+
+namespace mir_onnx
+{
+
+void ReduceMeanNodeConverter::convert(const onnx::NodeProto &onnx_node,
+ ConverterContext *context) const
+{
+ const auto opset_version = context->getOpsetVersion(onnx_node.domain());
+
+ if (opset_version >= 1)
+ convertV1(onnx_node, context);
+ else
+ throw std::runtime_error("Not supported opset version on ReduceMean operation!");
+}
+
+void ReduceMeanNodeConverter::convertV1(const onnx::NodeProto &onnx_node,
+ ConverterContext *context) const
+{
+ const auto inputs = context->getNodeInputs(onnx_node);
+ assert(inputs.size() == 1);
+
+ const auto axes = getAttributeValue<std::vector<std::int64_t>>(onnx_node, "axes");
+ const auto keepdims = getAttributeValue<int64_t>(onnx_node, "keepdims", 1);
+
+ std::vector<int32_t> reduce_dims;
+ if (axes.empty())
+ { // reduce over all dimensions
+ reduce_dims.resize(inputs[0]->getShape().rank());
+ std::iota(reduce_dims.begin(), reduce_dims.end(), 0);
+ }
+ else
+ {
+ reduce_dims.resize(axes.size());
+ std::copy(axes.begin(), axes.end(), reduce_dims.begin());
+ }
+ // Keep the reduced dimension or not, default 1 mean keep reduced dimension.
+ bool keep_dims = static_cast<bool>(keepdims);
+
+ mir::Graph *graph = context->getGraph();
+ auto result = createOp<mir::ops::ReduceOp>(graph, inputs[0], reduce_dims, keep_dims,
+ mir::ops::ReduceOp::FuncType::mean)
+ ->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_REDUCEMEAN_H
+#define MIR_ONNX_OP_REDUCEMEAN_H
+
+#include "ONNXNodeConverterRegistry.h"
+
+namespace mir_onnx
+{
+
+class ReduceMeanNodeConverter : 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;
+};
+
+} // namespace mir_onnx
+
+#endif // MIR_ONNX_OP_REDUCEMEAN_H