天天看点

对卷积的一点理解(图像卷积、文本卷积、傅立叶变换)

最近在看DPCNN这个模型,这个模型是一个腾讯提出的文本分类模型,借鉴了Text CNN和ResNet两个模型的特征和架构,因为是用在文本上应用了CNN,但是一直对卷积的概念不太清楚,所以趁着坐火车的时间看了看相关的博客。

       图像的卷积

       对于图像而言,卷积应该是一个革命性的操作,本质上是一种图像特征提取的方法,为什么我们不用全连接层硬怼呢?首先,如果每个特征都要对所有的像素点进行加权的话,其实很容易造成过拟合,而且参数过多,所以最开始我对卷积的理解是,使用卷积层代替全连接层能够有效地减少参数(这一点跟RNN共享参数是一个道理)。将一个卷积核作用于一个图像的一个通道,那么就能得到这幅图在该卷积核下的一个feature map,然后一般会有很多卷积核,然后得到很多个feature map,以前我们做数字图像处理,其实已经有卷积的概念了,那时候我们是手动构造特征,也就是规定卷积核到底长什么样子,比如用于边缘检测的Sobel卷积核,通过了Sobel卷积核作用后得到的feature map就能得到一幅图的边缘,即亮度突变的地方。但是,卷积核的本质是啥?

       卷积核的操作结果是啥?实际上只是一个像素点与其周围的像素点的大小的一个加权均值,不同的卷积核对应的权重不同,那么混合信息的方式也就不同,将卷积核的权重作为参数,根据有监督学习的训练样本对这些参数进行更新,那么就能自动地学习哪些卷积核有用。图像本质上是一个二维有限离散的函数,根据卷积定理,时域上的函数的卷积等于函数进行傅立叶变换后的函数的乘积,一个二元函数进行傅立叶变换后,对应的频域上的二元函数其实相当于一个未正规化的二元频率分布密度函数,将图像对一个固定的卷积核进行卷机操作,卷积核也对应一个二元频率分布密度函数,对应的进行相乘,其实相当于对某些频率进行过滤,这里与所谓的低通滤波、高通滤波其实非常像,所以我们卷积得到的特征的本质是图像不同频段的信息。

       文本的卷积

       对于文本而言,将一个序列看作纵轴,token的embedding看做横轴,那么一个序列就可以表示为一个图像,所以这个时候卷积核的大小有个讲究,就是卷积核横着的这个维度要等于embedding的大小,因为选部分的话,感觉意义不大。(这一点我持保留意见)

       感觉有很多可以尝试的东西,CNN在文本上或许也能做出一点可视化的东西出来,或者是做一些无监督的东西出来。

关键词

       广义上的时域和频域

       Frequencies for images

       The Fourier domain for images

       The convolution theorem

Due to the convolution theorem, we can imagine that convolutional nets operate on images in the Fourier domain and from the images above we now know that images in that domain contain a lot of information about orientation. Thus convolutional nets should be better than traditional algorithms when it comes to rotated images and this is indeed the case (although convolutional nets are still very bad at this when we compare them to human vision).

       The reason why the convolution operation is often described as a filtering operation, and why convolution kernels are often named filters will be apparent from the next example, which is very close to convolution.

       If we transform the original image with a Fourier transform and then multiply it by a circle padded by zeros (zeros=black) in the Fourier domain, we filter out all high frequency values (they will be set to zero, due to the zero padded values). Note that the filtered image still has the same striped pattern, but its quality is much worse now — this is how jpeg compression works (although a different but similar transform is used), we transform the image, keep only certain frequencies and transform back to the spatial image domain; the compression ratio would be the size of the black area to the size of the circle in this example.

参考:

  1. https://timdettmers.com/2015/03/26/convolution-deep-learning/
  2. http://www.hankcs.com/ml/understanding-the-convolution-in-deep-learning.html

继续阅读