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])
相关推荐
rayyy920 小时前
神经网络拟合高频信号实验
人工智能·pytorch·神经网络
团象科技20 小时前
跨境业务频繁卡顿遇瓶颈?谷歌云AI算力补齐链路短板破局增收
大数据·人工智能·深度学习
AI医影跨模态组学20 小时前
Eur Radiol 哈尔滨医科大学附属肿瘤医院王瑞涛团队:多模态深度学习探究肿瘤与内脏脂肪对结直肠癌隐匿性腹膜转移的影响
人工智能·深度学习·论文·医学影像·影像组学
香蕉鼠片20 小时前
CUDA、PyTorch、Transformers、PEFT 全栈详解
人工智能·pytorch·python
MediaTea20 小时前
PyTorch:张量与基础计算模块
人工智能·pytorch·python·深度学习·机器学习
明月醉窗台1 天前
深度学习(17)YOLO训练中的超参数详解
人工智能·深度学习·yolo
t_hj1 天前
大模型微调
人工智能·python·深度学习
z小猫不吃鱼1 天前
06 ViT 为什么需要大规模数据?从归纳偏置理解 ViT 的训练特点
深度学习·计算机视觉·cnn
nebula-AI1 天前
人工智能导论:模型与算法(核心技术)
人工智能·深度学习·神经网络·算法·机器学习·集成学习·sklearn