From 24ebd2d638f024c8b03407b205946750492e3db3 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Sun, 27 Dec 2015 20:56:24 -0800 Subject: [PATCH] enable dilated deconvolution Since the underlying routines are shared, we need only upgrade compute_output_shape. --- src/caffe/layers/base_conv_layer.cpp | 3 --- src/caffe/layers/deconv_layer.cpp | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/caffe/layers/base_conv_layer.cpp b/src/caffe/layers/base_conv_layer.cpp index ed659c2efdc..7953d586cc6 100644 --- a/src/caffe/layers/base_conv_layer.cpp +++ b/src/caffe/layers/base_conv_layer.cpp @@ -105,9 +105,6 @@ void BaseConvolutionLayer::LayerSetUp(const vector*>& bottom, for (int i = 0; i < num_spatial_axes_; ++i) { dilation_data[i] = (num_dilation_dims == 0) ? kDefaultDilation : conv_param.dilation((num_dilation_dims == 1) ? 0 : i); - if (reverse_dimensions()) { - CHECK_EQ(dilation_data[i], 1) << "Deconvolution doesn't support dilation"; - } } // Special case: im2col is the identity for 1x1 convolution with stride 1 // and no padding, so flag for skipping the buffer and transformation. diff --git a/src/caffe/layers/deconv_layer.cpp b/src/caffe/layers/deconv_layer.cpp index 275c05626c8..20a460fbdea 100644 --- a/src/caffe/layers/deconv_layer.cpp +++ b/src/caffe/layers/deconv_layer.cpp @@ -9,12 +9,14 @@ void DeconvolutionLayer::compute_output_shape() { const int* kernel_shape_data = this->kernel_shape_.cpu_data(); const int* stride_data = this->stride_.cpu_data(); const int* pad_data = this->pad_.cpu_data(); + const int* dilation_data = this->dilation_.cpu_data(); this->output_shape_.clear(); for (int i = 0; i < this->num_spatial_axes_; ++i) { // i + 1 to skip channel axis const int input_dim = this->input_shape(i + 1); + const int kernel_extent = dilation_data[i] * (kernel_shape_data[i] - 1) + 1; const int output_dim = stride_data[i] * (input_dim - 1) - + kernel_shape_data[i] - 2 * pad_data[i]; + + kernel_extent - 2 * pad_data[i]; this->output_shape_.push_back(output_dim); } }