本文整理匯總了Python中torchvision.models.resnet.conv3x3方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet.conv3x3方法的具體用法?Python resnet.conv3x3怎麽用?Python resnet.conv3x3使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchvision.models.resnet
的用法示例。
在下文中一共展示了resnet.conv3x3方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import conv3x3 [as 別名]
def __init__(self, in_planes, out_planes, nb_compressions=0, norm_layer=None):
if norm_layer is None:
norm_layer = nn.BatchNorm2d
layers = [conv3x3(in_planes, out_planes),
norm_layer(out_planes),
nn.LeakyReLU(0.1, inplace=True)]
for _ in range(nb_compressions):
layers.extend([conv1x1(out_planes, in_planes),
norm_layer(in_planes),
nn.LeakyReLU(0.1, inplace=True),
conv3x3(in_planes, out_planes),
norm_layer(out_planes),
nn.LeakyReLU(0.1, inplace=True)])
super().__init__(*layers)
示例2: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import conv3x3 [as 別名]
def __init__(self, config_channels, prefix, channels, stride=1):
nn.Module.__init__(self)
channels_in = config_channels.channels
self.conv1 = conv3x3(config_channels.channels, config_channels(channels, '%s.conv1.weight' % prefix), stride)
self.bn1 = nn.BatchNorm2d(config_channels.channels)
self.relu = nn.ReLU(inplace=True)
self.conv2 = conv3x3(config_channels.channels, config_channels(channels, '%s.conv2.weight' % prefix))
self.bn2 = nn.BatchNorm2d(config_channels.channels)
if stride > 1 or channels_in != config_channels.channels:
downsample = []
downsample.append(nn.Conv2d(channels_in, config_channels.channels, kernel_size=1, stride=stride, bias=False))
downsample.append(nn.BatchNorm2d(config_channels.channels))
self.downsample = nn.Sequential(*downsample)
else:
self.downsample = None
示例3: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import conv3x3 [as 別名]
def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,
base_width=4, dilation=1, scale=4, first_block=False, norm_layer=None):
"""Implements a residual block
Args:
inplanes (int): input channel dimensionality
planes (int): output channel dimensionality
stride (int): stride used for conv3x3
downsample (torch.nn.Module): module used for downsampling
groups: num of convolution groups
base_width: base width
dilation (int): dilation rate of conv3x3
scale (int): scaling ratio for cascade convs
first_block (bool): whether the block is the first to be placed in the conv layer
norm_layer (torch.nn.Module): norm layer to be used in blocks
"""
super(Res2Block, self).__init__()
if norm_layer is None:
norm_layer = nn.BatchNorm2d
width = int(planes * (base_width / 64.)) * groups
self.conv1 = conv1x1(inplanes, width * scale)
self.bn1 = norm_layer(width * scale)
# If scale == 1, single conv else identity & (scale - 1) convs
nb_branches = max(scale, 2) - 1
if first_block:
self.pool = nn.AvgPool2d(kernel_size=3, stride=stride, padding=1)
self.convs = nn.ModuleList([conv3x3(width, width, stride, groups, dilation)
for _ in range(nb_branches)])
self.bns = nn.ModuleList([norm_layer(width) for _ in range(nb_branches)])
self.first_block = first_block
self.scale = scale
self.conv3 = conv1x1(width * scale, planes * self.expansion)
self.bn3 = norm_layer(planes * self.expansion)
self.relu = nn.ReLU(inplace=False)
self.downsample = downsample
示例4: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import conv3x3 [as 別名]
def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,
base_width=4, dilation=1, scale=4, first_block=False, norm_layer=None):
"""Implements a residual block
Args:
inplanes (int): input channel dimensionality
planes (int): output channel dimensionality
stride (int): stride used for conv3x3
downsample (torch.nn.Module): module used for downsampling
groups: num of convolution groups
base_width: base width
dilation (int): dilation rate of conv3x3
scale (int): scaling ratio for cascade convs
first_block (bool): whether the block is the first to be placed in the conv layer
norm_layer (torch.nn.Module): norm layer to be used in blocks
"""
super(Res2Block, self).__init__()
if norm_layer is None:
norm_layer = nn.BatchNorm2d
width = int(planes * (base_width / 64.)) * groups
self.conv1 = conv1x1(inplanes, width * scale)
self.bn1 = norm_layer(width * scale)
# If scale == 1, single conv else identity & (scale - 1) convs
nb_branches = max(scale, 2) - 1
if first_block:
self.pool = nn.AvgPool2d(kernel_size=3, stride=stride, padding=1)
self.convs = nn.ModuleList([conv3x3(width, width, stride, groups, dilation)
for _ in range(nb_branches)])
self.bns = nn.ModuleList([norm_layer(width) for _ in range(nb_branches)])
self.first_block = first_block
self.scale = scale
self.conv3 = conv1x1(width * scale, planes * self.expansion)
self.relu = Mish() #nn.ReLU(inplace=False)
self.bn3 = norm_layer(planes * self.expansion) #bn reverse
self.downsample = downsample
示例5: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import conv3x3 [as 別名]
def __init__(self, inplanes, planes, stride=1, downsample=None):
super(BasicBlockV2, self).__init__()
self.relu = nn.ReLU(inplace=True)
self.bn1 = nn.BatchNorm2d(inplanes)
self.conv1 = conv3x3(inplanes, planes, stride=stride)
self.bn2 = nn.BatchNorm2d(planes)
self.conv2 = conv3x3(planes, planes, stride=1)
self.downsample = downsample
self.stride = stride