From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 7 Sep 2018 02:18:30 +0000 (+0900) Subject: [enco] Introduce ConcatSpec class (#1403) X-Git-Tag: nncc_backup~1890 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c9a8fb4b23aa956b8aa5f459ba50ef14bc12f80;p=platform%2Fcore%2Fml%2Fnnfw.git [enco] Introduce ConcatSpec class (#1403) This commit introduces ConcatSpec class which estimates the output shape of Concat layer. Signed-off-by: Jonghyun Park --- diff --git a/contrib/enco/frontend/caffe/src/ConcatSpec.cpp b/contrib/enco/frontend/caffe/src/ConcatSpec.cpp new file mode 100644 index 0000000..02eeaa4 --- /dev/null +++ b/contrib/enco/frontend/caffe/src/ConcatSpec.cpp @@ -0,0 +1,24 @@ +#include "ConcatSpec.h" + +#include + +using namespace nncc::core::ADT::tensor; + +nncc::core::ADT::tensor::Shape ConcatSpec::forward(const ShapeList &inputs) const +{ + assert(inputs.size() > 0); + + Shape output_shape = inputs.at(0); + + for (uint32_t n = 1; n < inputs.size(); ++n) + { + // The current implementation assumes that "inputs" is well-formed + // TODO Verify whether "inputs" is really well-formed + const auto &input_shape = inputs.at(n); + output_shape.dim(_axis) += input_shape.dim(_axis); + } + + return output_shape; +} + +ConcatSpec concat_spec(uint32_t axis) { return ConcatSpec{axis}; } diff --git a/contrib/enco/frontend/caffe/src/ConcatSpec.h b/contrib/enco/frontend/caffe/src/ConcatSpec.h new file mode 100644 index 0000000..0a831d9 --- /dev/null +++ b/contrib/enco/frontend/caffe/src/ConcatSpec.h @@ -0,0 +1,29 @@ +#ifndef __CONCAT_SPEC_H__ +#define __CONCAT_SPEC_H__ + +#include + +#include + +using ShapeList = std::vector; + +class ConcatSpec +{ +public: + explicit ConcatSpec(uint32_t axis) : _axis{axis} + { + // DO NOTHING + } + +public: + // @brief Return the output shape when inputs of given shape are + // concatenated along _axis + nncc::core::ADT::tensor::Shape forward(const ShapeList &) const; + +private: + uint32_t _axis; +}; + +ConcatSpec concat_spec(uint32_t axis); + +#endif // __CONCAT_SPEC_H__ diff --git a/contrib/enco/frontend/caffe/src/ConcatSpec.test.cpp b/contrib/enco/frontend/caffe/src/ConcatSpec.test.cpp new file mode 100644 index 0000000..5696990 --- /dev/null +++ b/contrib/enco/frontend/caffe/src/ConcatSpec.test.cpp @@ -0,0 +1,26 @@ +#include "ConcatSpec.h" + +#include + +using nncc::core::ADT::tensor::Shape; + +namespace +{ +class ConcatSpecTest : public ::testing::Test +{ + // FOR FUTURE USE +}; +} // namespace + +TEST_F(ConcatSpecTest, ifm_shape) +{ + const Shape in_1{1, 1, 4, 4}; + const Shape in_2{1, 2, 4, 4}; + const Shape in_3{1, 3, 4, 4}; + const Shape in_4{1, 4, 4, 4}; + + auto expected = Shape{1, 10, 4, 4}; + auto obtained = concat_spec(1).forward({in_1, in_2, in_3, in_4}); + + ASSERT_EQ(expected, obtained); +}