常用的神经网络层:
1 conv2d
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True)
注意是个类,要创建对象后再使用。
参数中的kernel_size, stride, padding, dilation的值,可以为int,也可以为tuple。是int的时候,就代表长宽相等。
Input size为(N,C_in,H,W);
Output size为(N,C_out,H_out,W_out).
其中,N为batch size,即样本数,C为channel数,H为height,W为width
2 全连接层/线性层 linear
torch.nn.Linear(in_features, out_features, bias=True)
Input size = (N,∗,in_features)
Output size = (N,∗,out_features)
例如:
self.fc1 = nn.Linear(16*53*53,120)
self.fc2 = nn.Linear(120,84)
3 Pooling (2D) 层
torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)
torch.nn.AvgPool2d(kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True)