本文整理匯總了Python中torch.nn.Dropout2d方法的典型用法代碼示例。如果您正苦於以下問題:Python nn.Dropout2d方法的具體用法?Python nn.Dropout2d怎麽用?Python nn.Dropout2d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.nn
的用法示例。
在下文中一共展示了nn.Dropout2d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self):
super(Model2, self).__init__()
# fine tuning the ResNet helped significantly with the accuracy
base_model = MyResNet(BasicBlock, [2, 2, 2, 2])
base_model.load_state_dict(model_zoo.load_url(model_urls['resnet18']))
# code needed to deactivate fine tuning of resnet
#for param in base_model.parameters():
# param.requires_grad = False
self.base_model = base_model
self.drop0 = nn.Dropout2d(0.05)
self.conv1 = nn.Conv2d(512, 256, 3, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(256)
self.drop1 = nn.Dropout2d(0.05)
self.conv2 = nn.Conv2d(256, 128, 3, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(128)
self.drop2 = nn.Dropout2d(0.05)
self.conv3 = nn.Conv2d(128, 1+9, 3, padding=1, bias=False)
示例2: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, n_channel, drop_rate, dilated):
super().__init__()
self.conv3x1_1 = nn.Conv2d(n_channel, n_channel, (3, 1), stride=1, padding=(1, 0), bias=True)
self.conv1x3_1 = nn.Conv2d(n_channel, n_channel, (1, 3), stride=1, padding=(0, 1), bias=True)
self.conv3x1_2 = nn.Conv2d(n_channel, n_channel, (3, 1), stride=1, padding=(1 * dilated, 0), bias=True,
dilation=(dilated, 1))
self.conv1x3_2 = nn.Conv2d(n_channel, n_channel, (1, 3), stride=1, padding=(0, 1 * dilated), bias=True,
dilation=(1, dilated))
self.bn1 = nn.BatchNorm2d(n_channel, eps=1e-03)
self.bn2 = nn.BatchNorm2d(n_channel, eps=1e-03)
self.relu = nn.ReLU(inplace=True)
self.dropout = nn.Dropout2d(drop_rate)
示例3: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, in_channels=2048, key_channels=512, value_channels=2048, height=224, width=304):
super(SADecoder, self).__init__()
out_channels = 512
self.saconv = SelfAttentionBlock_(in_channels, key_channels, value_channels)
self.image_context = nn.Sequential(OrderedDict([
('avgpool', nn.AvgPool2d((height // 8, width // 8), padding=0)),
('dropout', nn.Dropout2d(0.5, inplace=True)),
('reshape1', Reshape(2048)),
('linear1', nn.Linear(2048, 512)),
('relu1', nn.ReLU(inplace=True)),
('linear2', nn.Linear(512, 512)),
('relu2', nn.ReLU(inplace=True)),
('reshape2', Reshape(512, 1, 1)),
('upsample', nn.Upsample(size=(height // 8, width // 8), mode='bilinear', align_corners=True))]))
self.merge = nn.Sequential(OrderedDict([
('dropout1', nn.Dropout2d(0.5, inplace=True)),
('conv1', nn.Conv2d(value_channels+out_channels, value_channels, kernel_size=1, stride=1)),
('relu', nn.ReLU(inplace=True)),
('dropout2', nn.Dropout2d(0.5, inplace=False))]))
示例4: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self):
super(Network, self).__init__()
self.feature = nn.Sequential()
self.feature.add_module('f_conv1', nn.Conv2d(3, 64, kernel_size=5))
self.feature.add_module('f_bn1', nn.BatchNorm2d(64))
self.feature.add_module('f_pool1', nn.MaxPool2d(2))
self.feature.add_module('f_relu1', nn.ReLU(True))
self.feature.add_module('f_conv2', nn.Conv2d(64, 50, kernel_size=5))
self.feature.add_module('f_bn2', nn.BatchNorm2d(50))
self.feature.add_module('f_drop1', nn.Dropout2d())
self.feature.add_module('f_pool2', nn.MaxPool2d(2))
self.feature.add_module('f_relu2', nn.ReLU(True))
self.class_classifier = nn.Sequential()
self.class_classifier.add_module('c_fc1', nn.Linear(50 * 5 * 5, 100))
self.class_classifier.add_module('c_bn1', nn.BatchNorm1d(100))
self.class_classifier.add_module('c_relu1', nn.ReLU(True))
self.class_classifier.add_module('c_drop1', nn.Dropout2d())
self.class_classifier.add_module('c_fc2', nn.Linear(100, 500))
self.class_classifier.add_module('c_bn2', nn.BatchNorm1d(500))
self.class_classifier.add_module('c_relu2', nn.ReLU(True))
self.class_classifier.add_module('c_fc3', nn.Linear(500, 10))
示例5: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, num_classes, input_channels=3, base_size=32, dropout=0.25):
super(FeatureExtractor, self).__init__()
self.input_channels = input_channels
self.base_size = base_size
s = base_size
self.dropout = dropout
self.input_conv = BasicConv2d(input_channels, s, 1)
self.conv_1 = BasicConv2d(s * 1, s * 1, 3, padding=1)
self.conv_2 = BasicConv2d(s * 1, s * 1, 3, padding=1)
self.conv_3 = BasicConv2d(s * 1, s * 2, 3, padding=1)
self.conv_4 = BasicConv2d(s * 2, s * 2, 3, padding=1)
self.conv_5 = BasicConv2d(s * 2, s * 4, 3, padding=1)
self.conv_6 = BasicConv2d(s * 4, s * 4, 3, padding=1)
self.pool = nn.MaxPool2d(2, 2)
self.dropout2d = nn.Dropout2d(p=dropout)
self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
self.fc = nn.Linear(s * 4, num_classes)
示例6: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, features, inner_features=256, out_features=512, dilations=(12, 24, 36)):
super(ASPPModule, self).__init__()
self.conv1 = nn.Sequential(nn.AdaptiveAvgPool2d((1,1)),
nn.Conv2d(features, inner_features, kernel_size=1, padding=0, dilation=1, bias=False),
InPlaceABNSync(inner_features))
self.conv2 = nn.Sequential(nn.Conv2d(features, inner_features, kernel_size=1, padding=0, dilation=1, bias=False),
InPlaceABNSync(inner_features))
self.conv3 = nn.Sequential(nn.Conv2d(features, inner_features, kernel_size=3, padding=dilations[0], dilation=dilations[0], bias=False),
InPlaceABNSync(inner_features))
self.conv4 = nn.Sequential(nn.Conv2d(features, inner_features, kernel_size=3, padding=dilations[1], dilation=dilations[1], bias=False),
InPlaceABNSync(inner_features))
self.conv5 = nn.Sequential(nn.Conv2d(features, inner_features, kernel_size=3, padding=dilations[2], dilation=dilations[2], bias=False),
InPlaceABNSync(inner_features))
self.bottleneck = nn.Sequential(
nn.Conv2d(inner_features * 5, out_features, kernel_size=1, padding=0, dilation=1, bias=False),
InPlaceABNSync(out_features),
nn.Dropout2d(0.1)
)
示例7: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, in_channels, middle_channels, out_channels, dropout=False):
super(First2D, self).__init__()
layers = [
nn.Conv2d(in_channels, middle_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(middle_channels),
nn.ReLU(inplace=True),
nn.Conv2d(middle_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU(inplace=True)
]
if dropout:
assert 0 <= dropout <= 1, 'dropout must be between 0 and 1'
layers.append(nn.Dropout2d(p=dropout))
self.first = nn.Sequential(*layers)
示例8: setup_net
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def setup_net(self):
self.conv_params = nn.Sequential(
nn.Conv2d(self.num_channels, 20, kernel_size=5),
nn.MaxPool2d(2),
nn.ReLU(),
nn.Conv2d(20, 50, kernel_size=5),
nn.Dropout2d(p=0.5),
nn.MaxPool2d(2),
nn.ReLU(),
)
self.fc_params = nn.Linear(50*4*4, 500)
self.classifier = nn.Sequential(
nn.ReLU(),
nn.Dropout(p=0.5),
nn.Linear(500, self.num_cls)
)
示例9: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, input_dim=4096, output_dim=2, pretrained=False, weights_init=''):
super().__init__()
dim1 = 1024 if input_dim==4096 else 512
dim2 = int(dim1/2)
self.D = nn.Sequential(
nn.Conv2d(input_dim, dim1, 1),
nn.Dropout2d(p=0.5),
nn.ReLU(inplace=True),
nn.Conv2d(dim1, dim2, 1),
nn.Dropout2d(p=0.5),
nn.ReLU(inplace=True),
nn.Conv2d(dim2, output_dim, 1)
)
if pretrained and weights_init is not None:
self.load_weights(weights_init)
示例10: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, chann, dropprob, dilated):
super().__init__()
self.conv3x1_1 = nn.Conv2d(chann, chann, (3, 1), stride=1, padding=(1,0), bias=True)
self.conv1x3_1 = nn.Conv2d(chann, chann, (1,3), stride=1, padding=(0,1), bias=True)
self.bn1 = nn.BatchNorm2d(chann, eps=1e-03)
self.conv3x1_2 = nn.Conv2d(chann, chann, (3, 1), stride=1, padding=(1*dilated,0), bias=True, dilation = (dilated,1))
self.conv1x3_2 = nn.Conv2d(chann, chann, (1,3), stride=1, padding=(0,1*dilated), bias=True, dilation = (1, dilated))
self.bn2 = nn.BatchNorm2d(chann, eps=1e-03)
self.dropout = nn.Dropout2d(dropprob)
示例11: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, n_classes, n_layers):
super().__init__()
backbone = resnet(n_layers, settings.STRIDE)
self.extractor = nn.Sequential(
backbone.conv1,
backbone.bn1,
backbone.relu,
backbone.maxpool,
backbone.layer1,
backbone.layer2,
backbone.layer3,
backbone.layer4)
self.fc0 = ConvBNReLU(2048, 512, 3, 1, 1, 1)
self.emau = EMAU(512, 64, settings.STAGE_NUM)
self.fc1 = nn.Sequential(
ConvBNReLU(512, 256, 3, 1, 1, 1),
nn.Dropout2d(p=0.1))
self.fc2 = nn.Conv2d(256, n_classes, 1)
# Put the criterion inside the model to make GPU load balanced
self.crit = CrossEntropyLoss2d(ignore_index=settings.IGNORE_LABEL,
reduction='none')
示例12: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, channel, dilate=1, drop_prob=0.01):
super(SSnbt, self).__init__()
channel = channel // 2
self.left = nn.Sequential(
nn.Conv2d(channel, channel, (3, 1), (1, 1), (1, 0)), nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (1, 3), (1, 1), (0, 1), bias=False),
nn.BatchNorm2d(channel), nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (3, 1), (1, 1), (dilate, 0), dilation=(dilate, 1)),
nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (1, 3), (1, 1), (0, dilate), dilation=(1, dilate), bias=False),
nn.BatchNorm2d(channel), nn.Dropout2d(drop_prob, inplace=True)
)
self.right = nn.Sequential(
nn.Conv2d(channel, channel, (1, 3), (1, 1), (0, 1)), nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (3, 1), (1, 1), (1, 0), bias=False),
nn.BatchNorm2d(channel), nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (1, 3), (1, 1), (0, dilate), dilation=(1, dilate)),
nn.ReLU(inplace=True),
nn.Conv2d(channel, channel, (3, 1), (1, 1), (dilate, 0), dilation=(dilate, 1), bias=False),
nn.BatchNorm2d(channel), nn.Dropout2d(drop_prob, inplace=True)
)
示例13: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, in_channels, out_channels, key_channels, value_channels,
scales=([1]), norm_layer=nn.BatchNorm2d, **kwargs):
super(PyramidOCModule, self).__init__()
self.stages = nn.ModuleList([
PyramidAttentionBlock(in_channels, out_channels, key_channels, value_channels, scale, norm_layer, **kwargs)
for scale in scales])
self.up_dr = nn.Sequential(
nn.Conv2d(in_channels, in_channels * len(scales), 1),
norm_layer(in_channels * len(scales)),
nn.ReLU(True)
)
self.project = nn.Sequential(
nn.Conv2d(in_channels * len(scales) * 2, out_channels, 1),
norm_layer(out_channels),
nn.ReLU(True),
nn.Dropout2d(0.05)
)
示例14: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, in_channels, out_channels, norm_layer):
super(_RCCAModule, self).__init__()
self.recurrence = cfg.MODEL.CCNET.RECURRENCE
inter_channels = in_channels // 4
self.conva = nn.Sequential(
nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),
norm_layer(inter_channels),
nn.ReLU(True))
self.cca = CrissCrossAttention(inter_channels)
self.convb = nn.Sequential(
nn.Conv2d(inter_channels, inter_channels, 3, padding=1, bias=False),
norm_layer(inter_channels),
nn.ReLU(True))
self.bottleneck = nn.Sequential(
nn.Conv2d(in_channels + inter_channels, out_channels, 3, padding=1, bias=False),
norm_layer(out_channels),
nn.Dropout2d(0.1))
示例15: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import Dropout2d [as 別名]
def __init__(self, in_channels, inter_channels, out_channels, norm_layer=nn.BatchNorm2d, **kwargs):
super(UpsamplingBottleneck, self).__init__()
self.conv = nn.Sequential(
nn.Conv2d(in_channels, out_channels, 1, bias=False),
norm_layer(out_channels)
)
self.upsampling = nn.MaxUnpool2d(2)
self.block = nn.Sequential(
nn.Conv2d(in_channels, inter_channels, 1, bias=False),
norm_layer(inter_channels),
nn.PReLU(),
nn.ConvTranspose2d(inter_channels, inter_channels, 2, 2, bias=False),
norm_layer(inter_channels),
nn.PReLU(),
nn.Conv2d(inter_channels, out_channels, 1, bias=False),
norm_layer(out_channels),
nn.Dropout2d(0.1)
)
self.act = nn.PReLU()