卷积层大小计算公式

Given:

  • our input layer has a width of W and a height of H
  • our convolutional layer has a filter size F
  • we have a stride of S
  • a padding of P
  • and the number of filters K,

the following formula gives us the width of the next layer: W_out =[ (W−F+2P)/S] + 1.

The output height would be H_out = [(H-F+2P)/S] + 1.

And the output depth would be equal to the number of filters D_out = K.

The output volume would be W_out * H_out * D_out.

 

 

 

Being able to calculate the number of parameters in a neural network is useful since we want to have control over how much memory a neural network uses.

Setup

H = height, W = width, D = depth

  • We have an input of shape 32x32x3 (HxWxD)
  • 20 filters of shape 8x8x3 (HxWxD)
  • A stride of 2 for both the height and width (S)
  • Zero padding of size 1 (P)

Output Layer

  • 14x14x20 (HxWxD)

Solution

There are 756560 total parameters. That's a HUGE amount! Here's how we calculate it:

(8 * 8 * 3 + 1) * (14 * 14 * 20) = 756560

8 * 8 * 3 is the number of weights, we add 1 for the bias. Remember, each weight is assigned to every single part of the output (14 * 14 * 20). So we multiply these two numbers together and we get the final answer.

 

 

Now we'd like you to calculate the number of parameters in the convolutional layer, if every neuron in the output layer shares its parameters with every other neuron in its same channel.

This is the number of parameters actually used in a convolution layer (tf.nn.conv2d()).

Setup

H = height, W = width, D = depth

  • We have an input of shape 32x32x3 (HxWxD)
  • 20 filters of shape 8x8x3 (HxWxD)
  • A stride of 2 for both the height and width (S)
  • Zero padding of size 1 (P)

Output Layer

  • 14x14x20 (HxWxD)

Hint

With parameter sharing, each neuron in an output channel shares its weights with every other neuron in that channel. So the number of parameters is equal to the number of neurons in the filter, plus a bias neuron, all multiplied by the number of channels in the output layer.

Solution

There are 3860 total parameters. That's 196 times fewer parameters! Here's how the answer is calculated:

(8 * 8 * 3 + 1) * 20 = 3840 + 20 = 3860

That's 3840 weights and 20 biases. This should look similar to the answer from the previous quiz. The difference being it's just 20 instead of (14 * 14 * 20). Remember, with weight sharing we use the same filter for an entire depth slice. Because of this we can get rid of 14 * 14 and be left with only 20.

 

 

### RGB 卷积层计算公式 在神经网络中,特别是处理彩色图像时,RGB卷积层通过应用多个滤波器来提取特征。对于三维输入张量(宽度×高度×通道),每个滤波器也是一个三维矩阵,其尺寸通常小于输入图像,并且具有相同的深度(即三个颜色通道)。卷积操作可以表示如下: 给定一个大小为 \( W \times H \times D_{in} \) 的输入体积和一个大小为 \( F \times F \times D_{in} \) 的滤波器,其中 \( D_{in}=3 \),因为有红、绿、蓝三种颜色通道。 #### 计算过程 1. **单个滤波器的卷积运算** 对于每一个位置 (i,j), 输出中的对应元素由下式给出: \[ O(i, j)=\sum _{k=0}^{F-1}\sum _{l=0}^{F-1}\sum _{m=0}^{D_{in}-1}(I(i+k, j+l,m)\cdot K(k,l,m)) \] 这里, - \(O\) 是输出特征图; - \(I\) 表示输入图像; - \(K\) 则代表权重参数构成的核/滤波器; 2. **多通道情况下的卷积** 当涉及到多通道数据如RGB图片时,上述公式扩展到考虑所有通道上的加权求和。具体来说,在每一层上执行相同的操作并沿第三个维度累加以获得最终响应值[^1]。 ```matlab % MATLAB code snippet demonstrating simple convolution operation on an RGB image. w = single(repmat([1 0 -1], [1, 1, 3])); % Define filter weights across all channels w = cat(4, w, -w); % Stack filters together into a tensor form y = vl_nnconv(x, w, []); % Perform convolution between input 'x' and weight matrix 'w' z = vl_nnrelu(y); % Apply ReLU activation function after convolution step ``` 这段MATLAB代码展示了如何定义跨所有色彩平面共享的一组过滤器权重,并将其应用于输入图像 `x` 上来进行标准二维离散卷积运算[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值