我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用torch.nn.Dropout3d()。
def test_Dropout3d(self): b = random.randint(1, 5) w = random.randint(1, 5) h = random.randint(1, 5) d = random.randint(1, 2) num_features = 1000 input = torch.Tensor(num_features, b, d, w, h) self._test_dropout(nn.Dropout3d, input)
def __init__(self, inChans, nConvs, elu, dropout=False): super(DownTransition, self).__init__() outChans = 2*inChans self.down_conv = nn.Conv3d(inChans, outChans, kernel_size=2, stride=2) self.bn1 = ContBatchNorm3d(outChans) self.do1 = passthrough self.relu1 = ELUCons(elu, outChans) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
def __init__(self, inChans, outChans, nConvs, elu, dropout=False): super(UpTransition, self).__init__() self.up_conv = nn.ConvTranspose3d(inChans, outChans // 2, kernel_size=2, stride=2) self.bn1 = ContBatchNorm3d(outChans // 2) self.do1 = passthrough self.do2 = nn.Dropout3d() self.relu1 = ELUCons(elu, outChans // 2) self.relu2 = ELUCons(elu, outChans) if dropout: self.do1 = nn.Dropout3d() self.ops = _make_nConv(outChans, nConvs, elu)
def test_invalid_dropout_p(self): v = Variable(torch.ones(1)) self.assertRaises(ValueError, lambda: nn.Dropout(-0.1)) self.assertRaises(ValueError, lambda: nn.Dropout(1.1)) self.assertRaises(ValueError, lambda: nn.Dropout2d(-0.1)) self.assertRaises(ValueError, lambda: nn.Dropout2d(1.1)) self.assertRaises(ValueError, lambda: nn.Dropout3d(-0.1)) self.assertRaises(ValueError, lambda: nn.Dropout3d(1.1)) self.assertRaises(ValueError, lambda: F.dropout(v, -0.1)) self.assertRaises(ValueError, lambda: F.dropout(v, 1.1))
def dropout(p=0.5, inplace=False, dim=2): #TODO: in the future some preprocessing goes here in_dim = dim if in_dim == 1: return nn.Dropout(p=p, inplace=inplace) elif in_dim == 2: return nn.Dropout2d(p=p, inplace=inplace) elif in_dim == 3: return nn.Dropout3d(p=p, inplace=inplace) # convolutional # Regular convolution