Class USeDropout(nn.Module):
def __init__(self):
super(DropoutFC, self).__init__()
self.fc = nn.Linear(100,20)
self.dropout = nn.Dropout(p=0.5)
def forward(self, input):
out = self.fc(input)
out = self.dropout(out)
return out
Net = USeDropout()
Net.train()
示例代码如上,直接调用nn.Dropout即可,但是注意在调用时要将模型参数传入。