docstr: Test rendering R2N2 models with calibration matrices from R2N2's own Blender
  in batches.
docstr_tok: ["Test","rendering","R2N2","models","with","calibration","matrices","from","R2N2","'s","own","Blender","in","batches","."]
code: def test_render_by_r2n2_calibration(self):
      """
      Test rendering R2N2 models with calibration matrices from R2N2's own Blender
      in batches.
      """
      # Set up device and seed for random selections.
      device = torch.device("cuda:0")
      torch.manual_seed(39)
  
      # Load dataset in the train split.
      r2n2_dataset = R2N2(
          "train", SHAPENET_PATH, R2N2_PATH, SPLITS_PATH
      )
      model_idxs = torch.randint(1000, (2,)).tolist()
      view_idxs = torch.randint(24, (2,)).tolist()
      raster_settings = RasterizationSettings(image_size=512)
      lights = PointLights(
          location=torch.tensor([0.0, 1.0, -2.0], device=device)[None],
          # TODO(nikhilar): debug the source of the discrepancy in two images when
          # rendering on GPU.
          diffuse_color=((0, 0, 0),),
          specular_color=((0, 0, 0),),
          device=device,
      )
      r2n2_batch = r2n2_dataset.render(
          idxs=model_idxs,
          view_idxs=view_idxs,
          device=device,
          raster_settings=raster_settings,
          lights=lights,
      )
      for idx in range(4):
          r2n2_batch_rgb = r2n2_batch[idx, ..., :3].squeeze().cpu()
          if DEBUG:
              Image.fromarray(
                  (r2n2_batch_rgb.numpy() * 255).astype(np.uint8)
              ).save(
                  DATA_DIR
                  / (
                      "DEBUG_r2n2_render_with_blender_calibrations_%s.png"
                      % idx
                  )
              )
          image_ref = load_rgb_image(
              "test_r2n2_render_with_blender_calibrations_%s.png" % idx,
              DATA_DIR,
          )
          self.assertClose(r2n2_batch_rgb, image_ref, atol=0.05)
  
imports: import json
  import os
  import unittest
  import numpy
  import torch
  from PIL import Image
  from pytorch3d.datasets import BlenderCamera, collate_batched_R2N2, R2N2, render_cubified_voxels
  from pytorch3d.renderer import FoVPerspectiveCameras, look_at_view_transform, PointLights, RasterizationSettings
  from pytorch3d.renderer.cameras import get_world_to_view_transform
  from pytorch3d.transforms import Transform3d
  from pytorch3d.transforms.so3 import so3_exp_map
  from torch.utils.data import DataLoader
  from .common_testing import get_tests_dir, load_rgb_image, TestCaseMixin
label_desc: Use image node_id 7 for calling the TestR2N2 obj's underlying member method code with example usage: obj.test_render_by_r2n2_calibration() without return types