#include "mir/ops/Conv2DOp.h"
#include "mir/ops/DepthwiseConv2DOp.h"
#include "mir/ops/FullyConnectedOp.h"
-#include "mir/ops/InputOp.h"
#include "mir/ops/MulOp.h"
#include "mir/ops/PoolOp.h"
#include "mir/ops/ReluOp.h"
mir::Operation::Output *Caffe2OpCreator::convertCaffeToMIR(mir::Operation::Output *arg)
{
// NCHW -> NHWC
- auto transpose =
- createOp<ops::TransposeOp>("CaffeToMIR", arg, std::vector<std::size_t>{0, 2, 3, 1});
+ auto transpose = createOp<ops::TransposeOp>(arg, std::vector<std::size_t>{0, 2, 3, 1});
return transpose->getOutput(0);
}
mir::Operation::Output *Caffe2OpCreator::convertMIRToCaffe(mir::Operation::Output *arg)
{
// NHWC -> NCHW
- auto transpose =
- createOp<ops::TransposeOp>("MIRToCaffe", arg, std::vector<std::size_t>{0, 3, 1, 2});
+ auto transpose = createOp<ops::TransposeOp>(arg, std::vector<std::size_t>{0, 3, 1, 2});
return transpose->getOutput(0);
}
if (!hasArgument(op.arg(), "values"))
return {};
- return {createOp<ops::ConstantOp>("", createTensor(op))->getOutput(0)};
+ return {createOp<ops::ConstantOp>(createTensor(op))->getOutput(0)};
}
std::vector<mir::Operation::Output *>
if (getSingleArgument(op, "broadcast", 0) != 0)
{
// FIXME This only works when 'axis' == 1 and the second input is 1-D.
- auto result = createOp<ops::AddOp>("", convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
+ auto result = createOp<ops::AddOp>(convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
return {convertMIRToCaffe(result)};
}
- auto result = createOp<ops::AddOp>("", inputs[0], inputs[1])->getOutput(0);
+ auto result = createOp<ops::AddOp>(inputs[0], inputs[1])->getOutput(0);
return {result};
}
std::vector<mir::Operation::Output *>
std::vector<int32_t> pad_before, pad_after;
std::tie(pad_before, pad_after) = getPadding(op);
- auto pooling = createOp<ops::PoolOp>("Average_Pool", convertCaffeToMIR(inputs[0]), pool_type,
- window_shape, strides, pad_before, pad_after, border_type);
+ auto pooling = createOp<ops::PoolOp>(convertCaffeToMIR(inputs[0]), pool_type, window_shape,
+ strides, pad_before, pad_after, border_type);
return {convertMIRToCaffe(pooling->getOutput(0))};
}
{
// TODO handle properly kernel with layer multiplier
auto transposed_tensor = mir::transposeTensor<0, 1, 3, 2>(kernel_tensor);
- auto kernel = createOp<ops::ConstantOp>("Constant", transposed_tensor)->getOutput(0);
- result = createOp<ops::DepthwiseConv2DOp>("Depthwise_Conv2D", convertCaffeToMIR(inputs[0]),
- kernel, stride_shape, pad_before, pad_after)
+ auto kernel = createOp<ops::ConstantOp>(transposed_tensor)->getOutput(0);
+ result = createOp<ops::DepthwiseConv2DOp>(convertCaffeToMIR(inputs[0]), kernel, stride_shape,
+ pad_before, pad_after)
->getOutput(0);
}
else
if (num_groups != 1)
kernel_tensor = fixGroupedKernel(num_groups, kernel_tensor);
kernel_tensor = transposeTensor<3, 0, 1, 2>(kernel_tensor);
- auto kernel = createOp<ops::ConstantOp>("Constant", kernel_tensor)->getOutput(0);
- result = createOp<ops::Conv2DOp>("Conv2D", convertCaffeToMIR(inputs[0]), kernel, stride_shape,
- pad_before, pad_after)
+ auto kernel = createOp<ops::ConstantOp>(kernel_tensor)->getOutput(0);
+ result = createOp<ops::Conv2DOp>(convertCaffeToMIR(inputs[0]), kernel, stride_shape, pad_before,
+ pad_after)
->getOutput(0);
}
if (op.input_size() > 2)
{
- result = createOp<ops::AddOp>("", result, inputs[2])->getOutput(0);
+ result = createOp<ops::AddOp>(result, inputs[2])->getOutput(0);
}
return {convertMIRToCaffe(result)};
// `1` corresponds to the default (channels) axis.
int axis = getSingleArgument(op, "axis", 1);
- auto result = createOp<ops::ConcatOp>("Concat", inputs, axis);
+ auto result = createOp<ops::ConcatOp>(inputs, axis);
return {result->getOutput(0)};
}
// Transform input into 2-D tensor by flattening axes
Shape shape{input_shape.dim(0), input_shape.numElements() / input_shape.dim(0)};
- auto reshape = createOp<ops::ReshapeOp>("Reshape", inputs[0], shape)->getOutput(0);
- auto weights = createOp<ops::ConstantOp>("Constant", weights_tensor)->getOutput(0);
- auto result = createOp<ops::FullyConnectedOp>("Fully_Connected", reshape, weights)->getOutput(0);
- result = createOp<ops::AddOp>("", result, inputs[2])->getOutput(0);
+ auto reshape = createOp<ops::ReshapeOp>(inputs[0], shape)->getOutput(0);
+ auto weights = createOp<ops::ConstantOp>(weights_tensor)->getOutput(0);
+ auto result = createOp<ops::FullyConnectedOp>(reshape, weights)->getOutput(0);
+ result = createOp<ops::AddOp>(result, inputs[2])->getOutput(0);
return {result};
}
std::vector<int32_t> pad_before, pad_after;
std::tie(pad_before, pad_after) = getPadding(op);
- auto pooling = createOp<ops::PoolOp>("Pool", convertCaffeToMIR(inputs[0]), pool_type,
- window_shape, strides, pad_before, pad_after, border_type);
+ auto pooling = createOp<ops::PoolOp>(convertCaffeToMIR(inputs[0]), pool_type, window_shape,
+ strides, pad_before, pad_after, border_type);
return {convertMIRToCaffe(pooling->getOutput(0))};
}
if (getSingleArgument(op, "broadcast", 0) != 0)
{
// FIXME This only works when `axis` == 1 and the second input is 1-D.
- auto result = createOp<ops::MulOp>("", convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
+ auto result = createOp<ops::MulOp>(convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
return {convertMIRToCaffe(result)};
}
- auto result = createOp<ops::MulOp>("", inputs[0], inputs[1])->getOutput(0);
+ auto result = createOp<ops::MulOp>(inputs[0], inputs[1])->getOutput(0);
return {result};
}
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertRelu(const std::vector<mir::Operation::Output *> &inputs)
{
- auto relu = createOp<ops::ReluOp>("Relu", inputs[0]);
+ auto relu = createOp<ops::ReluOp>(inputs[0]);
return {relu->getOutput(0)};
}
scales[1] = getSingleArgument(op, "height_scale", 1.0f);
scales[2] = getSingleArgument(op, "width_scale", 1.0f);
scales[3] = 1;
- auto resize = createOp<ops::ResizeOp>("ResizeNearest", convertCaffeToMIR(inputs[0]),
+ auto resize = createOp<ops::ResizeOp>(convertCaffeToMIR(inputs[0]),
ops::ResizeOp::ResizeMethod::nearestNeighbor, scales);
return {convertMIRToCaffe(resize->getOutput(0))};
}
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertSigmoid(const std::vector<mir::Operation::Output *> &inputs)
{
- auto result = createOp<ops::SigmoidOp>("Sigmoid", inputs[0]);
+ auto result = createOp<ops::SigmoidOp>(inputs[0]);
return {result->getOutput(0)};
}
const ::caffe2::OperatorDef &op)
{
int axis = getSingleArgument(op, "axis", 1);
- auto softmax = createOp<ops::SoftmaxOp>("Softmax", inputs[0], axis);
+ auto softmax = createOp<ops::SoftmaxOp>(inputs[0], axis);
return {softmax->getOutput(0)};
}
for (auto &idx : ShapeRange(bias_data.getShape()))
bias_data.at(idx) *= -1;
- auto mean = createOp<ops::ConstantOp>("Constant", mean_tensor)->getOutput(0);
- auto result = createOp<ops::AddOp>("", convertCaffeToMIR(inputs[0]), mean)->getOutput(0);
+ auto mean = createOp<ops::ConstantOp>(mean_tensor)->getOutput(0);
+ auto result = createOp<ops::AddOp>(convertCaffeToMIR(inputs[0]), mean)->getOutput(0);
// res2 = res1 * scale / (var + epsilon)
Tensor<float> multiplier(scale_tensor);
for (auto &idx : ShapeRange(scale_tensor.getShape()))
multiplier.at(idx) /= std::sqrt(*reinterpret_cast<float *>(var_tensor.at(idx)) + eps);
- auto scale = createOp<ops::ConstantOp>("Constant", scale_tensor)->getOutput(0);
- result = createOp<ops::MulOp>("", result, scale)->getOutput(0);
+ auto scale = createOp<ops::ConstantOp>(scale_tensor)->getOutput(0);
+ result = createOp<ops::MulOp>(result, scale)->getOutput(0);
// overall_res = res2 + bias
- auto bias = createOp<ops::ConstantOp>("Constant", bias_tensor)->getOutput(0);
- result = createOp<ops::AddOp>("", result, bias)->getOutput(0);
+ auto bias = createOp<ops::ConstantOp>(bias_tensor)->getOutput(0);
+ result = createOp<ops::AddOp>(result, bias)->getOutput(0);
return {convertMIRToCaffe(result)};
}
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertSum(const std::vector<mir::Operation::Output *> &inputs)
{
- auto result = createOp<ops::AddOp>("", inputs[0], inputs[1])->getOutput(0);
+ auto result = createOp<ops::AddOp>(inputs[0], inputs[1])->getOutput(0);
for (int i = 2; i < static_cast<int>(inputs.size()); ++i)
{
- result = createOp<ops::AddOp>("", result, inputs[i])->getOutput(0);
+ result = createOp<ops::AddOp>(result, inputs[i])->getOutput(0);
}
return {result};
}
float min = getSingleArgument(op, "min", float(0));
assert(max > 0.0 && min == 0.0 && "Support only if clip is CappedRelu");
- auto cap_relu = createOp<ops::CappedReluOp>("Capped_Relu", inputs[0], max);
+ auto cap_relu = createOp<ops::CappedReluOp>(inputs[0], max);
return {cap_relu->getOutput(0)};
}
}
Shape out_shape(shape_vec);
- auto reshape = createOp<ops::ReshapeOp>("Reshape", inputs[0], out_shape);
+ auto reshape = createOp<ops::ReshapeOp>(inputs[0], out_shape);
return {reshape->getOutput(0)};
}
-Operation::Output *Caffe2OpCreator::createInput(const std::string &name, const mir::Shape &shape)
-{
- return _graph->create<ops::InputOp>(name, shape)->getOutput(0);
-}
-
} // namespace mir_caffe2