diff options
Diffstat (limited to 'compiler/tflchef')
-rw-r--r-- | compiler/tflchef/core/src/ModelChef.cpp | 45 | ||||
-rw-r--r-- | compiler/tflchef/core/src/Op/NonMaxSuppressionV5.cpp | 30 | ||||
-rw-r--r-- | compiler/tflchef/core/src/Op/NonMaxSuppressionV5.h | 52 | ||||
-rw-r--r-- | compiler/tflchef/core/src/OpChef.def | 1 | ||||
-rw-r--r-- | compiler/tflchef/core/src/OpChefs.h | 1 | ||||
-rw-r--r-- | compiler/tflchef/proto/tflchef.proto | 6 | ||||
-rw-r--r-- | compiler/tflchef/tflite/CMakeLists.txt | 1 | ||||
-rw-r--r-- | compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.cpp | 59 | ||||
-rw-r--r-- | compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.h | 39 | ||||
-rw-r--r-- | compiler/tflchef/tflite/src/TFliteImport.h | 65 | ||||
-rw-r--r-- | compiler/tflchef/tflite/src/TFliteOpChefs.h | 1 | ||||
-rw-r--r-- | compiler/tflchef/tflite/src/TFliteOpRegistry.h | 1 |
12 files changed, 194 insertions, 107 deletions
diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index 692ce48c1..a4b435dfa 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -26,6 +26,7 @@ #include "OpChefs.h" #include <souschef/Dataset.h> +#include <souschef/Dims.h> #include "Log.h" @@ -41,52 +42,8 @@ #include <sstream> #include <stdexcept> -namespace -{ - using namespace souschef; -template <typename T> std::vector<T> as_vector(const ::google::protobuf::RepeatedPtrField<T> &field) -{ - std::vector<T> res; - for (const auto &elem : field) - { - res.emplace_back(elem); - } - return res; -} - -template <typename T> Dataset<T> as_dataset(const ::google::protobuf::RepeatedPtrField<T> &field) -{ - return Dataset<T>(as_vector<T>(field)); -} - -} // namespace - -namespace -{ - -template <typename T> using Dims = std::vector<T>; - -Dims<int32_t> as_dims(const tflchef::TensorShape &shape) -{ - std::vector<int32_t> res; - - for (auto &dim : shape.dim()) - { - res.emplace_back(static_cast<int32_t>(dim)); - } - - return res; -} - -int32_t element_count(const Dims<int32_t> &dims) -{ - return std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int32_t>()); -} - -} // namespace - namespace { diff --git a/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.cpp b/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.cpp new file mode 100644 index 000000000..500aa467f --- /dev/null +++ b/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 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 "NonMaxSuppressionV5.h" + +flatbuffers::Offset<void> NonMaxSuppressionV5Chef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::NonMaxSuppressionV5OptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> +NonMaxSuppressionV5ChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new NonMaxSuppressionV5Chef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.h b/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.h new file mode 100644 index 000000000..a3c8b6009 --- /dev/null +++ b/compiler/tflchef/core/src/Op/NonMaxSuppressionV5.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 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 __OP_NON_MAX_SUPPRESSION_V5_H__ +#define __OP_NON_MAX_SUPPRESSION_V5_H__ + +#include "OpChef.h" + +class NonMaxSuppressionV5Chef final : public OpChef +{ +public: + explicit NonMaxSuppressionV5Chef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override + { + return tflite::BuiltinOperator_NON_MAX_SUPPRESSION_V5; + } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_NonMaxSuppressionV5Options; + } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct NonMaxSuppressionV5ChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_NON_MAX_SUPPRESSION_V5_H__ diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index 244186265..6b242e811 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -56,6 +56,7 @@ OP_CHEF(MirrorPad, MirrorPadChefFactory) OP_CHEF(Mul, MulChefFactory) OP_CHEF(Neg, NegChefFactory) OP_CHEF(NonMaxSuppressionV4, NonMaxSuppressionV4ChefFactory) +OP_CHEF(NonMaxSuppressionV5, NonMaxSuppressionV5ChefFactory) OP_CHEF(NotEqual, NotEqualChefFactory) OP_CHEF(OneHot, OneHotChefFactory) OP_CHEF(Pack, PackChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index 5b2e89bd9..7637b1c69 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -69,6 +69,7 @@ #include "Op/Mul.h" #include "Op/Neg.h" #include "Op/NonMaxSuppressionV4.h" +#include "Op/NonMaxSuppressionV5.h" #include "Op/NotEqual.h" #include "Op/OneHot.h" #include "Op/Pack.h" diff --git a/compiler/tflchef/proto/tflchef.proto b/compiler/tflchef/proto/tflchef.proto index 70b966ec3..9909d517a 100644 --- a/compiler/tflchef/proto/tflchef.proto +++ b/compiler/tflchef/proto/tflchef.proto @@ -371,6 +371,10 @@ message NonMaxSuppressionV4Options { // None } +message NonMaxSuppressionV5Options { + // None +} + message NotEqualOptions { // None } @@ -544,7 +548,7 @@ message Operation { // HardSwishOptions 196 optional DepthToSpaceOptions depth_to_space_options = 197; optional NonMaxSuppressionV4Options non_max_suppression_v4_options = 198; - // NonMaxSuppressionV5Options 199 + optional NonMaxSuppressionV5Options non_max_suppression_v5_options = 199; optional ScatterNdOptions scatter_nd_options = 200; optional NotEqualOptions notequal_options = 201; optional ExpandDimsOptions expand_dims_options = 202; diff --git a/compiler/tflchef/tflite/CMakeLists.txt b/compiler/tflchef/tflite/CMakeLists.txt index 645c16144..83127cb3e 100644 --- a/compiler/tflchef/tflite/CMakeLists.txt +++ b/compiler/tflchef/tflite/CMakeLists.txt @@ -7,3 +7,4 @@ target_link_libraries(tflchef_tflite tflchef_proto) target_link_libraries(tflchef_tflite mio_tflite) target_link_libraries(tflchef_tflite stdex) target_link_libraries(tflchef_tflite cwrap) +target_link_libraries(tflchef_tflite souschef) diff --git a/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.cpp b/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.cpp new file mode 100644 index 000000000..db7f4c932 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 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 "NonMaxSuppressionV5.h" + +#include "Convert.h" +#include "FillerHelper.h" + +namespace tflchef +{ + +void TFliteOpNonMaxSuppressionV5::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + const auto &inputs = *op->inputs(); + + const tflite::Tensor *max_output_size_tensor = import->tensors()->Get(inputs[2]); + assert(max_output_size_tensor->type() == tflite::TensorType::TensorType_INT32); + + const tflite::Tensor *iou_threshold_tensor = import->tensors()->Get(inputs[3]); + assert(iou_threshold_tensor->type() == tflite::TensorType::TensorType_FLOAT32); + + const tflite::Tensor *score_threshold_tensor = import->tensors()->Get(inputs[4]); + assert(score_threshold_tensor->type() == tflite::TensorType::TensorType_FLOAT32); + + const tflite::Tensor *soft_nms_sigma_tensor = import->tensors()->Get(inputs[5]); + assert(soft_nms_sigma_tensor->type() == tflite::TensorType::TensorType_FLOAT32); + + for (int32_t index = 2; index < 6; ++index) + { + fill_tensor_to_import(index, import); + } +} + +tflchef::Operation *TFliteOpNonMaxSuppressionV5::build(const tflite::Operator *op, + TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("NonMaxSuppressionV5"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.h b/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.h new file mode 100644 index 000000000..c948043f4 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/NonMaxSuppressionV5.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 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 __TFLITE_OP_NON_MAX_SUPPRESSION_V5_H__ +#define __TFLITE_OP_NON_MAX_SUPPRESSION_V5_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for NON_MAX_SUPPRESSION_V5 + */ +class TFliteOpNonMaxSuppressionV5 : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_NON_MAX_SUPPRESSION_V5_H__ diff --git a/compiler/tflchef/tflite/src/TFliteImport.h b/compiler/tflchef/tflite/src/TFliteImport.h index 5b46f4501..9d0a642ab 100644 --- a/compiler/tflchef/tflite/src/TFliteImport.h +++ b/compiler/tflchef/tflite/src/TFliteImport.h @@ -19,6 +19,8 @@ #include <mio/tflite/schema_generated.h> +#include <souschef/TensorFiller.h> + #include <tflchef.pb.h> #include <map> @@ -40,7 +42,7 @@ bool is_custom(const tflite::OperatorCode *opcode); /** * @brief Loads TF lite file and provides helpers to access attributes */ -class TFliteImport +class TFliteImport : public souschef::TensorFiller { public: TFliteImport(const tflite::Model *model); @@ -63,63 +65,6 @@ public: std::string opcode_name(const tflite::Operator *op) const; size_t buffer_info(const tflite::Tensor *tensor, const uint8_t **buff_data); - /** - * @brief This will record the tensor by index, if it needs filler option, - * such as kernel, bias. - */ - void set_tensor_filler(uint32_t tensor_index) { _tensor_filler[tensor_index] = true; } - - /** - * @brief This will store int32 filler values such as reshape information for the tensor - */ - void set_tensor_filler(uint32_t tensor_index, std::vector<int32_t> &expvalues) - { - _tensor_filler_vint32[tensor_index] = expvalues; - } - - void set_tensor_filler(uint32_t tensor_index, std::vector<float> &expvalues) - { - _tensor_filler_vfloat[tensor_index] = expvalues; - } - - /** - * @brief This will return true if the tensor by index, needs a filler option. - */ - bool get_tensor_filler(uint32_t tensor_index) - { - auto it = _tensor_filler.find(tensor_index); - if (it != _tensor_filler.end()) - { - return it->second; - } - return false; - } - - /** - * @brief This will return true if the tensor by index, needs a int array filler option. - */ - bool get_tensor_filler(uint32_t tensor_index, std::vector<int32_t> &expvalues) - { - auto it = _tensor_filler_vint32.find(tensor_index); - if (it != _tensor_filler_vint32.end()) - { - expvalues = it->second; - return true; - } - return false; - } - - bool get_tensor_filler(uint32_t tensor_index, std::vector<float> &expvalues) - { - auto it = _tensor_filler_vfloat.find(tensor_index); - if (it != _tensor_filler_vfloat.end()) - { - expvalues = it->second; - return true; - } - return false; - } - private: const TFliteSubGraphs_t *_subgraphs{nullptr}; const TFliteBuffers_t *_buffers{nullptr}; @@ -129,10 +74,6 @@ private: std::vector<const tflite::OperatorCode *> _op_codes{}; std::vector<int32_t> _inputs{}; std::vector<int32_t> _outputs{}; - - std::map<uint32_t, bool> _tensor_filler{}; - std::map<uint32_t, std::vector<int32_t>> _tensor_filler_vint32{}; - std::map<uint32_t, std::vector<float>> _tensor_filler_vfloat{}; }; } // namespace tflchef diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index de14e37d1..36a010957 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -69,6 +69,7 @@ #include "Op/Mul.h" #include "Op/Neg.h" #include "Op/NonMaxSuppressionV4.h" +#include "Op/NonMaxSuppressionV5.h" #include "Op/NotEqual.h" #include "Op/OneHot.h" #include "Op/Pack.h" diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index 8d33007be..a454e98b6 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -106,6 +106,7 @@ private: REG_TFL_OP(MUL, TFliteOpMul); REG_TFL_OP(NEG, TFliteOpNeg); REG_TFL_OP(NON_MAX_SUPPRESSION_V4, TFliteOpNonMaxSuppressionV4); + REG_TFL_OP(NON_MAX_SUPPRESSION_V5, TFliteOpNonMaxSuppressionV5); REG_TFL_OP(NOT_EQUAL, TFliteOpNotEqual); REG_TFL_OP(ONE_HOT, TFliteOpOneHot); REG_TFL_OP(PACK, TFliteOpPack); |