MCPcopy Create free account
hub / github.com/BVLC/caffe / LayerSetUp

Method LayerSetUp

src/caffe/layers/base_conv_layer.cpp:12–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11template <typename Dtype>
12void BaseConvolutionLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
13 const vector<Blob<Dtype>*>& top) {
14 // Configure the kernel size, padding, stride, and inputs.
15 ConvolutionParameter conv_param = this->layer_param_.convolution_param();
16 force_nd_im2col_ = conv_param.force_nd_im2col();
17 channel_axis_ = bottom[0]->CanonicalAxisIndex(conv_param.axis());
18 const int first_spatial_axis = channel_axis_ + 1;
19 const int num_axes = bottom[0]->num_axes();
20 num_spatial_axes_ = num_axes - first_spatial_axis;
21 CHECK_GE(num_spatial_axes_, 0);
22 vector<int> spatial_dim_blob_shape(1, std::max(num_spatial_axes_, 1));
23 // Setup filter kernel dimensions (kernel_shape_).
24 kernel_shape_.Reshape(spatial_dim_blob_shape);
25 int* kernel_shape_data = kernel_shape_.mutable_cpu_data();
26 if (conv_param.has_kernel_h() || conv_param.has_kernel_w()) {
27 CHECK_EQ(num_spatial_axes_, 2)
28 << "kernel_h & kernel_w can only be used for 2D convolution.";
29 CHECK_EQ(0, conv_param.kernel_size_size())
30 << "Either kernel_size or kernel_h/w should be specified; not both.";
31 kernel_shape_data[0] = conv_param.kernel_h();
32 kernel_shape_data[1] = conv_param.kernel_w();
33 } else {
34 const int num_kernel_dims = conv_param.kernel_size_size();
35 CHECK(num_kernel_dims == 1 || num_kernel_dims == num_spatial_axes_)
36 << "kernel_size must be specified once, or once per spatial dimension "
37 << "(kernel_size specified " << num_kernel_dims << " times; "
38 << num_spatial_axes_ << " spatial dims).";
39 for (int i = 0; i < num_spatial_axes_; ++i) {
40 kernel_shape_data[i] =
41 conv_param.kernel_size((num_kernel_dims == 1) ? 0 : i);
42 }
43 }
44 for (int i = 0; i < num_spatial_axes_; ++i) {
45 CHECK_GT(kernel_shape_data[i], 0) << "Filter dimensions must be nonzero.";
46 }
47 // Setup stride dimensions (stride_).
48 stride_.Reshape(spatial_dim_blob_shape);
49 int* stride_data = stride_.mutable_cpu_data();
50 if (conv_param.has_stride_h() || conv_param.has_stride_w()) {
51 CHECK_EQ(num_spatial_axes_, 2)
52 << "stride_h & stride_w can only be used for 2D convolution.";
53 CHECK_EQ(0, conv_param.stride_size())
54 << "Either stride or stride_h/w should be specified; not both.";
55 stride_data[0] = conv_param.stride_h();
56 stride_data[1] = conv_param.stride_w();
57 } else {
58 const int num_stride_dims = conv_param.stride_size();
59 CHECK(num_stride_dims == 0 || num_stride_dims == 1 ||
60 num_stride_dims == num_spatial_axes_)
61 << "stride must be specified once, or once per spatial dimension "
62 << "(stride specified " << num_stride_dims << " times; "
63 << num_spatial_axes_ << " spatial dims).";
64 const int kDefaultStride = 1;
65 for (int i = 0; i < num_spatial_axes_; ++i) {
66 stride_data[i] = (num_stride_dims == 0) ? kDefaultStride :
67 conv_param.stride((num_stride_dims == 1) ? 0 : i);
68 CHECK_GT(stride_data[i], 0) << "Stride dimensions must be nonzero.";
69 }

Callers

nothing calls this directly

Calls 11

CanonicalAxisIndexMethod · 0.80
num_axesMethod · 0.80
shapeMethod · 0.80
shape_stringMethod · 0.80
countMethod · 0.80
ReshapeMethod · 0.45
mutable_cpu_dataMethod · 0.45
sizeMethod · 0.45
resetMethod · 0.45
FillMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected