docstr: Test builder `create_res_roi_pooling_head`.
docstr_tok: ["Test","builder","`","create_res_roi_pooling_head","`","."]
code: def test_build_head_with_callable(self):
      """
      Test builder `create_res_roi_pooling_head`.
      """
      # ROI layer configs
      resolution = (10, 15)
      spatial_scale = 1.0 / 5.0
      sampling_ratio = 0
      roi_layer = RoIAlign(
          resolution,
          spatial_scale=spatial_scale,
          sampling_ratio=sampling_ratio,
      )
  
      for pool, activation in itertools.product(
          (nn.AvgPool3d, nn.MaxPool3d, nn.AdaptiveAvgPool3d, None),
          (nn.ReLU, nn.Softmax, nn.Sigmoid, None),
      ):
          if activation is None:
              activation_model = None
          elif activation == nn.Softmax:
              activation_model = activation(dim=1)
          else:
              activation_model = activation()
  
          if pool is None:
              pool_model = None
          elif pool == nn.AdaptiveAvgPool3d:
              pool_model = pool(1)
          else:
              pool_model = pool(kernel_size=[5, 1, 1], stride=[1, 1, 1])
  
          model = create_res_roi_pooling_head(
              in_features=16,
              out_features=32,
              resolution=resolution,
              spatial_scale=spatial_scale,
              sampling_ratio=sampling_ratio,
              roi=RoIAlign,
              pool=pool,
              pool_spatial=nn.MaxPool2d,
              pool_kernel_size=(5, 1, 1),
              output_size=(1, 1, 1),
              dropout_rate=0.0,
              activation=activation,
              output_with_global_average=True,
          )
          model_gt = ResNetRoIHead(
              proj=nn.Linear(16, 32),
              activation=activation_model,
              pool=pool_model,
              pool_spatial=nn.MaxPool2d(resolution, stride=1),
              roi_layer=roi_layer,
              dropout=None,
              output_pool=nn.AdaptiveAvgPool3d(1),
          )
          model.load_state_dict(
              model_gt.state_dict(), strict=True
          )  # explicitly use strict mode.
  
          # Test forwarding.
          for input_tensor, bboxes in TestRoIHeadHelper._get_inputs(
              input_dim=16
          ):
              with torch.no_grad():
                  if (
                      input_tensor.shape[1] != 16
                      or (pool is None)
                      or (
                          input_tensor.shape[-3] != 5
                          and pool != nn.AdaptiveAvgPool3d
                      )
                  ):
                      with self.assertRaises(Exception):
                          output_tensor = model(input_tensor, bboxes)
                      continue
                  else:
                      output_tensor = model(input_tensor, bboxes)
                      output_tensor_gt = model_gt(input_tensor, bboxes)
              self.assertEqual(
                  output_tensor.shape,
                  output_tensor_gt.shape,
                  "Output shape {} is different from expected shape {}".format(
                      output_tensor.shape, output_tensor_gt.shape
                  ),
              )
              self.assertTrue(
                  np.allclose(
                      output_tensor.numpy(), output_tensor_gt.numpy()
                  )
              )
  
imports: import itertools
  import unittest
  import numpy
  import torch
  from pytorchvideo.models.head import create_res_basic_head, create_res_roi_pooling_head, create_vit_basic_head, ResNetBasicHead, ResNetRoIHead, SequencePool
  from torch import nn
  from torchvision.ops import RoIAlign
label_desc: Use image node_id 6 for calling the TestRoIHeadHelper obj's underlying member method code with example usage: obj.test_build_head_with_callable() without return types