#include "tflite_op_creator.h"
#include "schema_generated.h"
-#include "mir/ops/BiasAddOp.h"
#include "mir/ops/CappedReluOp.h"
#include "mir/ops/ConcatOp.h"
#include "mir/ops/ConstantOp.h"
calculatePadding(opts->padding(), input_shape, window_shape, strides, padding_before,
padding_after);
- auto result = createOp<ops::Conv2DOp>(input, kernel, strides, padding_before, padding_after);
- result = createOp<ops::BiasAddOp>(result->getOutput(0), bias);
- return {addFusedActivation(result->getOutput(0), opts->fused_activation_function())};
+ auto result =
+ createOp<ops::Conv2DOp>(input, kernel, strides, padding_before, padding_after)->getOutput(0);
+ result = createAdd(result, bias);
+ return {addFusedActivation(result, opts->fused_activation_function())};
}
void TFLiteOpCreator::checkDepthwiseConv2D(const DepthwiseConv2DOptions *opts,
padding_after);
auto result =
- createOp<ops::DepthwiseConv2DOp>(input, kernel, strides, padding_before, padding_after);
- result = createOp<ops::BiasAddOp>(result->getOutput(0), bias);
- return {addFusedActivation(result->getOutput(0), opts->fused_activation_function())};
+ createOp<ops::DepthwiseConv2DOp>(input, kernel, strides, padding_before, padding_after)
+ ->getOutput(0);
+ result = createAdd(result, bias);
+ return {addFusedActivation(result, opts->fused_activation_function())};
}
void TFLiteOpCreator::checkConcatenation(const ConcatenationOptions *opts,
std::vector<mir::Operation::Output *>
TFLiteOpCreator::convertSquaredDifference(const std::vector<mir::Operation::Output *> &inputs)
{
- auto result = createOp<ops::ElementwiseOp>(inputs, ops::ElementwiseOp::OpType::sub);
- result = createOp<ops::ElementwiseOp>(
- std::vector<mir::Operation::Output *>{result->getOutput(0), result->getOutput(0)},
- ops::ElementwiseOp::OpType::mul);
- return {result->getOutput(0)};
+ auto result = createOp<ops::ElementwiseOp>(inputs, ops::ElementwiseOp::OpType::sub)->getOutput(0);
+ result = createMul(result, result);
+ return {result};
}
std::vector<mir::Operation::Output *>
const auto &weights_tensor = mir::transposeTensor<1, 0>(extractTensor(weights));
weights = createOp<ops::ConstantOp>(weights_tensor)->getOutput(0);
- auto result = createOp<ops::FullyConnectedOp>(flatten->getOutput(0), weights);
- result = createOp<ops::BiasAddOp>(result->getOutput(0), bias);
- return {addFusedActivation(result->getOutput(0), opts->fused_activation_function())};
+ auto result = createOp<ops::FullyConnectedOp>(flatten->getOutput(0), weights)->getOutput(0);
+ result = createAdd(result, bias);
+ return {addFusedActivation(result, opts->fused_activation_function())};
}
void TFLiteOpCreator::checkActivationType(ActivationFunctionType activation_type,
}
}
+mir::Operation::Output *TFLiteOpCreator::createAdd(mir::Operation::Output *arg1,
+ mir::Operation::Output *arg2)
+{
+ std::vector<mir::Operation::Output *> inputs{arg1, arg2};
+ auto op = createOp<ops::ElementwiseOp>(inputs, ops::ElementwiseOp::OpType::add);
+ return op->getOutput(0);
+}
+
+mir::Operation::Output *TFLiteOpCreator::createMul(mir::Operation::Output *arg1,
+ mir::Operation::Output *arg2)
+{
+ std::vector<mir::Operation::Output *> inputs{arg1, arg2};
+ auto op = createOp<ops::ElementwiseOp>(inputs, ops::ElementwiseOp::OpType::mul);
+ return op->getOutput(0);
+}
+
std::vector<mir::Operation::Output *>
TFLiteOpCreator::convertSqueeze(const ::tflite::SqueezeOptions *opts,
const std::vector<mir::Operation::Output *> &inputs)