examples/nerf.py
def sample_images_at_mc_locs(target_images, sampled_rays_xy):
    """
    Given a set of Monte Carlo pixel locations `sampled_rays_xy`,
    this method samples the tensor `target_images` at the
    respective 2D locations.

    This function is used in order to extract the colors from
    ground truth images that correspond to the colors
    rendered using `MonteCarloRaysampler`.
    """
    ba = target_images.shape[0]
    dim = target_images.shape[-1]
    spatial_size = sampled_rays_xy.shape[1:-1]
    # In order to sample target_images, we utilize
    # the grid_sample function which implements a
    # bilinear image sampler.
    # Note that we have to invert the sign of the
    # sampled ray positions to convert the NDC xy locations
    # of the MonteCarloRaysampler to the coordinate
    # convention of grid_sample.
    images_sampled = torch.nn.functional.grid_sample(
        target_images.permute(0, 3, 1, 2),
        -sampled_rays_xy.view(ba, -1, 1, 2),  # note the sign inversion
        align_corners=True
    )
    return images_sampled.permute(0, 2, 3, 1).view(
        ba, *spatial_size, dim
    )

    Given a set of Monte Carlo pixel locations `sampled_rays_xy`,
    this method samples the tensor `target_images` at the
    respective 2D locations.

    This function is used in order to extract the colors from
    ground truth images that correspond to the colors
    rendered using `MonteCarloRaysampler`.
    
Given a set of Monte Carlo pixel locations `sampled_rays_xy`,
this method samples the tensor `target_images` at the
respective 2D locations.

This function is used in order to extract the colors from
ground truth images that correspond to the colors
rendered using `MonteCarloRaysampler`.
Given a set of Monte Carlo pixel locations ` sampled_rays_xy ` this method samples the tensor ` target_images ` at the respective 2D locations . This function is used in order to extract the colors from ground truth images that correspond to the colors rendered using ` MonteCarloRaysampler ` .
def sample_images_at_mc_locs(target_images, sampled_rays_xy):
    ba = target_images.shape[0]
    dim = target_images.shape[-1]
    spatial_size = sampled_rays_xy.shape[1:-1]
    images_sampled = torch.nn.functional.grid_sample(
        target_images.permute(0, 3, 1, 2),
        -sampled_rays_xy.view(ba, -1, 1, 2),  
        align_corners=True
    )
    return images_sampled.permute(0, 2, 3, 1).view(
        ba, *spatial_size, dim
    )
def sample_images_at_mc_locs ( target_images , sampled_rays_xy ) : ba = target_images . shape [ 0 ] dim = target_images . shape [ - 1 ] spatial_size = sampled_rays_xy . shape [ 1 : - 1 ] images_sampled = torch . nn . functional . grid_sample ( target_images . permute ( 0 , 3 , 1 , 2 ) , - sampled_rays_xy . view ( ba , - 1 , 1 , 2 ) , align_corners = True ) return images_sampled . permute ( 0 , 2 , 3 , 1 ) . view ( ba , * spatial_size , dim )
Given a set of Monte Carlo pixel locations `sampled_rays_xy`,
this method samples the tensor `target_images` at the
respective 2D locations.
Given a set of Monte Carlo pixel locations ` sampled_rays_xy ` this method samples the tensor ` target_images ` at the respective 2D locations .
"""
    Given a set of Monte Carlo pixel locations `sampled_rays_xy`,
    this method samples the tensor `target_images` at the
    respective 2D locations.

    This function is used in order to extract the colors from
    ground truth images that correspond to the colors
    rendered using `MonteCarloRaysampler`.
    """ # In order to sample target_images, we utilize # the grid_sample function which implements a # bilinear image sampler. # Note that we have to invert the sign of the # sampled ray positions to convert the NDC xy locations # of the MonteCarloRaysampler to the coordinate # convention of grid_sample. # note the sign inversion
target_images
sampled_rays_xy