Python torch.nn.functional.upsample_nearest() Examples

The following are 3 code examples of torch.nn.functional.upsample_nearest(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module torch.nn.functional , or try the search function .
Example #1
Source File: asn_stacked_hg.py    From pose-adv-aug with Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source File: upsampling_nearest.py    From pytorch2keras with MIT License 5 votes vote down vote up
def forward(self, x):
        from torch.nn import functional as F
        return F.upsample_nearest(x, scale_factor=2) 
Example #3
Source File: util.py    From Graphonomy with MIT License 5 votes vote down vote up
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)