code: def create_and_check_get_image_hidden_states(
      self, config, pixel_values
  ):
      model = SamModel(config=config)
      model.to(torch_device)
      model.eval()
      with torch.no_grad():
          result = model.vision_encoder(
              pixel_values,
              output_hidden_states=True,
              return_dict=True,
          )
  
      # after computing the convolutional features
      expected_hidden_states_shape = (self.batch_size, 12, 12, 36)
      self.parent.assertEqual(
          len(result[1]), self.num_hidden_layers + 1
      )
      self.parent.assertEqual(
          result[1][0].shape, expected_hidden_states_shape
      )
  
      with torch.no_grad():
          result = model.vision_encoder(
              pixel_values,
              output_hidden_states=True,
              return_dict=False,
          )
  
      # after computing the convolutional features
      expected_hidden_states_shape = (self.batch_size, 12, 12, 36)
      self.parent.assertEqual(
          len(result[1]), self.num_hidden_layers + 1
      )
      self.parent.assertEqual(
          result[1][0].shape, expected_hidden_states_shape
      )
  
imports: import gc
  import unittest
  import requests
  from transformers import SamConfig, SamMaskDecoderConfig, SamPromptEncoderConfig, SamVisionConfig, pipeline
  from transformers.testing_utils import backend_empty_cache, require_torch, slow, torch_device
  from transformers.utils import is_torch_available, is_vision_available
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 6 for calling the SamModelTester obj's underlying member method code with example usage: obj.create_and_check_get_image_hidden_states(config, pixel_values) without return types