#include "caffe2_proto_helper.h"
#include "mir/ops/AddOp.h"
+#include "mir/ops/AvgPool2DOp.h"
#include "mir/ops/CappedReluOp.h"
#include "mir/ops/ConcatOp.h"
#include "mir/ops/ConstantOp.h"
#include "mir/ops/Conv2DOp.h"
#include "mir/ops/DepthwiseConv2DOp.h"
#include "mir/ops/FullyConnectedOp.h"
+#include "mir/ops/MaxPool2DOp.h"
#include "mir/ops/MulOp.h"
-#include "mir/ops/PoolOp.h"
#include "mir/ops/ReluOp.h"
#include "mir/ops/ReshapeOp.h"
#include "mir/ops/ResizeOp.h"
return {{pad, pad}, {pad, pad}};
}
-static std::vector<int32_t> getStrides(const ::caffe2::OperatorDef &op)
+static std::vector<std::int32_t> getStrides(const ::caffe2::OperatorDef &op)
{
- std::vector<int32_t> strides;
+ std::vector<std::int32_t> strides;
if (hasArgument(op.arg(), "stride"))
{
- int stride = getSingleArgument(op, "stride", 1);
+ std::int32_t stride = getSingleArgument(op, "stride", 1);
strides = {stride, stride};
}
return strides;
}
-static Shape getWindowShape(const ::caffe2::OperatorDef &op,
- const std::vector<mir::Operation::Output *> &inputs)
+static std::vector<std::int32_t> getWindowSize(const ::caffe2::OperatorDef &op,
+ const std::vector<mir::Operation::Output *> &inputs)
{
int is_global_pooling = getSingleArgument(op, "global_pooling", 0);
bool has_custom_kernel_size =
if (is_global_pooling)
{
const auto &input_shape = inputs[0]->getShape();
- assert(input_shape.rank() == 4 && "getWindowShape() inputs must be of rank 4");
+ assert(input_shape.rank() == 4 && "getWindowSize() inputs must be of rank 4");
kernel_h = input_shape.dim(2);
kernel_w = input_shape.dim(3);
}
}
}
}
- return Shape{kernel_h, kernel_w};
+ return {kernel_h, kernel_w};
}
mir::Operation::Output *Caffe2OpCreator::convertCaffeToMIR(mir::Operation::Output *arg)
auto result = createOp<ops::AddOp>(inputs[0], inputs[1])->getOutput(0);
return {result};
}
+
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertAveragePool(const std::vector<mir::Operation::Output *> &inputs,
const OperatorDef &op)
{
checkConvLikeOp(op);
- Shape window_shape = getWindowShape(op, inputs);
-
- Shape strides(getStrides(op));
-
- ops::PoolOp::PoolingType pool_type = ops::PoolOp::PoolingType::AVG;
- ops::PoolOp::BorderType border_type = ops::PoolOp::BorderType::EMPTY;
+ assert(inputs.size() == 1);
+ auto input = inputs[0];
- std::vector<int32_t> pad_before, pad_after;
+ const auto window_size = getWindowSize(op, inputs);
+ const auto strides = getStrides(op);
+ std::vector<std::int32_t> pad_before, pad_after;
std::tie(pad_before, pad_after) = getPadding(op);
- auto pooling = createOp<ops::PoolOp>(convertCaffeToMIR(inputs[0]), pool_type, window_shape,
- strides, pad_before, pad_after, border_type);
-
- return {convertMIRToCaffe(pooling->getOutput(0))};
+ input = convertCaffeToMIR(input);
+ auto result = createOp<ops::AvgPool2DOp>(input, window_size, strides, pad_before, pad_after,
+ false, mir::DataFormat::NHWC)
+ ->getOutput(0);
+ result = convertMIRToCaffe(result);
+ return {result};
}
std::vector<mir::Operation::Output *>
{
checkConvLikeOp(op);
- Shape window_shape = getWindowShape(op, inputs);
- Shape strides(getStrides(op));
-
- ops::PoolOp::PoolingType pool_type = ops::PoolOp::PoolingType::MAX;
- ops::PoolOp::BorderType border_type = ops::PoolOp::BorderType::EMPTY;
+ assert(inputs.size() == 1);
+ auto input = inputs[0];
- std::vector<int32_t> pad_before, pad_after;
+ const auto window_size = getWindowSize(op, inputs);
+ const auto strides = getStrides(op);
+ std::vector<std::int32_t> pad_before, pad_after;
std::tie(pad_before, pad_after) = getPadding(op);
- auto pooling = createOp<ops::PoolOp>(convertCaffeToMIR(inputs[0]), pool_type, window_shape,
- strides, pad_before, pad_after, border_type);
-
- return {convertMIRToCaffe(pooling->getOutput(0))};
+ input = convertCaffeToMIR(input);
+ auto result = createOp<ops::MaxPool2DOp>(input, window_size, strides, pad_before, pad_after,
+ mir::DataFormat::NHWC)
+ ->getOutput(0);
+ result = convertMIRToCaffe(result);
+ return {result};
}
std::vector<mir::Operation::Output *>