docstr: Test the loaded train split of R2N2 return items of the correct shapes and types. Also
  check the first image returned is correct.
docstr_tok: ["Test","the","loaded","train","split","of","R2N2","return","items","of","the","correct","shapes","and","types",".","Also","check","the","first","image","returned","is","correct","."]
code: def test_load_R2N2(self):
      """
      Test the loaded train split of R2N2 return items of the correct shapes and types. Also
      check the first image returned is correct.
      """
      # Load dataset in the train split.
      r2n2_dataset = R2N2(
          "test",
          SHAPENET_PATH,
          R2N2_PATH,
          SPLITS_PATH,
          return_voxels=True,
          voxels_rel_path=VOXELS_REL_PATH,
      )
  
      # Check total number of objects in the dataset is correct.
      with open(SPLITS_PATH) as splits:
          split_dict = json.load(splits)["test"]
      model_nums = [len(split_dict[synset]) for synset in split_dict]
      self.assertEqual(len(r2n2_dataset), sum(model_nums))
  
      # Check the numbers of loaded instances for each category are correct.
      for synset in split_dict:
          split_synset_nums = sum(
              len(split_dict[synset][model])
              for model in split_dict[synset]
          )
          idx_start = r2n2_dataset.synset_start_idxs[synset]
          idx_end = idx_start + r2n2_dataset.synset_num_models[synset]
          synset_views_list = r2n2_dataset.views_per_model_list[
              idx_start:idx_end
          ]
          loaded_synset_views = sum(
              len(views) for views in synset_views_list
          )
          self.assertEqual(loaded_synset_views, split_synset_nums)
  
      # Retrieve an object from the dataset.
      r2n2_obj = r2n2_dataset[39]
      # Check that verts and faces returned by __getitem__ have the correct shapes and types.
      verts, faces = r2n2_obj["verts"], r2n2_obj["faces"]
      self.assertTrue(verts.dtype == torch.float32)
      self.assertTrue(faces.dtype == torch.int64)
      self.assertEqual(verts.ndim, 2)
      self.assertEqual(verts.shape[-1], 3)
      self.assertEqual(faces.ndim, 2)
      self.assertEqual(faces.shape[-1], 3)
  
      # Check that the intrinsic matrix and extrinsic matrix have the
      # correct shapes.
      self.assertEqual(r2n2_obj["R"].shape[0], 24)
      self.assertEqual(r2n2_obj["R"].shape[1:], (3, 3))
      self.assertEqual(r2n2_obj["T"].ndim, 2)
      self.assertEqual(r2n2_obj["T"].shape[1], 3)
      self.assertEqual(r2n2_obj["K"].ndim, 3)
      self.assertEqual(r2n2_obj["K"].shape[1:], (4, 4))
  
      # Check that image batch returned by __getitem__ has the correct shape.
      self.assertEqual(r2n2_obj["images"].shape[0], 24)
      self.assertEqual(r2n2_obj["images"].shape[1:-1], (137, 137))
      self.assertEqual(r2n2_obj["images"].shape[-1], 3)
      self.assertEqual(r2n2_dataset[39, [21]]["images"].shape[0], 1)
      self.assertEqual(
          r2n2_dataset[39, torch.tensor([12, 21])]["images"].shape[0], 2
      )
  
      # Check models with total view counts less than 24 return image batches
      # of the correct shapes.
      self.assertEqual(r2n2_dataset[635]["images"].shape[0], 5)
      self.assertEqual(r2n2_dataset[8369]["images"].shape[0], 10)
  
      # Check that the voxel tensor returned by __getitem__ has the correct shape.
      self.assertEqual(r2n2_obj["voxels"].ndim, 4)
      self.assertEqual(r2n2_obj["voxels"].shape, (24, 128, 128, 128))
  
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 2 for calling the TestR2N2 obj's underlying member method code with example usage: obj.test_load_R2N2() without return types