本文整理匯總了Python中torch.nn.AdaptiveAvgPool3d方法的典型用法代碼示例。如果您正苦於以下問題:Python nn.AdaptiveAvgPool3d方法的具體用法?Python nn.AdaptiveAvgPool3d怎麽用?Python nn.AdaptiveAvgPool3d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torch.nn
的用法示例。
在下文中一共展示了nn.AdaptiveAvgPool3d方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, in_size, out_size, is_batchnorm):
super(UnetGatingSignal3, self).__init__()
self.fmap_size = (4, 4, 4)
if is_batchnorm:
self.conv1 = nn.Sequential(nn.Conv3d(in_size, in_size//2, (1,1,1), (1,1,1), (0,0,0)),
nn.BatchNorm3d(in_size//2),
nn.ReLU(inplace=True),
nn.AdaptiveAvgPool3d(output_size=self.fmap_size),
)
self.fc1 = nn.Linear(in_features=(in_size//2) * self.fmap_size[0] * self.fmap_size[1] * self.fmap_size[2],
out_features=out_size, bias=True)
else:
self.conv1 = nn.Sequential(nn.Conv3d(in_size, in_size//2, (1,1,1), (1,1,1), (0,0,0)),
nn.ReLU(inplace=True),
nn.AdaptiveAvgPool3d(output_size=self.fmap_size),
)
self.fc1 = nn.Linear(in_features=(in_size//2) * self.fmap_size[0] * self.fmap_size[1] * self.fmap_size[2],
out_features=out_size, bias=True)
# initialise the blocks
for m in self.children():
init_weights(m, init_type='kaiming')
示例2: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, block, layers, shortcut_type='B', cardinality=32, num_classes=400):
self.inplanes = 64
super(ResNeXt3D, self).__init__()
self.conv1 = nn.Conv3d(3, 64, kernel_size=7, stride=(1, 2, 2), padding=(3, 3, 3), bias=False)
self.bn1 = nn.BatchNorm3d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=2, padding=1)
self.layer1 = self._make_layer(block, 128, layers[0], shortcut_type, cardinality)
self.layer2 = self._make_layer(block, 256, layers[1], shortcut_type, cardinality, stride=2)
self.layer3 = self._make_layer(block, 512, layers[2], shortcut_type, cardinality, stride=2)
self.layer4 = self._make_layer(block, 1024, layers[3], shortcut_type, cardinality, stride=2)
self.avgpool = nn.AdaptiveAvgPool3d(1)
self.fc = nn.Linear(cardinality * 32 * block.expansion, num_classes)
for m in self.modules():
if isinstance(m, nn.Conv3d):
m.weight = nn.init.kaiming_normal(m.weight, mode='fan_out')
elif isinstance(m, nn.BatchNorm3d):
m.weight.data.fill_(1)
m.bias.data.zero_()
示例3: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self,
block,
layers,
nonlocal_layers,
shortcut_type='A',
num_classes=339):
self.inplanes = 64
super().__init__()
self.conv1 = nn.Conv3d(3, 64, kernel_size=7, stride=(1, 2, 2), padding=(3, 3, 3), bias=False)
self.bn1 = nn.BatchNorm3d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=2, padding=1)
self.layer1 = self._make_layer(block, 64, layers[0], nonlocal_layers[0], shortcut_type)
self.layer2 = self._make_layer(block, 128, layers[1], nonlocal_layers[1], shortcut_type, stride=2)
self.layer3 = self._make_layer(block, 256, layers[2], nonlocal_layers[2], shortcut_type, stride=2)
self.layer4 = self._make_layer(block, 512, layers[3], nonlocal_layers[3], shortcut_type, stride=2)
self.avgpool = nn.AdaptiveAvgPool3d(1)
self.last_linear = nn.Linear(512 * block.expansion, num_classes)
self.init_weights()
示例4: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self,
block,
layers,
k=1,
shortcut_type='B',
num_classes=400):
self.inplanes = 64
super(WideResNet, self).__init__()
self.conv1 = nn.Conv3d(3, 64, kernel_size=7, stride=(1, 2, 2), padding=(3, 3, 3), bias=False)
self.bn1 = nn.BatchNorm3d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=2, padding=1)
self.layer1 = self._make_layer(block, 64 * k, layers[0], shortcut_type)
self.layer2 = self._make_layer(block, 128 * k, layers[1], shortcut_type, stride=2)
self.layer3 = self._make_layer(block, 256 * k, layers[2], shortcut_type, stride=2)
self.layer4 = self._make_layer(block, 512 * k, layers[3], shortcut_type, stride=2)
self.avgpool = nn.AdaptiveAvgPool3d(1)
self.fc = nn.Linear(512 * k * block.expansion, num_classes)
for m in self.modules():
if isinstance(m, nn.Conv3d):
nn.init.kaiming_normal_(m.weight, mode='fan_out')
elif isinstance(m, nn.BatchNorm3d):
m.weight.data.fill_(1)
m.bias.data.zero_()
示例5: forward
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def forward(self, input, lateral):
x = self.conv1(input)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = torch.cat([x, lateral[0]], dim=1)
x = self.res2(x)
x = torch.cat([x, lateral[1]], dim=1)
x = self.res3(x)
x = torch.cat([x, lateral[2]], dim=1)
x = self.res4(x)
x = torch.cat([x, lateral[3]], dim=1)
x = self.res5(x)
x = nn.AdaptiveAvgPool3d(1)(x)
x = x.view(-1, x.size(1))
return x
示例6: slow_path
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def slow_path(self, input, lateral):
x = self.slow_conv1(input)
x = self.slow_bn1(x)
x = self.slow_relu(x)
x = self.slow_maxpool(x)
x = torch.cat([x, lateral[0]], dim=1)
x = self.slow_res2(x)
x = torch.cat([x, lateral[1]], dim=1)
x = self.slow_res3(x)
x = torch.cat([x, lateral[2]], dim=1)
x = self.slow_res4(x)
x = torch.cat([x, lateral[3]], dim=1)
x = self.slow_res5(x)
x = nn.AdaptiveAvgPool3d(1)(x)
x = x.view(-1, x.size(1))
return x
示例7: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self,in_channel,out_channel):
super(S3D_G_block, self).__init__()
# out_channel=[1x1x1,3x3x3_reduce,3x3x3,3x3x3_reduce,3x3x3,pooling_reduce]
self.branch1 = BasicConv3d(in_channel,out_channel[0], kernel_size=(3,1,1), stride=1, padding=(1,0,0))
self.branch2 = nn.Sequential(
BasicConv3d(in_channel, out_channel[1], kernel_size=1, stride=1),
BasicConv3d(out_channel[1], out_channel[1],kernel_size=(1,3,3), stride=1, padding=(0,1,1)),
BasicConv3d(out_channel[1], out_channel[2], kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))
)
self.branch3 = nn.Sequential(
BasicConv3d(in_channel, out_channel[3], kernel_size=1, stride=1),
BasicConv3d(out_channel[3], out_channel[3], kernel_size=(1, 3, 3), stride=1, padding= (0, 1, 1)),
BasicConv3d(out_channel[3], out_channel[4], kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))
)
self.branch4 = nn.Sequential(
nn.MaxPool3d(kernel_size=3,stride=1,padding=1),
BasicConv3d(in_channel, out_channel[5], kernel_size=(3,1,1), stride=1,padding=(1,0,0))
)
self.squeeze = nn.AdaptiveAvgPool3d(1)
# we replace weight matrix with 1D conv to reduce the para
self.excitation = nn.Conv1d(1, 1, (3,1,1), stride=1,padding=(1,0,0))
self.sigmoid=nn.Sigmoid()
示例8: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self,non_layers=[0,1,1,1],stripes=[16,16,16,16],non_type='normal',temporal=None):
super(Resnet50_NL,self).__init__()
original = models.resnet50(pretrained=True).state_dict()
if non_type == 'normal':
self.backbone = res.ResNet_Video_nonlocal(last_stride=1,non_layers=non_layers)
elif non_type == 'stripe':
self.backbone = res.ResNet_Video_nonlocal_stripe(last_stride = 1, non_layers=non_layers, stripes=stripes)
elif non_type == 'hr':
self.backbone = res.ResNet_Video_nonlocal_hr(last_stride = 1, non_layers=non_layers, stripes=stripes)
elif non_type == 'stripe_hr':
self.backbone = res.ResNet_Video_nonlocal_stripe_hr(last_stride = 1, non_layers=non_layers, stripes=stripes)
for key in original:
if key.find('fc') != -1:
continue
self.backbone.state_dict()[key].copy_(original[key])
del original
self.temporal = temporal
if self.temporal == 'Done':
self.avgpool = nn.AdaptiveAvgPool3d(1)
示例9: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, adaptive_pool=True, spatial_type='avg', spatial_size=1, temporal_size=1):
super(SlowFastSpatialTemporalModule, self).__init__()
self.adaptive_pool = adaptive_pool
assert spatial_type in ['avg']
self.spatial_type = spatial_type
self.spatial_size = spatial_size if not isinstance(spatial_size, int) else (spatial_size, spatial_size)
self.temporal_size = temporal_size
self.pool_size = (self.temporal_size, ) + self.spatial_size
if self.adaptive_pool:
if self.spatial_type == 'avg':
self.op = nn.AdaptiveAvgPool3d(self.pool_size)
else:
raise NotImplementedError
示例10: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, channels,
branch=2,
ratio=4,
stride=1,
groups=1,
min_channels=32,
norm_type=nn.BatchNorm3d,
act_type=nn.ReLU):
super(SKConv3d, self).__init__()
dim = max(channels // ratio, min_channels)
self.branch = branch
self.convs = nn.ModuleList([])
for i in range(branch):
self.convs.append(
ConvBnAct3d(channels, channels, kernel_size=3 + i * 2,
padding=i + 1, stride=stride, groups=groups,
norm_type=norm_type,
act_type=act_type)
)
self.avg_pool = nn.AdaptiveAvgPool3d(1)
self.fc = nn.Linear(channels, dim)
self.fcs = nn.ModuleList([])
for i in range(branch):
self.fcs.append(nn.Linear(dim, channels))
self.softmax = nn.Softmax(dim=1)
示例11: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, block, layers, num_classes=400, num_channels=3, decomposed=True):
self.inplanes = 64
super(R3D, self).__init__()
self.decomposed = decomposed
self.conv1 = make_conv(num_channels, 64, middle_planes=45, kernel_size=(3, 7, 7), stride=(1, 2, 2),
decomposed=decomposed)
self.bn1 = nn.BatchNorm3d(64)
self.relu = nn.ReLU(inplace=True)
# self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
self.layer1 = self._make_layer(block, 64, layers[0])
self.layer2 = self._make_layer(block, 128, layers[1], downsample=True)
self.layer3 = self._make_layer(block, 256, layers[2], downsample=True)
self.layer4 = self._make_layer(block, 512, layers[3], downsample=True)
self.avgpool = nn.AdaptiveAvgPool3d((1, 1, 1))
self.fc = nn.Linear(512 * block.expansion, num_classes)
for m in self.modules():
if isinstance(m, nn.Conv3d):
torch.nn.init.kaiming_normal_(m.weight, nonlinearity='relu')
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
示例12: SlowPath
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def SlowPath(self, input, lateral):
x = self.slow_conv1(input)
x = self.slow_bn1(x)
x = self.slow_relu(x)
x = self.slow_maxpool(x)
x = torch.cat([x, lateral[0]],dim=1)
x = self.slow_res2(x)
x = torch.cat([x, lateral[1]],dim=1)
x = self.slow_res3(x)
x = torch.cat([x, lateral[2]],dim=1)
x = self.slow_res4(x)
x = torch.cat([x, lateral[3]],dim=1)
x = self.slow_res5(x)
#x = nn.AdaptiveAvgPool3d(1)(x)
#x = x.view(-1, x.size(1))
return x
示例13: forward
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def forward(self,fast_input,slow_input):
fast_output=self.fast_res5(fast_input)
slow_output=self.slow_res5(slow_input)
x1 = nn.AdaptiveAvgPool3d(1)(fast_output)
x2 = nn.AdaptiveAvgPool3d(1)(slow_output)
x1 = x1.view(-1, x1.size(1))
x2 = x2.view(-1, x2.size(1))
x = torch.cat([x1, x2], dim=1)
return x
示例14: fast_path
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def fast_path(self, input):
lateral = []
x = self.fast_conv1(input)
x = self.fast_bn1(x)
x = self.fast_relu(x)
pool1 = self.fast_maxpool(x)
lateral_p = self.lateral_p1(pool1)
lateral.append(lateral_p)
res2 = self.fast_res2(pool1)
lateral_res2 = self.lateral_res2(res2)
lateral.append(lateral_res2)
res3 = self.fast_res3(res2)
lateral_res3 = self.lateral_res3(res3)
lateral.append(lateral_res3)
res4 = self.fast_res4(res3)
lateral_res4 = self.lateral_res4(res4)
lateral.append(lateral_res4)
res5 = self.fast_res5(res4)
x = nn.AdaptiveAvgPool3d(1)(res5)
x = x.view(-1, x.size(1))
return x, lateral
示例15: __init__
# 需要導入模塊: from torch import nn [as 別名]
# 或者: from torch.nn import AdaptiveAvgPool3d [as 別名]
def __init__(self, block, layers, shortcut_type='B', num_classes=339):
self.inplanes = 64
super(ResNet3D, self).__init__()
self.conv1 = self.Conv3d(3, 64, kernel_size=7, stride=(1, 2, 2), padding=(3, 3, 3), bias=False)
self.bn1 = nn.BatchNorm3d(64)
self.relu = nn.ReLU(inplace=True)
self.maxpool = nn.MaxPool3d(kernel_size=(3, 3, 3), stride=2, padding=1)
self.layer1 = self._make_layer(block, 64, layers[0], shortcut_type)
self.layer2 = self._make_layer(block, 128, layers[1], shortcut_type, stride=2)
self.layer3 = self._make_layer(block, 256, layers[2], shortcut_type, stride=2)
self.layer4 = self._make_layer(block, 512, layers[3], shortcut_type, stride=2)
self.avgpool = nn.AdaptiveAvgPool3d(1)
self.fc = nn.Linear(512 * block.expansion, num_classes)
self.init_weights()