本文整理汇总了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