class_docstr: GenericModel is a wrapper for the neural implicit
  rendering and reconstruction pipeline which consists
  of the following sequence of 7 steps (steps 2–4 are normally
  skipped in overfitting scenario, since conditioning on source views
  does not add much information; otherwise they should be present altogether):
  
  
      (1) Ray Sampling
      ------------------
      Rays are sampled from an image grid based on the target view(s).
              │_____________
              │             │
              │             ▼
              │    (2) Feature Extraction (optional)
              │    -----------------------
              │    A feature extractor (e.g. a convolutional
              │    neural net) is used to extract image features
              │    from the source view(s).
              │            │
              │            ▼
              │    (3) View Sampling  (optional)
              │    ------------------
              │    Image features are sampled at the 2D projections
              │    of a set of 3D points along each of the sampled
              │    target rays from (1).
              │            │
              │            ▼
              │    (4) Feature Aggregation  (optional)
              │    ------------------
              │    Aggregate features and masks sampled from
              │    image view(s) in (3).
              │            │
              │____________▼
              │
              ▼
      (5) Implicit Function Evaluation
      ------------------
      Evaluate the implicit function(s) at the sampled ray points
      (optionally pass in the aggregated image features from (4)).
      (also optionally pass in a global encoding from global_encoder).
              │
              ▼
      (6) Rendering
      ------------------
      Render the image into the target cameras by raymarching along
      the sampled rays and aggregating the colors and densities
      output by the implicit function in (5).
              │
              ▼
      (7) Loss Computation
      ------------------
      Compute losses based on the predicted target image(s).
  
  
  The `forward` function of GenericModel executes
  this sequence of steps. Currently, steps 1, 3, 4, 5, 6
  can be customized by intializing a subclass of the appropriate
  baseclass and adding the newly created module to the registry.
  Please see https://github.com/facebookresearch/pytorch3d/blob/main/projects/implicitron_trainer/README.md#custom-plugins
  for more details on how to create and register a custom component.
  
  In the config .yaml files for experiments, the parameters below are
  contained in the
  `model_factory_ImplicitronModelFactory_args.model_GenericModel_args`
  node. As GenericModel derives from ReplaceableBase, the input arguments are
  parsed by the run_auto_creation function to initialize the
  necessary member modules. Please see implicitron_trainer/README.md
  for more details on this process.
  
  Args:
      mask_images: Whether or not to mask the RGB image background given the
          foreground mask (the `fg_probability` argument of `GenericModel.forward`)
      mask_depths: Whether or not to mask the depth image background given the
          foreground mask (the `fg_probability` argument of `GenericModel.forward`)
      render_image_width: Width of the output image to render
      render_image_height: Height of the output image to render
      mask_threshold: If greater than 0.0, the foreground mask is
          thresholded by this value before being applied to the RGB/Depth images
      output_rasterized_mc: If True, visualize the Monte-Carlo pixel renders by
          splatting onto an image grid. Default: False.
      bg_color: RGB values for setting the background color of input image
          if mask_images=True. Defaults to (0.0, 0.0, 0.0). Each renderer has its own
          way to determine the background color of its output, unrelated to this.
      num_passes: The specified implicit_function is initialized num_passes
          times and run sequentially.
      chunk_size_grid: The total number of points which can be rendered
          per chunk. This is used to compute the number of rays used
          per chunk when the chunked version of the renderer is used (in order
          to fit rendering on all rays in memory)
      render_features_dimensions: The number of output features to render.
          Defaults to 3, corresponding to RGB images.
      n_train_target_views: The number of cameras to render into at training
          time; first `n_train_target_views` in the batch are considered targets,
          the rest are sources.
      sampling_mode_training: The sampling method to use during training. Must be
          a value from the RenderSamplingMode Enum.
      sampling_mode_evaluation: Same as above but for evaluation.
      global_encoder_class_type: The name of the class to use for global_encoder,
          which must be available in the registry. Or `None` to disable global encoder.
      global_encoder: An instance of `GlobalEncoder`. This is used to generate an encoding
          of the image (referred to as the global_code) that can be used to model aspects of
          the scene such as multiple objects or morphing objects. It is up to the implicit
          function definition how to use it, but the most typical way is to broadcast and
          concatenate to the other inputs for the implicit function.
      raysampler_class_type: The name of the raysampler class which is available
          in the global registry.
      raysampler: An instance of RaySampler which is used to emit
          rays from the target view(s).
      renderer_class_type: The name of the renderer class which is available in the global
          registry.
      renderer: A renderer class which inherits from BaseRenderer. This is used to
          generate the images from the target view(s).
      image_feature_extractor_class_type: If a str, constructs and enables
          the `image_feature_extractor` object of this type. Or None if not needed.
      image_feature_extractor: A module for extrating features from an input image.
      view_pooler_enabled: If `True`, constructs and enables the `view_pooler` object.
          This means features are sampled from the source image(s)
          at the projected 2d locations of the sampled 3d ray points from the target
          view(s), i.e. this activates step (3) above.
      view_pooler: An instance of ViewPooler which is used for sampling of
          image-based features at the 2D projections of a set
          of 3D points and aggregating the sampled features.
      implicit_function_class_type: The type of implicit function to use which
          is available in the global registry.
      implicit_function: An instance of ImplicitFunctionBase. The actual implicit functions
          are initialised to be in self._implicit_functions.
      view_metrics: An instance of ViewMetricsBase used to compute loss terms which
          are independent of the model's parameters.
      view_metrics_class_type: The type of view metrics to use, must be available in
          the global registry.
      regularization_metrics: An instance of RegularizationMetricsBase used to compute
          regularization terms which can depend on the model's parameters.
      regularization_metrics_class_type: The type of regularization metrics to use,
          must be available in the global registry.
      loss_weights: A dictionary with a {loss_name: weight} mapping; see documentation
          for `ViewMetrics` class for available loss functions.
      log_vars: A list of variable names which should be logged.
          The names should correspond to a subset of the keys of the
          dict `preds` output by the `forward` function.
class_docstr_tok: ["GenericModel","is","a","wrapper","for","the","neural","implicit","rendering","and","reconstruction","pipeline","which","consists","of","the","following","sequence","of","7","steps","(","steps","2\u20134","are","normally","skipped","in","overfitting","scenario",",","since","conditioning","on","source","views","does","not","add","much","information",";","otherwise","they","should","be","present","altogether",")",":","(","1",")","Ray","Sampling","--","--","--","--","--","--","--","--","--","Rays","are","sampled","from","an","image","grid","based","on","the","target","view","(","s",")",".","\u2502_____________","\u2502","\u2502","\u2502","\u25bc","\u2502","(","2",")","Feature","Extraction","(","optional",")","\u2502","--","--","--","--","--","--","--","--","--","--","--","-","\u2502","A","feature","extractor","(","e.g",".","a","convolutional","\u2502","neural","net",")","is","used","to","extract","image","features","\u2502","from","the","source","view","(","s",")",".","\u2502","\u2502","\u2502","\u25bc","\u2502","(","3",")","View","Sampling","(","optional",")","\u2502","--","--","--","--","--","--","--","--","--","\u2502","Image","features","are","sampled","at","the","2D","projections","\u2502","of","a","set","of","3D","points","along","each","of","the","sampled","\u2502","target","rays","from","(","1",")",".","\u2502","\u2502","\u2502","\u25bc","\u2502","(","4",")","Feature","Aggregation","(","optional",")","\u2502","--","--","--","--","--","--","--","--","--","\u2502","Aggregate","features","and","masks","sampled","from","\u2502","image","view","(","s",")","in","(","3",")",".","\u2502","\u2502","\u2502____________\u25bc","\u2502","\u25bc","(","5",")","Implicit","Function","Evaluation","--","--","--","--","--","--","--","--","--","Evaluate","the","implicit","function","(","s",")","at","the","sampled","ray","points","(","optionally","pass","in","the","aggregated","image","features","from","(","4",")",")",".","(","also","optionally","pass","in","a","global","encoding","from","global_encoder",")",".","\u2502","\u25bc","(","6",")","Rendering","--","--","--","--","--","--","--","--","--","Render","the","image","into","the","target","cameras","by","raymarching","along","the","sampled","rays","and","aggregating","the","colors","and","densities","output","by","the","implicit","function","in","(","5",")",".","\u2502","\u25bc","(","7",")","Loss","Computation","--","--","--","--","--","--","--","--","--","Compute","losses","based","on","the","predicted","target","image","(","s",")",".","The","`","forward","`","function","of","GenericModel","executes","this","sequence","of","steps",".","Currently",",","steps","1",",","3",",","4",",","5",",","6","can","be","customized","by","intializing","a","subclass","of","the","appropriate","baseclass","and","adding","the","newly","created","module","to","the","registry",".","Please","see","https",":","\/\/github.com\/facebookresearch\/pytorch3d\/blob\/main\/projects\/implicitron_trainer\/README.md","#","custom-plugins","for","more","details","on","how","to","create","and","register","a","custom","component",".","In","the","config",".yaml","files","for","experiments",",","the","parameters","below","are","contained","in","the","`","model_factory_ImplicitronModelFactory_args.model_GenericModel_args","`","node",".","As","GenericModel","derives","from","ReplaceableBase",",","the","input","arguments","are","parsed","by","the","run_auto_creation","function","to","initialize","the","necessary","member","modules",".","Please","see","implicitron_trainer\/README.md","for","more","details","on","this","process",".","Args",":","mask_images",":","Whether","or","not","to","mask","the","RGB","image","background","given","the","foreground","mask","(","the","`","fg_probability","`","argument","of","`","GenericModel.forward","`",")","mask_depths",":","Whether","or","not","to","mask","the","depth","image","background","given","the","foreground","mask","(","the","`","fg_probability","`","argument","of","`","GenericModel.forward","`",")","render_image_width",":","Width","of","the","output","image","to","render","render_image_height",":","Height","of","the","output","image","to","render","mask_threshold",":","If","greater","than","0.0",",","the","foreground","mask","is","thresholded","by","this","value","before","being","applied","to","the","RGB\/Depth","images","output_rasterized_mc",":","If","True",",","visualize","the","Monte-Carlo","pixel","renders","by","splatting","onto","an","image","grid",".","Default",":","False",".","bg_color",":","RGB","values","for","setting","the","background","color","of","input","image","if","mask_images=True",".","Defaults","to","(","0.0",",","0.0",",","0.0",")",".","Each","renderer","has","its","own","way","to","determine","the","background","color","of","its","output",",","unrelated","to","this",".","num_passes",":","The","specified","implicit_function","is","initialized","num_passes","times","and","run","sequentially",".","chunk_size_grid",":","The","total","number","of","points","which","can","be","rendered","per","chunk",".","This","is","used","to","compute","the","number","of","rays","used","per","chunk","when","the","chunked","version","of","the","renderer","is","used","(","in","order","to","fit","rendering","on","all","rays","in","memory",")","render_features_dimensions",":","The","number","of","output","features","to","render",".","Defaults","to","3",",","corresponding","to","RGB","images",".","n_train_target_views",":","The","number","of","cameras","to","render","into","at","training","time",";","first","`","n_train_target_views","`","in","the","batch","are","considered","targets",",","the","rest","are","sources",".","sampling_mode_training",":","The","sampling","method","to","use","during","training",".","Must","be","a","value","from","the","RenderSamplingMode","Enum",".","sampling_mode_evaluation",":","Same","as","above","but","for","evaluation",".","global_encoder_class_type",":","The","name","of","the","class","to","use","for","global_encoder",",","which","must","be","available","in","the","registry",".","Or","`","None","`","to","disable","global","encoder",".","global_encoder",":","An","instance","of","`","GlobalEncoder","`",".","This","is","used","to","generate","an","encoding","of","the","image","(","referred","to","as","the","global_code",")","that","can","be","used","to","model","aspects","of","the","scene","such","as","multiple","objects","or","morphing","objects",".","It","is","up","to","the","implicit","function","definition","how","to","use","it",",","but","the","most","typical","way","is","to","broadcast","and","concatenate","to","the","other","inputs","for","the","implicit","function",".","raysampler_class_type",":","The","name","of","the","raysampler","class","which","is","available","in","the","global","registry",".","raysampler",":","An","instance","of","RaySampler","which","is","used","to","emit","rays","from","the","target","view","(","s",")",".","renderer_class_type",":","The","name","of","the","renderer","class","which","is","available","in","the","global","registry",".","renderer",":","A","renderer","class","which","inherits","from","BaseRenderer",".","This","is","used","to","generate","the","images","from","the","target","view","(","s",")",".","image_feature_extractor_class_type",":","If","a","str",",","constructs","and","enables","the","`","image_feature_extractor","`","object","of","this","type",".","Or","None","if","not","needed",".","image_feature_extractor",":","A","module","for","extrating","features","from","an","input","image",".","view_pooler_enabled",":","If","`","True","`",",","constructs","and","enables","the","`","view_pooler","`","object",".","This","means","features","are","sampled","from","the","source","image","(","s",")","at","the","projected","2d","locations","of","the","sampled","3d","ray","points","from","the","target","view","(","s",")",",","i.e",".","this","activates","step","(","3",")","above",".","view_pooler",":","An","instance","of","ViewPooler","which","is","used","for","sampling","of","image-based","features","at","the","2D","projections","of","a","set","of","3D","points","and","aggregating","the","sampled","features",".","implicit_function_class_type",":","The","type","of","implicit","function","to","use","which","is","available","in","the","global","registry",".","implicit_function",":","An","instance","of","ImplicitFunctionBase",".","The","actual","implicit","functions","are","initialised","to","be","in","self._implicit_functions",".","view_metrics",":","An","instance","of","ViewMetricsBase","used","to","compute","loss","terms","which","are","independent","of","the","model","'s","parameters",".","view_metrics_class_type",":","The","type","of","view","metrics","to","use",",","must","be","available","in","the","global","registry",".","regularization_metrics",":","An","instance","of","RegularizationMetricsBase","used","to","compute","regularization","terms","which","can","depend","on","the","model","'s","parameters",".","regularization_metrics_class_type",":","The","type","of","regularization","metrics","to","use",",","must","be","available","in","the","global","registry",".","loss_weights",":","A","dictionary","with","a","{","loss_name",":","weight","}","mapping",";","see","documentation","for","`","ViewMetrics","`","class","for","available","loss","functions",".","log_vars",":","A","list","of","variable","names","which","should","be","logged",".","The","names","should","correspond","to","a","subset","of","the","keys","of","the","dict","`","preds","`","output","by","the","`","forward","`","function","."]
code: def __post_init__(self):
      if self.view_pooler_enabled:
          if self.image_feature_extractor_class_type is None:
              raise ValueError(
                  "image_feature_extractor must be present for view pooling."
              )
      run_auto_creation(self)
  
      self._implicit_functions = self._construct_implicit_functions()
  
      log_loss_weights(self.loss_weights, logger)
  
imports: import logging
  from dataclasses import field
  from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union
  import torch
  from omegaconf import DictConfig
  from pytorch3d.implicitron.models.base_model import ImplicitronModelBase, ImplicitronRender
  from pytorch3d.implicitron.models.feature_extractor import FeatureExtractorBase
  from pytorch3d.implicitron.models.global_encoder.global_encoder import GlobalEncoderBase
  from pytorch3d.implicitron.models.implicit_function.base import ImplicitFunctionBase
  from pytorch3d.implicitron.models.metrics import RegularizationMetricsBase, ViewMetricsBase
  from pytorch3d.implicitron.models.renderer.base import BaseRenderer, EvaluationMode, ImplicitFunctionWrapper, ImplicitronRayBundle, RendererOutput, RenderSamplingMode
  from pytorch3d.implicitron.models.renderer.ray_sampler import RaySamplerBase
  from pytorch3d.implicitron.models.utils import apply_chunked, chunk_generator, log_loss_weights, preprocess_input, weighted_sum_losses
  from pytorch3d.implicitron.models.view_pooler.view_pooler import ViewPooler
  from pytorch3d.implicitron.tools import vis_utils
  from pytorch3d.implicitron.tools.config import expand_args_fields, registry, run_auto_creation
  from pytorch3d.implicitron.tools.rasterize_mc import rasterize_sparse_ray_bundle
  from pytorch3d.renderer import utils
  from pytorch3d.renderer.cameras import CamerasBase
label_desc: Use image node_id 2 for calling the GenericModel obj's underlying member method code with example usage: obj.__post_init__() without return types