code: def test_inference_object_detection_head(self):
      model = DeformableDetrForObjectDetection.from_pretrained(
          "SenseTime/deformable-detr"
      ).to(torch_device)
  
      image_processor = self.default_image_processor
      image = prepare_img()
      encoding = image_processor(images=image, return_tensors="pt").to(
          torch_device
      )
      pixel_values = encoding["pixel_values"].to(torch_device)
      pixel_mask = encoding["pixel_mask"].to(torch_device)
  
      with torch.no_grad():
          outputs = model(pixel_values, pixel_mask)
  
      expected_shape_logits = torch.Size(
          (1, model.config.num_queries, model.config.num_labels)
      )
      self.assertEqual(outputs.logits.shape, expected_shape_logits)
  
      expected_logits = torch.tensor(
          [
              [-9.6645, -4.3449, -5.8705],
              [-9.7035, -3.8504, -5.0724],
              [-10.5634, -5.3379, -7.5116],
          ]
      ).to(torch_device)
      expected_boxes = torch.tensor(
          [
              [0.8693, 0.2289, 0.2492],
              [0.3150, 0.5489, 0.5845],
              [0.5563, 0.7580, 0.8518],
          ]
      ).to(torch_device)
  
      self.assertTrue(
          torch.allclose(
              outputs.logits[0, :3, :3], expected_logits, atol=1e-4
          )
      )
  
      expected_shape_boxes = torch.Size(
          (1, model.config.num_queries, 4)
      )
      self.assertEqual(outputs.pred_boxes.shape, expected_shape_boxes)
      self.assertTrue(
          torch.allclose(
              outputs.pred_boxes[0, :3, :3], expected_boxes, atol=1e-4
          )
      )
  
      # verify postprocessing
      results = image_processor.post_process_object_detection(
          outputs, threshold=0.3, target_sizes=[image.size[::-1]]
      )[0]
      expected_scores = torch.tensor(
          [0.7999, 0.7894, 0.6331, 0.4720, 0.4382]
      ).to(torch_device)
      expected_labels = [17, 17, 75, 75, 63]
      expected_slice_boxes = torch.tensor(
          [16.5028, 52.8390, 318.2544, 470.7841]
      ).to(torch_device)
  
      self.assertEqual(len(results["scores"]), 5)
      self.assertTrue(
          torch.allclose(results["scores"], expected_scores, atol=1e-4)
      )
      self.assertSequenceEqual(
          results["labels"].tolist(), expected_labels
      )
      self.assertTrue(
          torch.allclose(results["boxes"][0, :], expected_slice_boxes)
      )
  
imports: import inspect
  import math
  import unittest
  from typing import Dict, List, Tuple
  from transformers import DeformableDetrConfig, ResNetConfig, is_torch_available, is_vision_available
  from transformers.file_utils import cached_property
  from transformers.testing_utils import require_timm, require_torch, require_torch_accelerator, require_vision, slow, torch_device
  from ...generation.test_utils import GenerationTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 2 for calling the DeformableDetrModelIntegrationTests obj's underlying member method code with example usage: obj.test_inference_object_detection_head() without return types