本文整理汇总了Python中torch.nn.functional.adaptive_avg_pool3d方法的典型用法代码示例。如果您正苦于以下问题:Python functional.adaptive_avg_pool3d方法的具体用法?Python functional.adaptive_avg_pool3d怎么用?Python functional.adaptive_avg_pool3d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch.nn.functional
的用法示例。
在下文中一共展示了functional.adaptive_avg_pool3d方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
# x = self.avgpool(x)
x = F.adaptive_avg_pool3d(x, (1, 1, 1))
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
示例2: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
# print(x.shape)
# x = self.avgpool(x)
x = F.adaptive_avg_pool3d(x, (1, 1, 1))
x = x.view(x.size(0), -1)
x = self.fc(x)
return x
示例3: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = self.layer1(x)
x = self.temporalpool(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
x = F.adaptive_avg_pool3d(x, (1, 1, 1))
x = x.permute(0, 2, 1, 3, 4).contiguous()
x = x.view(x.size(0), -1)
x = self.avgdrop(x)
x = self.fc(x)
return x
示例4: cal_features
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def cal_features(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = self.layer1(x)
x = self.temporalpool(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
x = F.adaptive_avg_pool3d(x, (1, 1, 1))
x = x.permute(0, 2, 1, 3, 4).contiguous()
x = x.view(x.size(0), -1)
return x
示例5: forward_multiframe
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward_multiframe(self, x, pool=True):
(B, C, T, H, W) = x.size()
x = x.permute(0, 2, 1, 3, 4).contiguous()
x = x.view(B*T, C, H, W)
x = self.features(x)
x = self.fc(x)
(_, C, H, W) = x.size()
x = x.view(B, T, C, H, W)
x = x.permute(0, 2, 1, 3, 4)
if not pool:
return x
if self.pool_type == 'avgpool':
x = F.adaptive_avg_pool3d(x, 1)
elif self.pool_type == 'maxpool':
x = F.adaptive_max_pool3d(x, 1)
x = x.view(B, C)
return x
示例6: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, input_tensor):
"""
:param input_tensor: X, shape = (batch_size, num_channels, D, H, W)
:return: output tensor
"""
batch_size, num_channels, D, H, W = input_tensor.size()
# Project:
# Average along channels and different axes
squeeze_tensor_w = F.adaptive_avg_pool3d(input_tensor, (1, 1, W))
squeeze_tensor_h = F.adaptive_avg_pool3d(input_tensor, (1, H, 1))
squeeze_tensor_d = F.adaptive_avg_pool3d(input_tensor, (D, 1, 1))
# tile tensors to original size and add:
final_squeeze_tensor = sum([squeeze_tensor_w.view(batch_size, num_channels, 1, 1, W),
squeeze_tensor_h.view(batch_size, num_channels, 1, H, 1),
squeeze_tensor_d.view(batch_size, num_channels, D, 1, 1)])
# Excitation:
final_squeeze_tensor = self.sigmoid(self.conv_cT(self.relu(self.conv_c(final_squeeze_tensor))))
output_tensor = torch.mul(input_tensor, final_squeeze_tensor)
return output_tensor
示例7: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
out = F.adaptive_avg_pool3d(out,
output_size=(1, 1,
1)).view(features.size(0), -1)
out = self.classifier(out)
return out
示例8: cal_features
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def cal_features(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu(x)
x = self.maxpool(x)
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
# print(x.shape)
x = F.adaptive_avg_pool3d(x, (1, 1, 1))
x = x.view(x.size(0), -1)
return x
示例9: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
# last_duration = int(math.ceil(self.sample_duration / 16))
# last_size = int(math.floor(self.sample_size / 32))
# out = F.avg_pool3d(
# out, kernel_size=(last_duration, last_size, last_size)).view(
# features.size(0), -1)
out = F.adaptive_avg_pool3d(out, (1, 1, 1)).view(features.size(0), -1)
out = self.classifier(out)
return out
示例10: cal_features
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def cal_features(self, x):
features = self.features(x)
out = F.relu(features, inplace=True)
out = F.adaptive_avg_pool3d(out, (1, 1, 1)).view(features.size(0), -1)
return out
示例11: pool
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def pool(self, input):
return F.adaptive_avg_pool3d(input,1)
示例12: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def forward(self, x):
assert x.dim() == 5
inp_size = x.size()
out_dim1, out_dim2, out_dim3 = int(inp_size[2] * self.scale), int(inp_size[3] * self.scale), int(inp_size[4] * self.scale)
x_down = F.adaptive_avg_pool3d(x, output_size=(out_dim1, out_dim2, out_dim3))
return F.upsample(self.features(x_down), size=(inp_size[2], inp_size[3], inp_size[4]), mode='trilinear')
示例13: global_average_pooling
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def global_average_pooling(inp: torch.Tensor) -> torch.Tensor:
if inp.ndim == 5:
return F.adaptive_avg_pool3d(inp, 1)
elif inp.ndim == 4:
return F.adaptive_avg_pool2d(inp, 1)
else:
raise NotImplementedError
示例14: test_adaptive_avg_pool3d
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_avg_pool3d [as 别名]
def test_adaptive_avg_pool3d(self):
inp = torch.randn(1, 16, 16, 32, 32, device='cuda', dtype=self.dtype)
out = F.adaptive_avg_pool3d(inp, output_size=5)