From 297eb8b91d2ac5b01128afbf3a40c0d5016bdf70 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 30 Aug 2018 14:28:31 +0900 Subject: [PATCH] [enco] Set weight (kernel/bias) data for ANN subnet (#1242) This commit implements weight initializer for android NN subnet inside Split pass. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/Transforms/Split.cpp | 45 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/contrib/enco/core/src/Transforms/Split.cpp b/contrib/enco/core/src/Transforms/Split.cpp index b0142f3..b46d8c3 100644 --- a/contrib/enco/core/src/Transforms/Split.cpp +++ b/contrib/enco/core/src/Transforms/Split.cpp @@ -134,6 +134,8 @@ void ANNGroupBuilder::build(void) const #include +#include + namespace { @@ -153,13 +155,52 @@ public: auto ifm = _binder->addOperand(unit->ifm()); auto ker = _binder->addOperand(conv->ker()); - // TODO Fill kernel data + // Fill kernel data + { + auto obj = conv->ker(); + auto shape = obj->shape(); + auto len = nncc::core::ADT::kernel::num_elements(shape); + + auto ovl = _data->f32()->read(obj); + assert(ovl != nullptr); + + // Flatten? + std::vector values; + values.resize(len); + + for (uint32_t n = 0; n < shape.count(); ++n) + { + for (uint32_t ch = 0; ch < shape.depth(); ++ch) + { + for (uint32_t row = 0; row < shape.height(); ++row) + { + for (uint32_t col = 0; col < shape.width(); ++col) + { + const static nncc::core::ADT::kernel::NHWCLayout l{}; + const auto offset = static_cast(l.offset(shape, n, ch, row, col)); + + values.at(offset) = ovl->at(n, ch, row, col); + } + } + } + } + + _binder->setOperand(ker, values.begin(), values.end()); + } // Conv2D in coco IR has no bias, but bias is mandatory in Android NN API auto bias = _binder->addOperand(nncc::core::ADT::tensor::Shape{conv->ker()->shape().count()}); - // TODO Fill bias data + // Fill bias data + { + auto length = conv->ker()->shape().count(); + + std::vector values; + values.resize(length, 0.0f); + + _binder->setOperand(bias, values.begin(), values.end()); + } auto left = _binder->addOperand(); _binder->setOperand(left, 0); -- 2.7.4