Pytorch-常用神经网络层
1 2 import torch import torch.nn as nn 1. 线性层 1 2 3 4 5 input = torch.randn(3, 4) #3个样本,每个样本4个特征 linear = nn.Linear(in_features=4, out_features=2) linear(input).shape # torch.Size([3, 2]) 2. 正则化层 2.1 dropout 1 2 3 4 5 6 7 dropout = nn.Dropout(p=0.5) input = torch.randn(3, 4) dropout(input) # tensor([[ 0.0000, -0.0000, -0.5670,...