code: def _texture_map_per_rasterizer(self, rasterizer_type):
      device = torch.device("cuda:0")
  
      obj_filename = TUTORIAL_DATA_DIR / "cow_mesh/cow.obj"
  
      # Load mesh + texture
      verts, faces, aux = load_obj(
          obj_filename,
          device=device,
          load_textures=True,
          texture_wrap=None,
      )
      tex_map = list(aux.texture_images.values())[0]
      tex_map = tex_map[None, ...].to(faces.textures_idx.device)
      textures = TexturesUV(
          maps=tex_map,
          faces_uvs=[faces.textures_idx],
          verts_uvs=[aux.verts_uvs],
      )
      mesh = Meshes(
          verts=[verts], faces=[faces.verts_idx], textures=textures
      )
  
      # Init rasterizer settings
      R, T = look_at_view_transform(2.7, 0, 0)
      cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
  
      raster_settings = RasterizationSettings(
          image_size=512, blur_radius=0.0, faces_per_pixel=1
      )
  
      # Init shader settings
      materials = Materials(device=device)
      lights = PointLights(device=device)
  
      # Place light behind the cow in world space. The front of
      # the cow is facing the -z direction.
      lights.location = torch.tensor([0.0, 0.0, 2.0], device=device)[
          None
      ]
  
      blend_params = BlendParams(
          sigma=1e-1 if rasterizer_type == MeshRasterizer else 0.5,
          gamma=1e-4,
          background_color=torch.tensor([1.0, 1.0, 1.0], device=device),
      )
      # Init renderer
      rasterizer = rasterizer_type(
          cameras=cameras, raster_settings=raster_settings
      )
      if rasterizer_type == MeshRasterizer:
          shader = TexturedSoftPhongShader(
              lights=lights,
              cameras=cameras,
              materials=materials,
              blend_params=blend_params,
          )
      elif rasterizer_type == MeshRasterizerOpenGL:
          shader = SplatterPhongShader(
              lights=lights,
              cameras=cameras,
              materials=materials,
              blend_params=blend_params,
          )
      renderer = MeshRenderer(rasterizer=rasterizer, shader=shader)
  
      # Load reference image
      image_ref = load_rgb_image(
          f"test_texture_map_back_{rasterizer_type.__name__}.png",
          DATA_DIR,
      )
  
      for bin_size in [0, None]:
          if rasterizer_type == MeshRasterizerOpenGL and bin_size == 0:
              # MeshRasterizerOpenGL does not use this parameter.
              continue
          # Check both naive and coarse to fine produce the same output.
          renderer.rasterizer.raster_settings.bin_size = bin_size
          images = renderer(mesh)
          rgb = images[0, ..., :3].squeeze().cpu()
  
          if DEBUG:
              Image.fromarray(
                  (rgb.numpy() * 255).astype(np.uint8)
              ).save(
                  DATA_DIR
                  / f"DEBUG_texture_map_back_{rasterizer_type.__name__}.png"
              )
  
          # NOTE some pixels can be flaky and will not lead to
          # `cond1` being true. Add `cond2` and check `cond1 or cond2`
          cond1 = torch.allclose(rgb, image_ref, atol=0.05)
          cond2 = ((rgb - image_ref).abs() > 0.05).sum() < 5
          # self.assertTrue(cond1 or cond2)
  
      # Check grad exists
      [verts] = mesh.verts_list()
      verts.requires_grad = True
      mesh2 = Meshes(
          verts=[verts], faces=mesh.faces_list(), textures=mesh.textures
      )
      images = renderer(mesh2)
      images[0, ...].sum().backward()
      self.assertIsNotNone(verts.grad)
  
      ##########################################
      # Check rendering of the front of the cow
      ##########################################
  
      R, T = look_at_view_transform(2.7, 0, 180)
      cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
  
      # Move light to the front of the cow in world space
      lights.location = torch.tensor([0.0, 0.0, -2.0], device=device)[
          None
      ]
  
      # Load reference image
      image_ref = load_rgb_image(
          f"test_texture_map_front_{rasterizer_type.__name__}.png",
          DATA_DIR,
      )
  
      for bin_size in [0, None]:
          if rasterizer == MeshRasterizerOpenGL and bin_size == 0:
              # MeshRasterizerOpenGL does not use this parameter.
              continue
          # Check both naive and coarse to fine produce the same output.
          renderer.rasterizer.raster_settings.bin_size = bin_size
  
          images = renderer(mesh, cameras=cameras, lights=lights)
          rgb = images[0, ..., :3].squeeze().cpu()
  
          if DEBUG:
              Image.fromarray(
                  (rgb.numpy() * 255).astype(np.uint8)
              ).save(
                  DATA_DIR
                  / f"DEBUG_texture_map_front_{rasterizer_type.__name__}.png"
              )
  
          # NOTE some pixels can be flaky and will not lead to
          # `cond1` being true. Add `cond2` and check `cond1 or cond2`
          cond1 = torch.allclose(rgb, image_ref, atol=0.05)
          cond2 = ((rgb - image_ref).abs() > 0.05).sum() < 5
          self.assertTrue(cond1 or cond2)
  
      #################################
      # Add blurring to rasterization
      #################################
      if rasterizer_type == MeshRasterizer:
          # Note that MeshRasterizer can blur the images arbitrarily, however
          # MeshRasterizerOpenGL is limited by its kernel size (currently 3 px^2),
          # so this test only makes sense for MeshRasterizer.
          R, T = look_at_view_transform(2.7, 0, 180)
          cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
          # For MeshRasterizer, blurring is controlled by blur_radius. For
          # MeshRasterizerOpenGL, by sigma.
          blend_params = BlendParams(sigma=5e-4, gamma=1e-4)
          raster_settings = RasterizationSettings(
              image_size=512,
              blur_radius=np.log(1.0 / 1e-4 - 1.0) * blend_params.sigma,
              faces_per_pixel=100,
              clip_barycentric_coords=True,
              perspective_correct=rasterizer_type.__name__
              == "MeshRasterizerOpenGL",
          )
  
          # Load reference image
          image_ref = load_rgb_image(
              "test_blurry_textured_rendering.png", DATA_DIR
          )
  
          for bin_size in [0, None]:
              # Check both naive and coarse to fine produce the same output.
              renderer.rasterizer.raster_settings.bin_size = bin_size
  
              images = renderer(
                  mesh.clone(),
                  cameras=cameras,
                  raster_settings=raster_settings,
                  blend_params=blend_params,
              )
              rgb = images[0, ..., :3].squeeze().cpu()
  
              if DEBUG:
                  Image.fromarray(
                      (rgb.numpy() * 255).astype(np.uint8)
                  ).save(
                      DATA_DIR / "DEBUG_blurry_textured_rendering.png"
                  )
  
              self.assertClose(rgb, image_ref, atol=0.05)
  
imports: import os
  import unittest
  from collections import namedtuple
  from itertools import product
  import numpy
  import torch
  from PIL import Image
  from pytorch3d.io import load_obj, load_objs_as_meshes
  from pytorch3d.renderer import AmbientLights, FoVOrthographicCameras, FoVPerspectiveCameras, look_at_view_transform, Materials, MeshRasterizer, MeshRenderer, MeshRendererWithFragments, OrthographicCameras, PerspectiveCameras, PointLights, RasterizationSettings, TexturesAtlas, TexturesUV, TexturesVertex
  from pytorch3d.renderer.fisheyecameras import FishEyeCameras
  from pytorch3d.renderer.mesh.shader import BlendParams, HardFlatShader, HardGouraudShader, HardPhongShader, SoftPhongShader, SoftSilhouetteShader, SplatterPhongShader, TexturedSoftPhongShader
  from pytorch3d.renderer.opengl import MeshRasterizerOpenGL
  from pytorch3d.structures.meshes import join_meshes_as_batch, join_meshes_as_scene, Meshes
  from pytorch3d.utils.ico_sphere import ico_sphere
  from pytorch3d.utils.torus import torus
  from .common_testing import get_pytorch3d_dir, get_tests_dir, load_rgb_image, TestCaseMixin
label_desc: Use image node_id 9 for calling the TestRenderMeshes obj's underlying member method code with example usage: obj._texture_map_per_rasterizer(rasterizer_type) without return types