[enco.caffe] Initial pooling layer support (#1314)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Tue, 4 Sep 2018 04:49:29 +0000 (13:49 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Tue, 4 Sep 2018 04:49:29 +0000 (13:49 +0900)
This commit presents the initial implementation of pooling layer
supporting routine.

The current implementation supports only simple Max pooling (w/o padding
and stride).

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/frontend/caffe/src/Frontend.cpp

index 6d10069..8a574d8 100644 (file)
@@ -1,5 +1,6 @@
 #include "Frontend.h"
 #include "ConvolutionSpec.h"
+#include "PoolingSpec.h"
 
 #include <nncc/core/ADT/feature/CHWLayout.h>
 #include <nncc/core/ADT/kernel/Shape.h>
@@ -225,6 +226,62 @@ enco::Bundle Frontend::load(void) const
       bag_ctx[ofm_name] = ofm_bag;
       shape_ctx[ofm_name] = ofm_shape;
     }
+    else if (layer.type() == "Pooling")
+    {
+      assert(layer.bottom().size() == 1);
+      assert(layer.top().size() == 1);
+
+      assert(layer.has_pooling_param());
+      const auto &param = layer.pooling_param();
+
+      PoolingSpec spec{param};
+      {
+        const auto ifm_name = layer.bottom(0);
+        const auto ifm_shape = shape_ctx.at(ifm_name);
+        spec.ifm_shape(ifm_shape);
+      }
+
+      // Create an object for an input feature map
+      const auto ifm_name = layer.bottom(0);
+      const auto ifm_shape = shape_ctx.at(ifm_name);
+      auto ifm_bag = bag_ctx.at(ifm_name);
+      auto ifm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ifm_shape));
+
+      ifm_obj->bag(ifm_bag);
+      ifm_obj->reorder<feature::CHWLayout>();
+
+      // Create an object for an output feature map
+      const auto ofm_name = layer.top(0);
+      const auto ofm_shape = spec.ofm_shape();
+      auto ofm_bag = m->entity()->bag()->create(num_elements(ofm_shape));
+      auto ofm_obj = m->entity()->object()->create(morph::caffe::as_feature_shape(ofm_shape));
+
+      ofm_obj->bag(ofm_bag);
+      ofm_obj->reorder<feature::CHWLayout>();
+
+      // TODO Support other pooling method
+      assert(!param.has_pool() || (param.pool() == ::caffe::PoolingParameter_PoolMethod_MAX));
+
+      // Create a MaxPool2D op
+      auto op = m->entity()->op()->create<coco::MaxPool2D>();
+
+      op->window()->vertical(spec.window_height());
+      op->window()->horizontal(spec.window_width());
+
+      // Create a UnitF instruction
+      auto ins = m->entity()->instr()->create<coco::UnitF>();
+
+      ins->ifm(ifm_obj);
+      ins->ofm(ofm_obj);
+      ins->op(op);
+
+      // Append the instruction to the block
+      blk->instr()->append(ins);
+
+      // Update bag and shape context
+      bag_ctx[ofm_name] = ofm_bag;
+      shape_ctx[ofm_name] = ofm_shape;
+    }
     else if (layer.type() == "ReLU")
     {
       assert(layer.bottom().size() == 1);