code: def render_vanilla(
      coarse_net,
      cap,
      fine_net=None,
      rays_per_batch=32768,
      samples_per_ray=64,
      importance_samples_per_ray=128,
      white_bkg=True,
      near_far_source="bkg",
      return_depth=False,
      ablate_nerft=False,
  ):
      device = next(coarse_net.parameters()).device
  
      def build_batch(origins, dirs, near, far):
          _bs = origins.shape[0]
          ray_batch = {
              "origin": torch.from_numpy(origins).float().to(device),
              "direction": torch.from_numpy(dirs).float().to(device),
              "near": torch.tensor([near] * _bs, dtype=torch.float32)[
                  ..., None
              ].to(device),
              "far": torch.tensor([far] * _bs, dtype=torch.float32)[
                  ..., None
              ].to(device),
          }
          return ray_batch
  
      with torch.set_grad_enabled(False):
          origins, dirs = ray_utils.shot_all_rays(cap)
          total_rays = origins.shape[0]
          total_rgb_map = []
          total_depth_map = []
          for i in range(0, total_rays, rays_per_batch):
              print(f"{i} / {total_rays}")
              ray_batch = build_batch(
                  origins[i : i + rays_per_batch],
                  dirs[i : i + rays_per_batch],
                  cap.near[near_far_source],
                  cap.far[near_far_source],
              )
              if ablate_nerft:
                  cur_time = (
                      cap.frame_id["frame_id"]
                      / cap.frame_id["total_frames"]
                  )
                  coarse_time = (
                      torch.ones(
                          origins[i : i + rays_per_batch].shape[0],
                          samples_per_ray,
                          1,
                          device=device,
                      )
                      * cur_time
                  )
                  fine_time = (
                      torch.ones(
                          origins[i : i + rays_per_batch].shape[0],
                          samples_per_ray + importance_samples_per_ray,
                          1,
                          device=device,
                      )
                      * cur_time
                  )
              else:
                  coarse_time, fine_time = None, None
              _pts, _dirs, _z_vals = ray_utils.ray_to_samples(
                  ray_batch,
                  samples_per_ray,
                  device=device,
                  append_t=coarse_time,
              )
              out = coarse_net(_pts, _dirs)
              (
                  rgb_map,
                  disp_map,
                  acc_map,
                  weights,
                  depth_map,
              ) = raw2outputs(
                  out, _z_vals, _dirs[:, 0, :], white_bkg=white_bkg
              )
  
              if fine_net is not None:
                  (
                      _pts,
                      _dirs,
                      _z_vals,
                  ) = ray_utils.ray_to_importance_samples(
                      ray_batch,
                      _z_vals,
                      weights,
                      importance_samples_per_ray,
                      device=device,
                      append_t=fine_time,
                  )
                  out = fine_net(_pts, _dirs)
                  (
                      rgb_map,
                      disp_map,
                      acc_map,
                      weights,
                      depth_map,
                  ) = raw2outputs(
                      out, _z_vals, _dirs[:, 0, :], white_bkg=white_bkg
                  )
  
              total_rgb_map.append(rgb_map)
              total_depth_map.append(depth_map)
          total_rgb_map = (
              torch.cat(total_rgb_map)
              .reshape(*cap.shape, -1)
              .detach()
              .cpu()
              .numpy()
          )
          total_depth_map = (
              torch.cat(total_depth_map)
              .reshape(*cap.shape)
              .detach()
              .cpu()
              .numpy()
          )
      if return_depth:
          return total_rgb_map, total_depth_map
      return total_rgb_map
  
file_path: ml-neuman/utils/render_utils.py
imports: import random
  import numpy
  import torch
  import torch.nn.functional
  from pytorch3d.structures import Meshes
  from pytorch3d.renderer import RasterizationSettings, MeshRenderer, MeshRasterizer, HardPhongShader, PointLights, TexturesVertex, PerspectiveCameras
  from PIL import Image
  from cameras.camera_pose import CameraPose
  from utils import ray_utils
  from utils.constant import DEFAULT_GEO_THRESH
  from geometry import transformations
label_desc: Use image node_id 4 for calling a global function with example usage: render_vanilla(coarse_net, cap, fine_net, rays_per_batch, samples_per_ray, importance_samples_per_ray, white_bkg, near_far_source, return_depth, ablate_nerft) and returns: total_rgb_map, ray_batch, total_rgb_map,  total_depth_map