(target_shape, data_shape=None,
        image_size=None, scale_offset=None,
        source=None, convolutions=None, dtype=torch.float, device=None)
return upsample_func
Returns a function that will upsample a batch of torch data from the
    expected data_shape to the specified target_shape. Can use scale_offset
    and image_size to center the grid in a nondefault way: scale_offset
    maps feature pixels to image_size pixels, and it is assumed that
    the target_shape is a uniform downsampling of image_size.
Returns a function that will upsample a batch of torch data from the
    expected data_shape to the specified target_shape. Can use scale_offset
    and image_size to center the grid in a nondefault way: scale_offset
    maps feature pixels to image_size pixels, and it is assumed that
    the target_shape is a uniform downsampling of image_size.
Returns a function that will upsample a batch of torch data from the expected data_shape to the specified target_shape . Can use scale_offset and image_size to center the grid in a nondefault way : scale_offset maps feature pixels to image_size pixels and it is assumed that the target_shape is a uniform downsampling of image_size .
def upsampler(target_shape, data_shape=None,
        image_size=None, scale_offset=None,
        source=None, convolutions=None, dtype=torch.float, device=None):
    '''
    Returns a function that will upsample a batch of torch data from the
    expected data_shape to the specified target_shape. Can use scale_offset
    and image_size to center the grid in a nondefault way: scale_offset
    maps feature pixels to image_size pixels, and it is assumed that
    the target_shape is a uniform downsampling of image_size.
    '''
    if source is not None:
        assert image_size is None
        image_size = image_size_from_source(source)
    if convolutions is not None:
        assert scale_offset is None
        scale_offset = sequence_scale_offset(convolutions)
        if image_size is not None and data_shape is None:
            data_shape = sequence_data_size(convolutions, image_size)
    assert data_shape is not None
    assert len(data_shape) == 2
    grid = upsample_grid(data_shape, target_shape, image_size, scale_offset,
            dtype, device)
    batch_grid = grid
    # padding mode could be 'border'
    def upsample_func(data, mode='bilinear', padding_mode='zeros'):
        nonlocal grid, batch_grid
        # Use the same grid over the whole batch
        if batch_grid.shape[0] != data.shape[0]:
            batch_grid = grid.expand((data.shape[0],) + grid.shape[1:])
        if batch_grid.device != data.device:
            batch_grid = batch_grid.to(data.device)
        return torch.nn.functional.grid_sample(data, batch_grid, mode=mode,
                padding_mode=padding_mode)
    return upsample_func
def upsampler ( target_shape , data_shape = None , image_size = None , scale_offset = None , source = None , convolutions = None , dtype = torch . float , device = None ) : if source is not None : assert image_size is None image_size = image_size_from_source ( source ) if convolutions is not None : assert scale_offset is None scale_offset = sequence_scale_offset ( convolutions ) if image_size is not None and data_shape is None : data_shape = sequence_data_size ( convolutions , image_size ) assert data_shape is not None assert len ( data_shape ) == 2 grid = upsample_grid ( data_shape , target_shape , image_size , scale_offset , dtype , device ) batch_grid = grid # padding mode could be 'border' def upsample_func ( data , mode = 'bilinear' , padding_mode = 'zeros' ) : nonlocal grid , batch_grid # Use the same grid over the whole batch if batch_grid . shape [ 0 ] != data . shape [ 0 ] : batch_grid = grid . expand ( ( data . shape [ 0 ] , ) + grid . shape [ 1 : ] ) if batch_grid . device != data . device : batch_grid = batch_grid . to ( data . device ) return torch . nn . functional . grid_sample ( data , batch_grid , mode = mode , padding_mode = padding_mode ) return upsample_func