1.conv2d的实现:
接口定义:
class torch.nn.Conv2d(in_channels,
out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1,
bias=True)
参数说明:
- in_channels (int) – 输入通道个数。
- out_channels (int) – 输出通道个数 。有多少个out_channels,就需要多少个卷积(也就是卷积核的数量)
- kernel_size(int or tuple) –
卷积核的尺寸;卷积核的第二个维度由in_channels决定,所以实际上卷积核的大小为kernel_size * in_channels - stride (int or tuple, optional) – 卷积操作的步长, 默认:1
- padding (int or tuple, optional) – 输入数据各维度各边上要补齐0的层数,默认: 0
- dilation (int or tuple, optional) – 卷积核各元素之间的距离,默认: 1
- groups (int, optional) – 输入通道与输出通道之间相互隔离的连接的个数, 默认:1
- bias (bool, optional) – 如果被置为True,向输出增加一个偏差量,此偏差是可学习参数。 默认:True
channel的理解:

- 最初输入的图片样本的 channels ,取决于图片类型,比如RGB;
- 卷积操作完成后输出的 out_channels ,取决于卷积核的数量。此时的 out_channels 也会作为下一次卷积时的卷积核的 in_channels;
- 卷积核中的 in_channels ,刚刚2中已经说了,就是上一次卷积的 out_channels,如果是第一次做卷积,就是1中样本图片的 channels 。
2.pytorch如何微调fine tuning:
在加载了预训练模型参数之后,需要finetuning模型,可以使用不同的方式finetune:
局部微调: 加载了模型参数后,只想调节最后几层,其它层不训练,也就是不进行梯度计算,pytorch提供的requires_grad使得对训练的控制变得非常简单。
model = torchvision.models.resnet18(pretrained=True)
for param in model.parameters():
param.requires_grad = False
1445




被折叠的 条评论
为什么被折叠?



