CNN中的过滤器数量是多少? [英] What is the number of filter in CNN?

查看:855
本文介绍了CNN中的过滤器数量是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在看到theano的API,

I am currently seeing the API of theano,

theano.tensor.nnet.conv2d(input, filters, input_shape=None, filter_shape=None, border_mode='valid', subsample=(1, 1), filter_flip=True, image_shape=None, **kwargs)

其中 filter_shape (num_filter,num_channel,高度,宽度)的元组,我对此感到困惑,因为不是在图像上滑动滤镜窗口时由步幅决定的滤镜数量?我如何像这样指定过滤器编号?对我来说,如果它是通过参数跨度(如果有的话)计算出来的。

where the filter_shape is a tuple of (num_filter, num_channel, height, width), I am confusing about this because isn't that the number of filter decided by the stride while sliding the filter window on the image? How can I specify on filter number just like this? It would be reasonable to me if it is calculated by the parameter stride (if there is any).

此外,我对术语特征图也感到困惑每层的神经元?批量大小如何?它们如何关联?

Also, I am confused with the term feature map as well, is it the neurons at each layer? How about the batch size? How are they correlated?

推荐答案

过滤器的数量就是神经元的数量,因为每个神经元在输入上执行不同的卷积

The number of filters is the number of neurons, since each neuron performs a different convolution on the input to the layer (more precisely, the neurons' input weights form convolution kernels).

特征图是应用过滤器的结果(因此,您拥有许多特征映射为过滤器),其大小是过滤器的窗口/内核大小和步幅的结果。

A feature map is the result of applying a filter (thus, you have as many feature maps as filters), and its size is a result of window/kernel size of your filter and stride.

下图是我能找到的最好的解释概念的图像高级别:

注意,将2个不同的卷积滤镜应用于输入图像,从而生成2个不同的特征图(滤镜的输出)。每个特征图的每个像素都是卷积层的输出。

The following image was the best I could find to explain the concept at high level: Note that 2 different convolutional filters are applied to the input image, resulting in 2 different feature maps (the output of the filters). Each pixel of each feature map is an output of the convolutional layer.

例如,如果您有28x28的输入图像和一个包含20个7x7滤镜且跨度为1的卷积层,您将在此层的输出上获得20张22x22要素地图。请注意,这以宽度=高度= 22且深度= num_channels = 20的体积的形式呈现给下一层。您可以使用相同的表示形式在RGB图像上训练CNN,例如CIFAR10数据集中的图像。 32x32x3的体积(仅将卷积应用于2个空间维度)。

For instance, if you have 28x28 input images and a convolutional layer with 20 7x7 filters and stride 1, you will get 20 22x22 feature maps at the output of this layer. Note that this is presented to the next layer as a volume with width = height = 22 and depth = num_channels = 20. You could use the same representation to train your CNN on RGB images such as the ones from the CIFAR10 dataset, which would be 32x32x3 volumes (convolution is applied only to the 2 spatial dimensions).

编辑:我想澄清的评论似乎有些混乱。首先,没有神经元。神经元只是神经网络中的一个隐喻。也就是说,在卷积层中有多少个神经元无法客观地回答,而是相对于您对该层执行的计算的看法。在我看来,过滤器是单个神经元,它通过图像扫描,为每个位置提供不同的激活。整个功能图是由单个神经元/滤镜在我视图中的多个位置生成的。评论员似乎有和我一样有效的另一种观点。他们将每个过滤器视为用于卷积运算的一组权重,并将每个神经元视为图像中每个参与位置的神经元,所有神经元都共享由过滤器定义的同一组权重。请注意,这两个视图在功能上(甚至从根本上来说)是相同的,因为它们使用相同的参数,计算并产生相同的结果。因此,这不是问题。

There seems to be some confusion going on in the comments that I'd like to clarify. First, there are no neurons. Neurons are just a metaphor in neural networks. That said, "how many neurons are there in a convolutional layer" cannot be answered objectively, but relative to your view of the computations performed by the layer. In my view, a filter is a single neuron that sweeps through the image, providing different activations for each position. An entire feature map is produced by a single neuron/filter at multiple positions in my view. The commentors seem to have another view that is as valid as mine. They see each filter as a set of weights for a convolution operation, and one neuron for each attended position in the image, all sharing the same set of weights defined by the filter. Note that both views are functionally (and even fundamentally) the same, as they use the same parameters, computations, and produce the same results. Therefore, this is a non-issue.

这篇关于CNN中的过滤器数量是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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