class_docstr: Implements a renderer of a Neural Radiance Field.
  
  This class holds pointers to the fine and coarse renderer objects, which are
  instances of `pytorch3d.renderer.ImplicitRenderer`, and pointers to the
  neural networks representing the fine and coarse Neural Radiance Fields,
  which are instances of `NeuralRadianceField`.
  
  The rendering forward pass proceeds as follows:
      1) For a given input camera, rendering rays are generated with the
          `NeRFRaysampler` object of `self._renderer['coarse']`.
          In the training mode (`self.training==True`), the rays are a set
              of `n_rays_per_image` random 2D locations of the image grid.
          In the evaluation mode (`self.training==False`), the rays correspond
              to the full image grid. The rays are further split to
              `chunk_size_test`-sized chunks to prevent out-of-memory errors.
      2) For each ray point, the coarse `NeuralRadianceField` MLP is evaluated.
          The pointer to this MLP is stored in `self._implicit_function['coarse']`
      3) The coarse radiance field is rendered with the
          `EmissionAbsorptionNeRFRaymarcher` object of `self._renderer['coarse']`.
      4) The coarse raymarcher outputs a probability distribution that guides
          the importance raysampling of the fine rendering pass. The
          `ProbabilisticRaysampler` stored in `self._renderer['fine'].raysampler`
          implements the importance ray-sampling.
      5) Similar to 2) the fine MLP in `self._implicit_function['fine']`
          labels the ray points with occupancies and colors.
      6) self._renderer['fine'].raymarcher` generates the final fine render.
      7) The fine and coarse renders are compared to the ground truth input image
          with PSNR and MSE metrics.
class_docstr_tok: ["Implements","a","renderer","of","a","Neural","Radiance","Field",".","This","class","holds","pointers","to","the","fine","and","coarse","renderer","objects",",","which","are","instances","of","`","pytorch3d.renderer.ImplicitRenderer","`",",","and","pointers","to","the","neural","networks","representing","the","fine","and","coarse","Neural","Radiance","Fields",",","which","are","instances","of","`","NeuralRadianceField","`",".","The","rendering","forward","pass","proceeds","as","follows",":","1",")","For","a","given","input","camera",",","rendering","rays","are","generated","with","the","`","NeRFRaysampler","`","object","of","`","self._renderer","[","'coarse","'","]","`",".","In","the","training","mode","(","`","self.training==True","`",")",",","the","rays","are","a","set","of","`","n_rays_per_image","`","random","2D","locations","of","the","image","grid",".","In","the","evaluation","mode","(","`","self.training==False","`",")",",","the","rays","correspond","to","the","full","image","grid",".","The","rays","are","further","split","to","`","chunk_size_test","`","-sized","chunks","to","prevent","out-of-memory","errors",".","2",")","For","each","ray","point",",","the","coarse","`","NeuralRadianceField","`","MLP","is","evaluated",".","The","pointer","to","this","MLP","is","stored","in","`","self._implicit_function","[","'coarse","'","]","`","3",")","The","coarse","radiance","field","is","rendered","with","the","`","EmissionAbsorptionNeRFRaymarcher","`","object","of","`","self._renderer","[","'coarse","'","]","`",".","4",")","The","coarse","raymarcher","outputs","a","probability","distribution","that","guides","the","importance","raysampling","of","the","fine","rendering","pass",".","The","`","ProbabilisticRaysampler","`","stored","in","`","self._renderer","[","'fine","'","]",".raysampler","`","implements","the","importance","ray-sampling",".","5",")","Similar","to","2",")","the","fine","MLP","in","`","self._implicit_function","[","'fine","'","]","`","labels","the","ray","points","with","occupancies","and","colors",".","6",")","self._renderer","[","'fine","'","]",".raymarcher","`","generates","the","final","fine","render",".","7",")","The","fine","and","coarse","renders","are","compared","to","the","ground","truth","input","image","with","PSNR","and","MSE","metrics","."]
docstr: Precaches the rays emitted from the list of cameras `cache_cameras`,
  where each camera is uniquely identified with the corresponding hash
  from `cache_camera_hashes`.
  
  The cached rays are moved to cpu and stored in
  `self._renderer['coarse']._ray_cache`.
  
  Raises `ValueError` when caching two cameras with the same hash.
  
  Args:
      cache_cameras: A list of `N` cameras for which the rays are pre-cached.
      cache_camera_hashes: A list of `N` unique identifiers for each
          camera from `cameras`.
docstr_tok: ["Precaches","the","rays","emitted","from","the","list","of","cameras","`","cache_cameras","`",",","where","each","camera","is","uniquely","identified","with","the","corresponding","hash","from","`","cache_camera_hashes","`",".","The","cached","rays","are","moved","to","cpu","and","stored","in","`","self._renderer","[","'coarse","'","]","._ray_cache","`",".","Raises","`","ValueError","`","when","caching","two","cameras","with","the","same","hash",".","Args",":","cache_cameras",":","A","list","of","`","N","`","cameras","for","which","the","rays","are","pre-cached",".","cache_camera_hashes",":","A","list","of","`","N","`","unique","identifiers","for","each","camera","from","`","cameras","`","."]
code: def precache_rays(
      self,
      cache_cameras: List[CamerasBase],
      cache_camera_hashes: List[str],
  ):
      """
      Precaches the rays emitted from the list of cameras `cache_cameras`,
      where each camera is uniquely identified with the corresponding hash
      from `cache_camera_hashes`.
  
      The cached rays are moved to cpu and stored in
      `self._renderer['coarse']._ray_cache`.
  
      Raises `ValueError` when caching two cameras with the same hash.
  
      Args:
          cache_cameras: A list of `N` cameras for which the rays are pre-cached.
          cache_camera_hashes: A list of `N` unique identifiers for each
              camera from `cameras`.
      """
      self._renderer["coarse"].raysampler.precache_rays(
          cache_cameras,
          cache_camera_hashes,
      )
  
file_path: pytorch3d/projects/nerf/nerf/nerf_renderer.py
imports: from typing import List, Optional, Tuple
  import torch
  from pytorch3d.renderer import ImplicitRenderer, ray_bundle_to_ray_points
  from pytorch3d.renderer.cameras import CamerasBase
  from pytorch3d.structures import Pointclouds
  from pytorch3d.vis.plotly_vis import plot_scene
  from visdom import Visdom
  from .implicit_function import NeuralRadianceField
  from .raymarcher import EmissionAbsorptionNeRFRaymarcher
  from .raysampler import NeRFRaysampler, ProbabilisticRaysampler
  from .utils import calc_mse, calc_psnr, sample_images_at_mc_locs
label_desc: Use image node_id 2 for calling the RadianceFieldRenderer obj's underlying member method code with example usage: obj.precache_rays(cache_cameras, cache_camera_hashes) without return types