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])
相关推荐
NCU_wander23 分钟前
显存和算力的关系
深度学习
蒋星熠1 小时前
脑机接口(BCI):从信号到交互的工程实践
人工智能·python·神经网络·算法·机器学习·ai·交互
数智顾问2 小时前
Transformer模型:深度解析自然语言处理的革命性架构——从注意力机制到基础架构拆解
人工智能·rnn·深度学习
春末的南方城市2 小时前
港大和字节携手打造WorldWeaver:以统一建模方案整合感知条件,为长视频生成领域带来质量与一致性双重飞跃。
人工智能·深度学习·机器学习·计算机视觉·aigc·音视频
gladiator+4 小时前
深度学习--行人重识别技术(超分辨率网络+ResNet101)附数据集
人工智能·深度学习
努力还债的学术吗喽5 小时前
PyTorch nn.Linear 终极详解:从零理解线性层的一切(含可视化+完整代码)
人工智能·pytorch·python·深度学习·基础组件·线性层·nn.linear
无风听海5 小时前
神经网络之sigmoid激活函数
人工智能·深度学习·神经网络
wan5555cn6 小时前
AI视频生成技术:从想象到现实的视觉革命
人工智能·笔记·深度学习·算法·音视频
极客代码6 小时前
第五篇:后端优化——位姿图的灵魂--从图优化到滑动窗口的联合状态估计
python·深度学习·计算机视觉·视觉里程计·slam·回环检测·地图构建
charieli-fh6 小时前
LoRA 高效微调大语言模型全流程:从原理、实践到参数调优
人工智能·深度学习·大模型·大语言模型