本文整理汇总了Python中torch.nn.functional.upsample_nearest方法的典型用法代码示例。如果您正苦于以下问题:Python functional.upsample_nearest方法的具体用法?Python functional.upsample_nearest怎么用?Python functional.upsample_nearest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torch.nn.functional
的用法示例。
在下文中一共展示了functional.upsample_nearest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dropout
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import upsample_nearest [as 别名]
def _dropout(self, x, masks):
# x: n x c x h x w
# masks: n x 1 x 4 x 4
# sample_num = x.data.size(0)
height = x.data.size(2)
width = x.data.size(3)
assert(height == width)
scale = height / 4
# print(scale)
# assert (len(ys) == len(xs))
# masks = masks.unsqueeze(1)
# print(masks.size())
# masks = 1 - masks
# print(masks[0])
if scale != 1:
masks = F.upsample_nearest(masks, scale_factor=scale)
# print(masks[0])
# print(x[0, 1])
x = x * masks.expand(x.size())
# print(x[0, 1])
# exit()
return x
示例2: forward
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import upsample_nearest [as 别名]
def forward(self, x):
from torch.nn import functional as F
return F.upsample_nearest(x, scale_factor=2)
示例3: scale_tensor
# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import upsample_nearest [as 别名]
def scale_tensor(input,size=512,mode='bilinear'):
print(input.size())
# b,h,w = input.size()
_, _, h, w = input.size()
if mode == 'nearest':
if h == 512 and w == 512:
return input
return F.upsample_nearest(input,size=(size,size))
if h>512 and w > 512:
return F.upsample(input, size=(size,size), mode=mode, align_corners=True)
return F.upsample(input, size=(size,size), mode=mode, align_corners=True)