32 ::caffe::NetParameter param;
34 param.set_name(
"conv");
38 auto input = param.add_layer();
39 input->set_name(
"input");
40 input->set_type(
"Input");
41 input->add_top(model.ifm_name());
43 auto input_param = new ::caffe::InputParameter{};
44 auto input_shape = input_param->add_shape();
45 input_shape->add_dim(1);
46 input_shape->add_dim(model.ifm_shape().depth());
47 input_shape->add_dim(model.ifm_shape().height());
48 input_shape->add_dim(model.ifm_shape().width());
49 input->set_allocated_input_param(input_param);
54 auto conv = param.add_layer();
55 conv->set_name(
"conv");
56 conv->set_type(
"Convolution");
57 conv->add_bottom(model.ifm_name());
58 conv->add_top(model.ofm_name());
60 const auto &ker_shape = model.ker_shape();
62 auto ker_blob_shape = new ::caffe::BlobShape{};
64 ker_blob_shape->add_dim(ker_shape.count());
65 ker_blob_shape->add_dim(ker_shape.depth());
66 ker_blob_shape->add_dim(ker_shape.height());
67 ker_blob_shape->add_dim(ker_shape.width());
69 auto ker_blob = conv->add_blobs();
71 for (uint32_t n = 0; n < ker_shape.count(); ++n)
73 for (uint32_t ch = 0; ch < ker_shape.depth(); ++ch)
75 for (uint32_t row = 0; row < ker_shape.height(); ++row)
77 for (uint32_t col = 0; col < ker_shape.width(); ++col)
79 ker_blob->add_data(model.ker_data().at(n, ch, row, col));
85 ker_blob->set_allocated_shape(ker_blob_shape);
87 auto conv_param = new ::caffe::ConvolutionParameter{};
88 conv_param->set_num_output(model.ker_shape().count());
89 conv_param->set_bias_term(
false);
90 conv_param->add_kernel_size(model.ker_shape().height());
91 conv_param->add_kernel_size(model.ker_shape().width());
92 conv->set_allocated_convolution_param(conv_param);
95 auto net = make_unique<::caffe::Net<float>>(param);
96 return make_unique<nnkit::support::caffe::Backend<float>>(std::move(net));