Convolution operation and Grouped Convolution

filter is not the kernel,but the kernels.that's mean a filter include one or two or more kernels.that's depend the input feature map and the output feature maps. for example, if we have an image, the shape of image is (32,32), has 3 channels,that's RGB.so the input feature maps is (1,3,32,32).the format of input feature maps is (batch_size,in_channels,H_in,W_in),the output feature maps is(batch_size,out_channels,H_out,W_out),there is a formulation for out_H,out_W.

p is padding,default is 0. s is stride,default is 1.

so, we get the the Height and Width of output feature map,but how about the output channels?how do we get the output channels from the input channels.Or,In other words,what's the convolution operation?

first,i'll give the conclusion and explain it later.

so the weight size is (filters, kernels of filter,H_k,W_k),the format of weight vector is (C_out,C_in,H_k,W_k)

that's mean we have C_out filters, and each filter has C_in kernels.if you don't understand, look through this link,it will tell you the specific operations.

as we go deeper into the convolution this dimension of channels increases very rapidly thus increases complexity. The spatial dimensions(means height and weight) have some degree of effect on the complexity but in deeper layers, they are not really the cause of concern. Thus in bigger neural networks, the filter groups will dominate.so,the grouped convolution was proposed,you can access to this link for more details.

you can try this code for validation.

python 复制代码
import torch.nn as nn
import torch

# 假设输入特征图的大小为 (batch_size, in_channels, H, W)
batch_size = 1
in_channels = 4
out_channels = 2
H = 6
W = 6

# 定义1x1卷积层,输入通道数为in_channels,输出通道数为out_channels
conv = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0)

# 对输入特征图进行1x1卷积操作
x = torch.randn(batch_size, in_channels, H, W)
y = conv(x)

# 输入特征图的大小为 (batch_size, in_channels, H, W)
print(x.shape)  # torch.Size([1, 4, 6, 6])
# 输出特征图的大小为 (batch_size, out_channels, H, W)
print(y.size())   # torch.Size([1, 2, 6, 6])
# 获取卷积核的尺寸 (out_channels, in_channels // groups, *kernel_size)
weight_size = conv.weight.size()
print('卷积核的尺寸为:', weight_size)  # torch.Size([2, 4, 1, 1])
相关推荐
问天_观心8 分钟前
深入学习Transformer(二)
深度学习·学习·transformer
richard_first10 小时前
Transformer 与大语言模型:第9章 LayerNorm 归一化层
人工智能·深度学习·机器学习·transformer
咖啡星人k16 小时前
2026 多模态大模型:AI 如何“看图+读字+听音“三合一,MonkeyCode 免费上手
人工智能·深度学习·神经网络·计算机视觉·自然语言处理
johnsong17 小时前
深度拆解:150M循环模型如何用循环推理击败大Transformer
android·深度学习·transformer
txg66617 小时前
LLM 驱动漏洞传播验证:TransferFuzz-Pro 如何自动调试“继承“来的安全债
人工智能·深度学习·安全
Rocky Ding*18 小时前
【三年面试五年模拟】2026-08-18_哔哩哔哩_AI应用岗Agent开发一面面经(含完整答案)
论文阅读·人工智能·深度学习·机器学习·aigc·ai-native·ai agent
小小帅呀18 小时前
学习VLA第3天:训练一个最简单的神经网络
人工智能·神经网络·学习
2601_9578793318 小时前
Seedance排队太久怎么办?2026免排队AI视频工具与替代方案怎么选
大数据·人工智能·深度学习
a1879272183119 小时前
从一条直线到大模型输出一个token(九):输出矩阵与多层堆叠
深度学习·ai·transformer·token·注意力机制·deepseek·多层堆叠
jay神19 小时前
YOLO模型什么时候应该加注意力机制?
人工智能·深度学习·yolo·分类·回归·毕业设计