简体   繁体   English

改变卷积神经网络中的参数

[英]Change parameters in Convolution neural network

I'm praticing CNNs.我正在练习 CNN。 I read some papers about training MNIST dataset use CNNs.size of image is 28x28 and use architecture 5 layers: input>conv1-maxpool1>conv2-maxpool2>fully connected>output我阅读了一些关于使用 CNNs.size of image 训练 MNIST 数据集并使用架构 5 层的论文:input>conv1-maxpool1>conv2-maxpool2>fully connected>output

Convolutional Layer #1
- Computes 32 features using a 5x5 filter with ReLU activation.
- Padding is added to preserve width and height.
- Input Tensor Shape: [batch_size, 28, 28, 1]
- Output Tensor Shape: [batch_size, 28, 28, 32] 
Pooling Layer #1
- First max pooling layer with a 2x2 filter and stride of 2
- Input Tensor Shape: [batch_size, 28, 28, 32]
- Output Tensor Shape: [batch_size, 14, 14, 32] 
Convolutional Layer #2
- Computes 64 features using a 5x5 filter.
- Padding is added to preserve width and height.
- Input Tensor Shape: [batch_size, 14, 14, 32]
- Output Tensor Shape: [batch_size, 14, 14, 64] 
Pooling Layer #2
- Second max pooling layer with a 2x2 filter and stride of 2
- Input Tensor Shape: [batch_size, 14, 14, 64]
- Output Tensor Shape: [batch_size, 7, 7, 64] 
Flatten tensor into a batch of vectors
- Input Tensor Shape: [batch_size, 7, 7, 64]
- Output Tensor Shape: [batch_size, 7 * 7 * 64] 
Fully Connected Layer
- Densely connected layer with 1024 neurons
- Input Tensor Shape: [batch_size, 7 * 7 * 64]
- Output Tensor Shape: [batch_size, 1024] Output layer
- Input Tensor Shape: [batch_size, 1024]
- Output Tensor Shape: [batch_size, 10]

In conv1, with 1 input computates 32 features using a 5x5 filter and in conv2 with 32 input from conv1 computates 64 features using same filter.在 conv1 中,1 个输入使用 5x5 过滤器计算 32 个特征,而在 conv2 中,来自 conv1 的 32 个输入使用相同的过滤器计算 64 个特征。 What are parameters such as 32,64,2x2 filter chosen based on? 32、64、2x2滤波器等参数是根据什么选择的? Do they based on size of image?它们是否基于图像的大小?

If size of images is larger than 28x28 such as 128x128.如果图像尺寸大于 28x28,例如 128x128。 Should I increse the number of layers over 5 layers?我应该增加 5 层以上的层数吗? How are above parameters changed with other size of images?上述参数如何随其他尺寸的图像而变化?

Thank advance提前致谢

At it's base level, those inputs are called HyperParameters and are not typically defined by any particular set of rules.在它的基础级别,这些输入称为 HyperParameters,通常不由任何特定的规则集定义。 That said, often we use rules of thumb (heuristics) to choose a set of hyper parameters and then use hyperparameter optimisation to increase performance or efficiency etc.也就是说,我们经常使用经验法则(启发式)来选择一组超参数,然后使用超参数优化来提高性能或效率等。

A great explanation of this is Here对此的一个很好的解释是这里

Edit: Further info in this paper - it's a widely studied problem, look into Arxiv and Stats.Stackexchange for more info but here is a great paper I used when I was learning Here编辑:本文中的更多信息 - 这是一个被广泛研究的问题,查看 Arxiv 和 Stats.Stackexchange 以获取更多信息,但这是我学习时使用的一篇很棒的论文在这里

What are parameters such as 32,64,2x2 filter chosen based on? 32、64、2x2滤波器等参数是根据什么选择的? Do they based on size of image?它们是否基于图像的大小?

The parameters that you have mentioned (32,64,2x2) are number of filters for a convolutional layer and a filter size.您提到的参数 (32,64,2x2) 是卷积层的过滤器数量和过滤器大小。 They are the hyperparameters that you can select and adjust as you train your models.它们是您可以在训练模型时选择和调整的超参数。 Depending on your dataset, application and model performance you can control them.根据您的数据集、应用程序和模型性能,您可以控制它们。

For a number of filters, you use it to control number of features that your model learns.对于许多过滤器,您可以使用它来控制模型学习的特征数量。 In your model, your filter number increase from 32 to 64 after maxpooling layer.在您的模型中,您的过滤器编号在 maxpooling 层之后从 32 增加到 64。 Maxpooling layer with 2x2 filter will reduce the number of features by half.带有 2x2 过滤器的 Maxpooling 层会将特征数量减少一半。 And by increasing the filter numbers by double, it will keep the same number of features in the model.通过将过滤器数量增加一倍,它将在模型中保持相同数量的特征。 In convention, after a 2x2 maxpooling layer, the filter number will double for this reason.按照惯例,在 2x2 最大池化层之后,过滤器数量将因此加倍。

And for the filter size, if it's for maxpooling layer, it will determine the size of feature reduction.而对于过滤器的大小,如果是对于maxpooling层,它将决定特征减少的大小。 If it's for convolutional layer, it will determine how detail the input images are learned.如果是卷积层,它将决定输入图像的学习细节。 For example, if you are trying to work with images where small pixels or features differciate objects, you would choose small filter size such as 3x3 or 5x5.例如,如果您尝试使用小像素或特征区分对象的图像,则可以选择较小的过滤器尺寸,例如 3x3 或 5x5。 And vise versa for large filter size.对于大过滤器尺寸,反之亦然。

One way of understanding these hyperparameters is that understand how these affect learning of the model and you will know how to control them depending on each case.理解这些超参数的一种方法是了解它们如何影响模型的学习,并且您将知道如何根据每种情况控制它们。 And another way is to look at how these are set for models used by other people.另一种方法是查看这些是如何为其他人使用的模型设置的。 You may find some conventions such as filter number increasing after maxpooling layer.您可能会发现一些约定,例如在 maxpooling 层之后增加过滤器数量。

If size of images is larger than 28x28 such as 128x128.如果图像尺寸大于 28x28,例如 128x128。 Should I increse the number of layers over 5 layers?我应该增加 5 层以上的层数吗? How are above parameters changed with other size of images?上述参数如何随其他尺寸的图像而变化?

And about layers, having more layers will make your model deeper and will result in more parameters.关于层,拥有更多层将使您的模型更深,并会产生更多参数。 This means that your model will become more complex and become able to learn more about image features.这意味着您的模型将变得更加复杂,并且能够了解更多有关图像特征的信息。 So, having a deep architecture can benefit learning images with large resolutions.因此,拥有深度架构有助于学习高分辨率图像。 Because large resolution means there are many features to learn.因为大分辨率意味着有很多特征需要学习。 However, this also will depend case by case.但是,这也将视具体情况而定。 Good approach to this would be starting with simple model with few layers and gradually increase your layers while it benefits your model.解决此问题的好方法是从具有少量层的简单模型开始,然后逐渐增加层数,同时对您的模型有益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM