diff --git a/common/daq.fbs b/common/daq.fbs index 1244de7..95158dc 100644 --- a/common/daq.fbs +++ b/common/daq.fbs @@ -7,7 +7,7 @@ enum DataType:byte { Float32 = 0, Int8, Int32, Float16, Bool8, enum FuseCode:byte { None = 0, Relu, Relu1, Relu6 } enum LayerType:byte { Conv2D = 0, AvePool, MaxPool, Relu, Softmax, FC, Add, Concat, DepthwiseConv2D, BatchToSpace, SpaceToBatch, StridedSlice, Mul, AddScalar, MulScalar, - Dequantize, LRN} + Dequantize, LRN, Tanh, Floor} table Tensor { data_type:DataType; @@ -164,6 +164,16 @@ table LRN { output:string; } +table Tanh { + input:string; + output:string; +} + +table Floor { + input:string; + output:string; +} + table Layer { type:LayerType; conv2d_param:Conv2D; @@ -183,6 +193,8 @@ table Layer { mul_scalar_param:MulScalar; dequantize_param:Dequantize; lrn_param:LRN; + tanh_param:Tanh; + floor_param:Floor; } table Model { diff --git a/dnnlibrary/ModelBuilderImpl.cpp b/dnnlibrary/ModelBuilderImpl.cpp index bb0d69d..febaf81 100644 --- a/dnnlibrary/ModelBuilderImpl.cpp +++ b/dnnlibrary/ModelBuilderImpl.cpp @@ -487,6 +487,40 @@ ModelBuilder::Index ModelBuilder::AddLRN(const std::string &input, return output_idx; } #endif // __ANDROID_API__ >= 27 +#if __ANDROID_API__ >= 27 +ModelBuilder::Index ModelBuilder::AddTanh(const std::string &input, + const std::string &output) { + IndexSeq input_indexes; + imm_blob_inputs_.insert(input); + const auto input_idx = operand_indexes_.at(input); + input_indexes.push_back(input_idx); + shaper_.Identity(input, output); + const OperandType operand_type = + GetOperandType(operand_types_.at(input).type, shaper_[output]); + const auto output_idx = + AddOperation(ANEURALNETWORKS_TANH, input_indexes, operand_type)[0]; + RegisterOperand(output, output_idx, operand_type); + imm_blob_outputs_.insert(output); + return output_idx; +} +#endif // __ANDROID_API__ >= 27 +#if __ANDROID_API__ >= 27 +ModelBuilder::Index ModelBuilder::AddFloor(const std::string &input, + const std::string &output) { + IndexSeq input_indexes; + imm_blob_inputs_.insert(input); + const auto input_idx = operand_indexes_.at(input); + input_indexes.push_back(input_idx); + shaper_.Identity(input, output); + const OperandType operand_type = + GetOperandType(operand_types_.at(input).type, shaper_[output]); + const auto output_idx = + AddOperation(ANEURALNETWORKS_FLOOR, input_indexes, operand_type)[0]; + RegisterOperand(output, output_idx, operand_type); + imm_blob_outputs_.insert(output); + return output_idx; +} +#endif // __ANDROID_API__ >= 27 // ModelBuilder auto generated methods end // Methods for backward compatibility diff --git a/include/common/daq_generated.h b/include/common/daq_generated.h index c665a9c..c866f71 100644 --- a/include/common/daq_generated.h +++ b/include/common/daq_generated.h @@ -48,6 +48,10 @@ struct Dequantize; struct LRN; +struct Tanh; + +struct Floor; + struct Layer; struct Model; @@ -144,78 +148,68 @@ inline const char *EnumNameFuseCode(FuseCode e) { } enum class LayerType : int8_t { - Conv2D = 0, - AvePool = 1, - MaxPool = 2, - Relu = 3, - Softmax = 4, - FC = 5, - Add = 6, - Concat = 7, - DepthwiseConv2D = 8, - BatchToSpace = 9, - SpaceToBatch = 10, - StridedSlice = 11, - Mul = 12, - AddScalar = 13, - MulScalar = 14, - Dequantize = 15, - LRN = 16, - MIN = Conv2D, - MAX = LRN + Conv2D = 0, + AvePool = 1, + MaxPool = 2, + Relu = 3, + Softmax = 4, + FC = 5, + Add = 6, + Concat = 7, + DepthwiseConv2D = 8, + BatchToSpace = 9, + SpaceToBatch = 10, + StridedSlice = 11, + Mul = 12, + AddScalar = 13, + MulScalar = 14, + Dequantize = 15, + LRN = 16, + Tanh = 17, + Floor = 18, + MIN = Conv2D, + MAX = Floor }; -inline const LayerType (&EnumValuesLayerType())[17] { - static const LayerType values[] = { - LayerType::Conv2D, - LayerType::AvePool, - LayerType::MaxPool, - LayerType::Relu, - LayerType::Softmax, - LayerType::FC, - LayerType::Add, - LayerType::Concat, - LayerType::DepthwiseConv2D, - LayerType::BatchToSpace, - LayerType::SpaceToBatch, - LayerType::StridedSlice, - LayerType::Mul, - LayerType::AddScalar, - LayerType::MulScalar, - LayerType::Dequantize, - LayerType::LRN - }; - return values; +inline const LayerType (&EnumValuesLayerType())[19] { + static const LayerType values[] = {LayerType::Conv2D, + LayerType::AvePool, + LayerType::MaxPool, + LayerType::Relu, + LayerType::Softmax, + LayerType::FC, + LayerType::Add, + LayerType::Concat, + LayerType::DepthwiseConv2D, + LayerType::BatchToSpace, + LayerType::SpaceToBatch, + LayerType::StridedSlice, + LayerType::Mul, + LayerType::AddScalar, + LayerType::MulScalar, + LayerType::Dequantize, + LayerType::LRN, + LayerType::Tanh, + LayerType::Floor}; + return values; } inline const char * const *EnumNamesLayerType() { - static const char * const names[] = { - "Conv2D", - "AvePool", - "MaxPool", - "Relu", - "Softmax", - "FC", - "Add", - "Concat", - "DepthwiseConv2D", - "BatchToSpace", - "SpaceToBatch", - "StridedSlice", - "Mul", - "AddScalar", - "MulScalar", - "Dequantize", - "LRN", - nullptr - }; - return names; + static const char *const names[] = { + "Conv2D", "AvePool", "MaxPool", + "Relu", "Softmax", "FC", + "Add", "Concat", "DepthwiseConv2D", + "BatchToSpace", "SpaceToBatch", "StridedSlice", + "Mul", "AddScalar", "MulScalar", + "Dequantize", "LRN", "Tanh", + "Floor", nullptr}; + return names; } inline const char *EnumNameLayerType(LayerType e) { - if (e < LayerType::Conv2D || e > LayerType::LRN) return ""; - const size_t index = static_cast(e); - return EnumNamesLayerType()[index]; + if (e < LayerType::Conv2D || e > LayerType::Floor) return ""; + const size_t index = static_cast(e); + return EnumNamesLayerType()[index]; } struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { @@ -2184,29 +2178,145 @@ inline flatbuffers::Offset CreateLRNDirect( output__); } +struct Tanh FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_INPUT = 4, + VT_OUTPUT = 6 + }; + const flatbuffers::String *input() const { + return GetPointer(VT_INPUT); + } + const flatbuffers::String *output() const { + return GetPointer(VT_OUTPUT); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_INPUT) && + verifier.VerifyString(input()) && + VerifyOffset(verifier, VT_OUTPUT) && + verifier.VerifyString(output()) && verifier.EndTable(); + } +}; + +struct TanhBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_input(flatbuffers::Offset input) { + fbb_.AddOffset(Tanh::VT_INPUT, input); + } + void add_output(flatbuffers::Offset output) { + fbb_.AddOffset(Tanh::VT_OUTPUT, output); + } + explicit TanhBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + TanhBuilder &operator=(const TanhBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTanh( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset input = 0, + flatbuffers::Offset output = 0) { + TanhBuilder builder_(_fbb); + builder_.add_output(output); + builder_.add_input(input); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateTanhDirect( + flatbuffers::FlatBufferBuilder &_fbb, const char *input = nullptr, + const char *output = nullptr) { + auto input__ = input ? _fbb.CreateString(input) : 0; + auto output__ = output ? _fbb.CreateString(output) : 0; + return DNN::CreateTanh(_fbb, input__, output__); +} + +struct Floor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_INPUT = 4, + VT_OUTPUT = 6 + }; + const flatbuffers::String *input() const { + return GetPointer(VT_INPUT); + } + const flatbuffers::String *output() const { + return GetPointer(VT_OUTPUT); + } + bool Verify(flatbuffers::Verifier &verifier) const { + return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_INPUT) && + verifier.VerifyString(input()) && + VerifyOffset(verifier, VT_OUTPUT) && + verifier.VerifyString(output()) && verifier.EndTable(); + } +}; + +struct FloorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_input(flatbuffers::Offset input) { + fbb_.AddOffset(Floor::VT_INPUT, input); + } + void add_output(flatbuffers::Offset output) { + fbb_.AddOffset(Floor::VT_OUTPUT, output); + } + explicit FloorBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { + start_ = fbb_.StartTable(); + } + FloorBuilder &operator=(const FloorBuilder &); + flatbuffers::Offset Finish() { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFloor( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset input = 0, + flatbuffers::Offset output = 0) { + FloorBuilder builder_(_fbb); + builder_.add_output(output); + builder_.add_input(input); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateFloorDirect( + flatbuffers::FlatBufferBuilder &_fbb, const char *input = nullptr, + const char *output = nullptr) { + auto input__ = input ? _fbb.CreateString(input) : 0; + auto output__ = output ? _fbb.CreateString(output) : 0; + return DNN::CreateFloor(_fbb, input__, output__); +} + struct Layer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_TYPE = 4, - VT_CONV2D_PARAM = 6, - VT_AVEPOOL_PARAM = 8, - VT_MAXPOOL_PARAM = 10, - VT_RELU_PARAM = 12, - VT_SOFTMAX_PARAM = 14, - VT_FC_PARAM = 16, - VT_ADD_PARAM = 18, - VT_CONCAT_PARAM = 20, - VT_DEPTHWISE_CONV2D_PARAM = 22, - VT_BATCH_TO_SPACE_PARAM = 24, - VT_SPACE_TO_BATCH_PARAM = 26, - VT_STRIDED_SLICE_PARAM = 28, - VT_MUL_PARAM = 30, - VT_ADD_SCALAR_PARAM = 32, - VT_MUL_SCALAR_PARAM = 34, - VT_DEQUANTIZE_PARAM = 36, - VT_LRN_PARAM = 38 - }; - LayerType type() const { - return static_cast(GetField(VT_TYPE, 0)); + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TYPE = 4, + VT_CONV2D_PARAM = 6, + VT_AVEPOOL_PARAM = 8, + VT_MAXPOOL_PARAM = 10, + VT_RELU_PARAM = 12, + VT_SOFTMAX_PARAM = 14, + VT_FC_PARAM = 16, + VT_ADD_PARAM = 18, + VT_CONCAT_PARAM = 20, + VT_DEPTHWISE_CONV2D_PARAM = 22, + VT_BATCH_TO_SPACE_PARAM = 24, + VT_SPACE_TO_BATCH_PARAM = 26, + VT_STRIDED_SLICE_PARAM = 28, + VT_MUL_PARAM = 30, + VT_ADD_SCALAR_PARAM = 32, + VT_MUL_SCALAR_PARAM = 34, + VT_DEQUANTIZE_PARAM = 36, + VT_LRN_PARAM = 38, + VT_TANH_PARAM = 40, + VT_FLOOR_PARAM = 42 + }; + LayerType type() const { + return static_cast(GetField(VT_TYPE, 0)); } const Conv2D *conv2d_param() const { return GetPointer(VT_CONV2D_PARAM); @@ -2259,44 +2369,53 @@ struct Layer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const LRN *lrn_param() const { return GetPointer(VT_LRN_PARAM); } + const Tanh *tanh_param() const { + return GetPointer(VT_TANH_PARAM); + } + const Floor *floor_param() const { + return GetPointer(VT_FLOOR_PARAM); + } bool Verify(flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_TYPE) && - VerifyOffset(verifier, VT_CONV2D_PARAM) && - verifier.VerifyTable(conv2d_param()) && - VerifyOffset(verifier, VT_AVEPOOL_PARAM) && - verifier.VerifyTable(avepool_param()) && - VerifyOffset(verifier, VT_MAXPOOL_PARAM) && - verifier.VerifyTable(maxpool_param()) && - VerifyOffset(verifier, VT_RELU_PARAM) && - verifier.VerifyTable(relu_param()) && - VerifyOffset(verifier, VT_SOFTMAX_PARAM) && - verifier.VerifyTable(softmax_param()) && - VerifyOffset(verifier, VT_FC_PARAM) && - verifier.VerifyTable(fc_param()) && - VerifyOffset(verifier, VT_ADD_PARAM) && - verifier.VerifyTable(add_param()) && - VerifyOffset(verifier, VT_CONCAT_PARAM) && - verifier.VerifyTable(concat_param()) && - VerifyOffset(verifier, VT_DEPTHWISE_CONV2D_PARAM) && - verifier.VerifyTable(depthwise_conv2d_param()) && - VerifyOffset(verifier, VT_BATCH_TO_SPACE_PARAM) && - verifier.VerifyTable(batch_to_space_param()) && - VerifyOffset(verifier, VT_SPACE_TO_BATCH_PARAM) && - verifier.VerifyTable(space_to_batch_param()) && - VerifyOffset(verifier, VT_STRIDED_SLICE_PARAM) && - verifier.VerifyTable(strided_slice_param()) && - VerifyOffset(verifier, VT_MUL_PARAM) && - verifier.VerifyTable(mul_param()) && - VerifyOffset(verifier, VT_ADD_SCALAR_PARAM) && - verifier.VerifyTable(add_scalar_param()) && - VerifyOffset(verifier, VT_MUL_SCALAR_PARAM) && - verifier.VerifyTable(mul_scalar_param()) && - VerifyOffset(verifier, VT_DEQUANTIZE_PARAM) && - verifier.VerifyTable(dequantize_param()) && - VerifyOffset(verifier, VT_LRN_PARAM) && - verifier.VerifyTable(lrn_param()) && - verifier.EndTable(); + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_TYPE) && + VerifyOffset(verifier, VT_CONV2D_PARAM) && + verifier.VerifyTable(conv2d_param()) && + VerifyOffset(verifier, VT_AVEPOOL_PARAM) && + verifier.VerifyTable(avepool_param()) && + VerifyOffset(verifier, VT_MAXPOOL_PARAM) && + verifier.VerifyTable(maxpool_param()) && + VerifyOffset(verifier, VT_RELU_PARAM) && + verifier.VerifyTable(relu_param()) && + VerifyOffset(verifier, VT_SOFTMAX_PARAM) && + verifier.VerifyTable(softmax_param()) && + VerifyOffset(verifier, VT_FC_PARAM) && + verifier.VerifyTable(fc_param()) && + VerifyOffset(verifier, VT_ADD_PARAM) && + verifier.VerifyTable(add_param()) && + VerifyOffset(verifier, VT_CONCAT_PARAM) && + verifier.VerifyTable(concat_param()) && + VerifyOffset(verifier, VT_DEPTHWISE_CONV2D_PARAM) && + verifier.VerifyTable(depthwise_conv2d_param()) && + VerifyOffset(verifier, VT_BATCH_TO_SPACE_PARAM) && + verifier.VerifyTable(batch_to_space_param()) && + VerifyOffset(verifier, VT_SPACE_TO_BATCH_PARAM) && + verifier.VerifyTable(space_to_batch_param()) && + VerifyOffset(verifier, VT_STRIDED_SLICE_PARAM) && + verifier.VerifyTable(strided_slice_param()) && + VerifyOffset(verifier, VT_MUL_PARAM) && + verifier.VerifyTable(mul_param()) && + VerifyOffset(verifier, VT_ADD_SCALAR_PARAM) && + verifier.VerifyTable(add_scalar_param()) && + VerifyOffset(verifier, VT_MUL_SCALAR_PARAM) && + verifier.VerifyTable(mul_scalar_param()) && + VerifyOffset(verifier, VT_DEQUANTIZE_PARAM) && + verifier.VerifyTable(dequantize_param()) && + VerifyOffset(verifier, VT_LRN_PARAM) && + verifier.VerifyTable(lrn_param()) && + VerifyOffset(verifier, VT_TANH_PARAM) && + verifier.VerifyTable(tanh_param()) && + VerifyOffset(verifier, VT_FLOOR_PARAM) && + verifier.VerifyTable(floor_param()) && verifier.EndTable(); } }; @@ -2357,6 +2476,12 @@ struct LayerBuilder { void add_lrn_param(flatbuffers::Offset lrn_param) { fbb_.AddOffset(Layer::VT_LRN_PARAM, lrn_param); } + void add_tanh_param(flatbuffers::Offset tanh_param) { + fbb_.AddOffset(Layer::VT_TANH_PARAM, tanh_param); + } + void add_floor_param(flatbuffers::Offset floor_param) { + fbb_.AddOffset(Layer::VT_FLOOR_PARAM, floor_param); + } explicit LayerBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -2370,8 +2495,7 @@ struct LayerBuilder { }; inline flatbuffers::Offset CreateLayer( - flatbuffers::FlatBufferBuilder &_fbb, - LayerType type = LayerType::Conv2D, + flatbuffers::FlatBufferBuilder &_fbb, LayerType type = LayerType::Conv2D, flatbuffers::Offset conv2d_param = 0, flatbuffers::Offset avepool_param = 0, flatbuffers::Offset maxpool_param = 0, @@ -2388,27 +2512,31 @@ inline flatbuffers::Offset CreateLayer( flatbuffers::Offset add_scalar_param = 0, flatbuffers::Offset mul_scalar_param = 0, flatbuffers::Offset dequantize_param = 0, - flatbuffers::Offset lrn_param = 0) { - LayerBuilder builder_(_fbb); - builder_.add_lrn_param(lrn_param); - builder_.add_dequantize_param(dequantize_param); - builder_.add_mul_scalar_param(mul_scalar_param); - builder_.add_add_scalar_param(add_scalar_param); - builder_.add_mul_param(mul_param); - builder_.add_strided_slice_param(strided_slice_param); - builder_.add_space_to_batch_param(space_to_batch_param); - builder_.add_batch_to_space_param(batch_to_space_param); - builder_.add_depthwise_conv2d_param(depthwise_conv2d_param); - builder_.add_concat_param(concat_param); - builder_.add_add_param(add_param); - builder_.add_fc_param(fc_param); - builder_.add_softmax_param(softmax_param); - builder_.add_relu_param(relu_param); - builder_.add_maxpool_param(maxpool_param); - builder_.add_avepool_param(avepool_param); - builder_.add_conv2d_param(conv2d_param); - builder_.add_type(type); - return builder_.Finish(); + flatbuffers::Offset lrn_param = 0, + flatbuffers::Offset tanh_param = 0, + flatbuffers::Offset floor_param = 0) { + LayerBuilder builder_(_fbb); + builder_.add_floor_param(floor_param); + builder_.add_tanh_param(tanh_param); + builder_.add_lrn_param(lrn_param); + builder_.add_dequantize_param(dequantize_param); + builder_.add_mul_scalar_param(mul_scalar_param); + builder_.add_add_scalar_param(add_scalar_param); + builder_.add_mul_param(mul_param); + builder_.add_strided_slice_param(strided_slice_param); + builder_.add_space_to_batch_param(space_to_batch_param); + builder_.add_batch_to_space_param(batch_to_space_param); + builder_.add_depthwise_conv2d_param(depthwise_conv2d_param); + builder_.add_concat_param(concat_param); + builder_.add_add_param(add_param); + builder_.add_fc_param(fc_param); + builder_.add_softmax_param(softmax_param); + builder_.add_relu_param(relu_param); + builder_.add_maxpool_param(maxpool_param); + builder_.add_avepool_param(avepool_param); + builder_.add_conv2d_param(conv2d_param); + builder_.add_type(type); + return builder_.Finish(); } struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { diff --git a/include/dnnlibrary/ModelBuilder.h b/include/dnnlibrary/ModelBuilder.h index 7de9642..2993bc0 100644 --- a/include/dnnlibrary/ModelBuilder.h +++ b/include/dnnlibrary/ModelBuilder.h @@ -212,6 +212,14 @@ class ModelBuilder { ModelBuilder::Index AddLRN(const std::string &input, int32_t radius, float bias, float alpha, float beta, const std::string &output); +#endif // __ANDROID_API__ >= 27 +#if __ANDROID_API__ >= 27 + ModelBuilder::Index AddTanh(const std::string &input, + const std::string &output); +#endif // __ANDROID_API__ >= 27 +#if __ANDROID_API__ >= 27 + ModelBuilder::Index AddFloor(const std::string &input, + const std::string &output); #endif // __ANDROID_API__ >= 27 // ModelBuilder auto generated methods end Index AddDepthWiseConv( diff --git a/include/tools/onnx2daq/OnnxConverter.h b/include/tools/onnx2daq/OnnxConverter.h index d72ea1c..7b3d9cb 100644 --- a/include/tools/onnx2daq/OnnxConverter.h +++ b/include/tools/onnx2daq/OnnxConverter.h @@ -158,6 +158,8 @@ class OnnxConverter { const std::string &output); void AddLayerLRN(const std::string &input, int32_t radius, float bias, float alpha, float beta, const std::string &output); + void AddLayerTanh(const std::string &input, const std::string &output); + void AddLayerFloor(const std::string &input, const std::string &output); // OnnxConverter auto generated methods end /** diff --git a/ops.yml b/ops.yml index 32d7cd4..01af043 100644 --- a/ops.yml +++ b/ops.yml @@ -417,3 +417,11 @@ shaper: Identity pos: 16 api: 27 +- + name: Tanh + shaper: Identity + api: 27 +- + name: Floor + shaper: Identity + api: 27 diff --git a/tools/onnx2daq/OnnxConverter.cpp b/tools/onnx2daq/OnnxConverter.cpp index d17a4df..80be976 100644 --- a/tools/onnx2daq/OnnxConverter.cpp +++ b/tools/onnx2daq/OnnxConverter.cpp @@ -849,6 +849,52 @@ void OnnxConverter::AddLayerLRN(const std::string &input, int32_t radius, layers_.push_back(layer); } +void OnnxConverter::AddLayerTanh(const std::string &input, + const std::string &output) { + { + const auto name = input; + + if (onnx_tensors_.has(name)) { + const auto &onnx_tensor = onnx_tensors_.at(name); + const auto new_tensor = OnnxToNnapiAxes0231(onnx_tensor); + shaper_.AddShape(name, new_tensor.shape); + nnapi_tensors_[name] = new_tensor; + CreateTensorFb(name, new_tensor); + } + } + + shaper_.Identity(m(input), output); + const auto param = + DNN::CreateTanhDirect(builder_, m(input).c_str(), output.c_str()); + const auto layer = + DNN::CreateLayer(builder_, DNN::LayerType::Tanh, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, param); + layers_.push_back(layer); +} + +void OnnxConverter::AddLayerFloor(const std::string &input, + const std::string &output) { + { + const auto name = input; + + if (onnx_tensors_.has(name)) { + const auto &onnx_tensor = onnx_tensors_.at(name); + const auto new_tensor = OnnxToNnapiAxes0231(onnx_tensor); + shaper_.AddShape(name, new_tensor.shape); + nnapi_tensors_[name] = new_tensor; + CreateTensorFb(name, new_tensor); + } + } + + shaper_.Identity(m(input), output); + const auto param = + DNN::CreateFloorDirect(builder_, m(input).c_str(), output.c_str()); + const auto layer = + DNN::CreateLayer(builder_, DNN::LayerType::Floor, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, param); + layers_.push_back(layer); +} + // OnnxConverter auto generated methods end void OnnxConverter::SetIdentity(css &input_name, css &output_name) { @@ -1079,7 +1125,8 @@ std::pair OnnxConverter::IsNodeSupported( "Softmax", "Concat", "Dropout", "BatchNormalization", "Reshape", "LRN", - "Identity"}; + "Identity", "Tanh", + "Floor"}; if (std::find(supported_types.begin(), supported_types.end(), op) == supported_types.end()) { return {false, "Unsupported operator " + op}; @@ -1514,6 +1561,18 @@ void OnnxConverter::Convert(const ONNX_NAMESPACE::ModelProto &model_proto, AddLayerLRN(node.input(0), radius, bias, alpha, beta, node.output(0)); VLOG(5) << "Converting LRN completed"; + } else if (op == "Tanh") { + VLOG(5) << "Start converting Tanh"; + const auto input_name = m(node.input(0)); + const auto output_name = m(node.output(0)); + AddLayerTanh(input_name, output_name); + VLOG(5) << "Converting Tanh completed"; + } else if (op == "Floor") { + VLOG(5) << "Start converting Floor"; + const auto input_name = m(node.input(0)); + const auto output_name = m(node.output(0)); + AddLayerFloor(input_name, output_name); + VLOG(5) << "Converting Floor completed"; } else { throw std::invalid_argument("Unsupported operator " + op); }