43 std::map<std::string, tensor::Shape> &shape_ctx = context->
shape_ctx();
44 std::map<std::string, coco::Bag *> &bag_ctx = context->
bag_ctx();
47 assert(layer.bottom().size() == 1);
48 assert(layer.top().size() == 1);
50 assert(layer.has_convolution_param());
51 const auto ¶m = layer.convolution_param();
55 const auto ifm_name = layer.bottom(0);
56 const auto ifm_shape = shape_ctx.at(ifm_name);
62 assert(spec.num_batch_axes() == 1);
63 assert(spec.num_spatial_axes() == 2);
66 const auto ifm_name = layer.bottom(0);
67 const auto ifm_shape = shape_ctx.at(ifm_name);
68 auto ifm_bag = bag_ctx.at(ifm_name);
69 auto ifm_obj =
module->entity()->object()->create<coco::FeatureObject>();
71 ifm_obj->bag(ifm_bag);
75 const auto ofm_name = layer.top(0);
76 const auto ofm_shape = spec.ofm_shape();
77 auto ofm_bag =
module->entity()->bag()->create(num_elements(ofm_shape));
78 auto ofm_obj =
module->entity()->object()->create<coco::FeatureObject>();
80 ofm_obj->bag(ofm_bag);
86 const auto ker_shape = spec.ker_shape();
87 auto ker_bag =
module->entity()->bag()->create(num_elements(ker_shape));
88 auto ker_obj =
module->entity()->object()->create<coco::KernelObject>();
90 ker_obj->bag(ker_bag);
94 data->f32()->allocate(ker_bag);
97 assert(weight_ctx.
blob_count(layer.name()) >= 1);
98 auto ker_blob = weight_ctx.
blob_get(layer.name(), 0);
102 auto ker_dst = data->f32()->access(ker_obj);
104 ker_obj->shape(), ker_blob->mutable_data()->begin());
106 for (uint32_t n = 0; n < ker_obj->shape().count(); ++n)
108 for (uint32_t ch = 0; ch < ker_obj->shape().depth(); ++ch)
110 for (uint32_t row = 0; row < ker_obj->shape().height(); ++row)
112 for (uint32_t col = 0; col < ker_obj->shape().width(); ++col)
114 ker_dst->at(n, ch, row, col) = ker_src.at(n, ch, row, col);
124 auto op =
module->entity()->op()->create<coco::Conv2D>();
126 op->group(spec.group());
129 op->stride()->vertical(spec.stride(0));
130 op->stride()->horizontal(spec.stride(1));
132 op->pad()->top(spec.pad(0));
133 op->pad()->bottom(spec.pad(0));
134 op->pad()->left(spec.pad(1));
135 op->pad()->right(spec.pad(1));
151 if (param.bias_term())
153 assert(weight_ctx.
blob_count(layer.name()) >= 2);
156 auto bias_bag =
module->entity()->bag()->create(ker_shape.dim(0));
157 auto bias_obj =
module->entity()->object()->create<coco::FeatureObject>();
159 bias_obj->bag(bias_bag);
162 auto added_bag =
module->entity()->bag()->create(num_elements(ofm_shape));
163 auto added_obj =
module->entity()->object()->create<coco::FeatureObject>();
165 added_obj->bag(added_bag);
178 data->f32()->allocate(bias_bag);
180 auto bias_span = data->f32()->weight(bias_bag);
181 auto bias_blob = weight_ctx.
blob_get(layer.name(), 1);
183 for (uint32_t ch = 0; ch < ker_obj->shape().count(); ++ch)
185 bias_span[ch] = bias_blob->data(ch);
193 bag_ctx[ofm_name] = ofm_bag;
194 shape_ctx[ofm_name] = ofm_shape;
ShapeContext & shape_ctx()
WeightContext & weight_ctx()
int blob_count(const LayerName &name)
::caffe::BlobProto * blob_get(const LayerName &name, uint32_t n)