code: def project_points_and_sample(
      pts: torch.Tensor,
      feats: Dict[str, torch.Tensor],
      camera: CamerasBase,
      masks: Optional[torch.Tensor],
      eps: float = 1e-2,
      sampling_mode: str = "bilinear",
  ) -> Tuple[Dict[str, torch.Tensor], torch.Tensor]:
      """
      Project each point cloud from a batch of point clouds to all input cameras
      and sample features at the 2D projection locations.
  
      Args:
          pts: `(pts_batch, n_pts, 3)` tensor containing a batch of 3D point clouds.
          feats: A dict `{feat_i: feat_T_i}` of features to sample,
              where each `feat_T_i` is a tensor of shape
              `(n_cameras, feat_i_dim, feat_i_H, feat_i_W)`
              of `feat_i_dim`-dimensional features extracted from `n_cameras`
              source views.
          camera: A batch of `n_cameras` cameras corresponding to their feature
              tensors `feat_T_i` from `feats`.
          masks: A tensor of shape `(n_cameras, 1, mask_H, mask_W)` denoting
              valid locations for sampling.
          eps: A small constant controlling the minimum depth of projections
              of `pts` to avoid divisons by zero in the projection operation.
          sampling_mode: Sampling mode of the grid sampler.
  
      Returns:
          sampled_feats: Dict of sampled features `{feat_i: sampled_T_i}`.
              Each `sampled_T_i` is of shape
              `(pts_batch, n_cameras, n_pts, feat_i_dim)`.
          sampled_masks: A tensor with the mask of the sampled features
              of shape `(pts_batch, n_cameras, n_pts, 1)`.
              If `masks` is `None`, the returned `sampled_masks` will be
              filled with 1s.
      """
  
      n_cameras = camera.R.shape[0]
      pts_batch = pts.shape[0]
      n_pts = pts.shape[1:-1]
  
      camera_rep, pts_rep = cameras_points_cartesian_product(
          camera, pts
      )
  
      # The eps here is super-important to avoid NaNs in backprop!
      proj_rep = camera_rep.transform_points(
          pts_rep.reshape(n_cameras * pts_batch, -1, 3), eps=eps
      )[..., :2]
      # [ pts1 in cam1, pts2 in cam1, pts3 in cam1,
      #   pts1 in cam2, pts2 in cam2, pts3 in cam2,
      #   pts1 in cam3, pts2 in cam3, pts3 in cam3 ]
  
      # reshape for the grid sampler
      sampling_grid_ndc = proj_rep.view(n_cameras, pts_batch, -1, 2)
      # [ [pts1 in cam1, pts2 in cam1, pts3 in cam1],
      #   [pts1 in cam2, pts2 in cam2, pts3 in cam2],
      #   [pts1 in cam3, pts2 in cam3, pts3 in cam3] ]
      #   n_cameras x pts_batch x n_pts x 2
  
      # sample both feats
      feats_sampled = {
          k: ndc_grid_sample(
              f,
              sampling_grid_ndc,
              mode=sampling_mode,
              align_corners=False,
          )
          .permute(2, 0, 3, 1)
          .reshape(pts_batch, n_cameras, *n_pts, -1)
          for k, f in feats.items()
      }  # {k: pts_batch x n_cameras x *n_pts x dim} for each feat type "k"
  
      if masks is not None:
          # sample masks
          masks_sampled = (
              ndc_grid_sample(
                  masks,
                  sampling_grid_ndc,
                  mode=sampling_mode,
                  align_corners=False,
              )
              .permute(2, 0, 3, 1)
              .reshape(pts_batch, n_cameras, *n_pts, 1)
          )
      else:
          masks_sampled = sampling_grid_ndc.new_ones(
              pts_batch, n_cameras, *n_pts, 1
          )
  
      return feats_sampled, masks_sampled
  
file_path: pytorch3d/pytorch3d/implicitron/models/view_pooler/view_sampler.py
imports: from typing import Dict, List, Optional, Tuple, Union
  import torch
  from pytorch3d.implicitron.tools.config import Configurable
  from pytorch3d.renderer.cameras import CamerasBase
  from pytorch3d.renderer.utils import ndc_grid_sample
label_desc: Use image node_id 1 for calling a global function with example usage: project_points_and_sample(pts, feats, camera, masks, eps, sampling_mode) and returns: feats_sampled,  masks_sampled