二维卷积作为矩阵矩阵乘法 [英] 2-D convolution as a matrix-matrix multiplication

查看:717
本文介绍了二维卷积作为矩阵矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在一维情况下,两个向量ab之间的卷积可以计算为conv(a, b),也可以计算为T_ab之间的乘积,其中T_aa对应的Toeplitz矩阵.

I know that, in the 1D case, the convolution between two vectors, a and b, can be computed as conv(a, b), but also as the product between the T_a and b, where T_a is the corresponding Toeplitz matrix for a.

是否可以将此想法扩展到2D?

Is it possible to extend this idea to 2D?

给出a = [5 1 3; 1 1 2; 2 1 3]b=[4 3; 1 2],是否可以像一维情况一样在Toeplitz矩阵中转换a并计算T_ab之间的矩阵矩阵乘积?

Given a = [5 1 3; 1 1 2; 2 1 3] and b=[4 3; 1 2], is it possible to convert a in a Toeplitz matrix and compute the matrix-matrix product between T_a and b as in the 1-D case?

推荐答案

是的,有可能,并且您还应该使用双块循环矩阵(这是

Yes, it is possible and you should also use a doubly block circulant matrix (which is a special case of Toeplitz matrix). I will give you an example with a small size of kernel and the input, but it is possible to construct Toeplitz matrix for any kernel. So you have a 2d input x and 2d kernel k and you want to calculate the convolution x * k. Also let's assume that k is already flipped. Let's also assume that x is of size n×n and k is m×m.

因此,将k展开为大小为(n-m+1)^2 × n^2的稀疏矩阵,然后将x展开为长向量n^2 × 1.您可以将此稀疏矩阵与向量相乘,然后将结果向量(大小为(n-m+1)^2 × 1)转换为n-m+1方阵.

So you unroll k into a sparse matrix of size (n-m+1)^2 × n^2, and unroll x into a long vector n^2 × 1. You compute a multiplication of this sparse matrix with a vector and convert the resulting vector (which will have a size (n-m+1)^2 × 1) into a n-m+1 square matrix.

我敢肯定,仅从阅读中很难理解这一点.因此,这里是2×2内核和3×3输入的示例.

I am pretty sure this is hard to understand just from reading. So here is an example for 2×2 kernel and 3×3 input.

*

这是一个带有向量的构造矩阵:

Here is a constructed matrix with a vector:

等于.

这与在x上滑动k的滑动窗口所获得的结果相同.

And this is the same result you would have got by doing a sliding window of k over x.

这篇关于二维卷积作为矩阵矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆