As pointed out by @papirrin, the answer given by @Prune is a bit misleading. In CNNs (or Fully Convolutional Neural Neworks, which is where Deconvolution is first proposed), the deconvolution is not exactly the reverse of convolution. More precisely, the deconvolution in CNNs only reverse the shape, but not the content. The name of deconvolution is misleading because deconvolution is already defined mathematically, hence, in the below, we will use transposed convolution to indicate the "deconvolution in CNNs".
To understand the transposed convolution, you will need to transform the filters of convolution operation into a matrix when performing the convolution operation. Then, the convolution operation can be defined as Y=WX
. Then, in the transposed convolution, we basically transpose the matrix, and the output will be computed as Y=W^TX
. For some examples, you can refer to https://tinynet.autoai.org/en/latest/induction/convolution.html and https://tinynet.autoai.org/en/latest/induction/convolution-transpose.html.
As for how to get the convolution matrix in transposed convolution, it depends on how you are going to use it. For image segmentation, it is learned during back propagation. In some visualizations of intermediate feature maps (for example, the ECCV14 paper: https://arxiv.org/abs/1311.2901), it is directly derived from the convolution operation. In summary, both ways are fine.
For how to compute the gradient, it is exactly the same as in convolution. You can also interpret the transposed convolution operation as it basically swap the forward and backward process of a convolution operation.