[enco] Support bias setting for ANNConv2DAppender (#2652)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 13 Dec 2018 02:19:10 +0000 (11:19 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 13 Dec 2018 02:19:10 +0000 (11:19 +0900)
With this commit, users are able to a pass bias term to ANNConv2DAppender.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/Transforms/Split.cpp

index 38e0b11..9ecb51b 100644 (file)
@@ -150,6 +150,9 @@ public:
 
   void ifm(coco::FeatureObject *ifm) { _ifm = ifm; }
   void ker(coco::KernelObject *ker) { _ker = ker; }
+  // Q: Should we take a bias as a feature object?
+  // NOTE This interface is subject to change
+  void bias(coco::FeatureObject *bias) { _bias = bias; }
   void ofm(coco::FeatureObject *ofm) { _ofm = ofm; }
 
 public:
@@ -175,7 +178,9 @@ public:
     auto bias = binder->addOperand<float>(nncc::core::ADT::tensor::Shape{_ker->shape().count()});
 
     // Fill bias data
+    if (_bias == nullptr)
     {
+      // Use a fresh empty bias if "bias" is not specified
       auto length = _ker->shape().count();
 
       std::vector<float> values;
@@ -183,6 +188,17 @@ public:
 
       binder->setOperand(bias, values.begin(), values.end());
     }
+    else
+    {
+      // Use specified "bias"
+      auto bias_bag = _bias->bag();
+      auto bias_weight = data->f32()->weight(bias_bag);
+
+      assert(bias_weight.data() != nullptr);
+      assert(bias_weight.size() == _ker->shape().count());
+
+      binder->setOperand(bias, bias_weight.data(), bias_weight.data() + bias_weight.size());
+    }
 
     auto left = binder->addOperand<int32_t>();
     binder->setOperand(left, _pad.left());
@@ -215,6 +231,7 @@ private:
 private:
   coco::FeatureObject *_ifm = nullptr;
   coco::KernelObject *_ker = nullptr;
+  coco::FeatureObject *_bias = nullptr;
   coco::FeatureObject *_ofm = nullptr;
 };