'''simple docstring'''






import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, 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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import UperNetForSemanticSegmentation
   from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from PIL import Image

   from transformers import AutoImageProcessor







class lowercase_       :







   """simple docstring"""

   def __init__(      self      :			Union[str, Any], UpperCamelCase__      :			str, UpperCamelCase__      :			Dict=13, UpperCamelCase__      :			Optional[Any]=32, UpperCamelCase__      :			Union[str, Any]=3, UpperCamelCase__      :			Tuple=4, UpperCamelCase__      :			List[str]=[10, 20, 30, 40], UpperCamelCase__      :			List[Any]=[2, 2, 3, 2], UpperCamelCase__      :			str=True, UpperCamelCase__      :			Tuple=True, UpperCamelCase__      :			Union[str, Any]=37, UpperCamelCase__      :			str="gelu", UpperCamelCase__      :			int=10, UpperCamelCase__      :			Any=0.02, UpperCamelCase__      :			Dict=["stage2", "stage3", "stage4"], UpperCamelCase__      :			str=3, UpperCamelCase__      :			List[str]=None, )  ->			str:
        _A    		=  parent
        _A    		=  batch_size
        _A    		=  image_size
        _A    		=  num_channels
        _A    		=  num_stages
        _A    		=  hidden_sizes
        _A    		=  depths
        _A    		=  is_training
        _A    		=  use_labels
        _A    		=  intermediate_size
        _A    		=  hidden_act
        _A    		=  type_sequence_label_size
        _A    		=  initializer_range
        _A    		=  out_features
        _A    		=  num_labels
        _A    		=  scope
        _A    		=  num_stages
   def 	__UpperCAmelCase   (      self      :			Any     )  ->			List[str]:
        _A    		=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

        _A    		=  None
        if self.use_labels:
             _A    		=  ids_tensor([self.batch_size], self.type_sequence_label_size     )

        _A    		=  self.get_config()

        return config, pixel_values, labels
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Optional[int]:
        return ConvNextConfig(
            num_channels=self.num_channels, num_stages=self.num_stages, hidden_sizes=self.hidden_sizes, depths=self.depths, is_training=self.is_training, intermediate_size=self.intermediate_size, hidden_act=self.hidden_act, out_features=self.out_features, )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			Tuple:
        return UperNetConfig(
            backbone_config=self.get_backbone_config(), hidden_size=5_12, pool_scales=[1, 2, 3, 6], use_auxiliary_head=lowerCamelCase_, auxiliary_loss_weight=0.4, auxiliary_in_channels=40, auxiliary_channels=2_56, auxiliary_num_convs=1, auxiliary_concat_input=lowerCamelCase_, loss_ignore_index=2_55, num_labels=self.num_labels, )
   def 	__UpperCAmelCase   (      self      :			Optional[Any], UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			int, UpperCamelCase__      :			Tuple     )  ->			List[str]:
        _A    		=  UperNetForSemanticSegmentation(config=lowerCamelCase_     )
        model.to(lowerCamelCase_     )
        model.eval()
        _A    		=  model(lowerCamelCase_     )
        self.parent.assertEqual(
            result.logits.shape, (self.batch_size, self.num_labels, self.image_size, self.image_size)     )

   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			List[Any]:
        _A    		=  self.prepare_config_and_inputs()
        (
            _A							
        )    		=  config_and_inputs
        _A    		=  {"""pixel_values""": pixel_values}
        return config, inputs_dict







@require_torch
class lowercase_       (		lowercase_    ,    lowercase_    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   (UperNetForSemanticSegmentation,) if is_torch_available() else ()
   __lowerCAmelCase         =   {"image-segmentation": UperNetForSemanticSegmentation} if is_torch_available() else {}
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   __lowerCAmelCase         =   False
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Union[str, Any]:
        _A    		=  UperNetModelTester(self     )
        _A    		=  ConfigTester(self, config_class=lowerCamelCase_, has_text_modality=lowerCamelCase_, hidden_size=37     )
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Union[str, Any]:
        self.create_and_test_config_common_properties()
        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			int:
        return
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Optional[int]:
        _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             _A    		=  model_class(lowerCamelCase_     )
             _A    		=  inspect.signature(model.forward     )
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             _A    		=  [*signature.parameters.keys()]

             _A    		=  ["""pixel_values"""]
             self.assertListEqual(arg_names[:1], lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			Any:
        _A    		=  self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase_     )
   @unittest.skip(reason='UperNet does not use inputs_embeds'     )
   def 	__UpperCAmelCase   (      self      :			Optional[Any]     )  ->			List[Any]:
        pass
   @unittest.skip(reason='UperNet does not support input and output embeddings'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Tuple:
        pass
   @unittest.skip(reason='UperNet does not have a base model'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Any:
        pass
   @unittest.skip(reason='UperNet does not have a base model'     )
   def 	__UpperCAmelCase   (      self      :			Tuple     )  ->			Dict:
        pass
   @require_torch_multi_gpu
   @unittest.skip(reason='UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			int:
        pass
   @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			str:
        pass
   def 	__UpperCAmelCase   (      self      :			int     )  ->			List[Any]:



        def check_hidden_states_output(UpperCamelCase__      :			Dict, UpperCamelCase__      :			int, UpperCamelCase__      :			str     ):
             _A    		=  model_class(lowerCamelCase_     )
             model.to(lowerCamelCase_     )
             model.eval()

             with torch.no_grad():
                  _A    		=  model(**self._prepare_for_class(lowerCamelCase_, lowerCamelCase_     )     )

             _A    		=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

             _A    		=  self.model_tester.num_stages
             self.assertEqual(len(lowerCamelCase_     ), expected_num_stages + 1     )

             # ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]     ), [self.model_tester.image_size // 4, self.model_tester.image_size // 4], )

        _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             _A    		=  True
             check_hidden_states_output(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_     )

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             _A    		=  True

             check_hidden_states_output(lowerCamelCase_, lowerCamelCase_, lowerCamelCase_     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Union[str, Any]:
        _A    		=  self.model_tester.prepare_config_and_inputs_for_common()

        _A    		=  _config_zero_init(lowerCamelCase_     )
        _A    		=  _config_zero_init(configs_no_init.backbone_config     )
        for model_class in self.all_model_classes:
             _A    		=  model_class(config=lowerCamelCase_     )
             for name, param in model.named_parameters():
                  if param.requires_grad:
                       self.assertIn(
                           ((param.data.mean() * 1e9).round() / 1e9).item(), [0.0, 1.0], msg=f'Parameter {name} of model {model_class} seems not properly initialized', )
   @unittest.skip(reason='UperNet does not have tied weights'     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			Tuple:
        pass

   @slow
   def 	__UpperCAmelCase   (      self      :			str     )  ->			List[str]:



        for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             _A    		=  UperNetForSemanticSegmentation.from_pretrained(lowerCamelCase_     )
             self.assertIsNotNone(lowerCamelCase_     )






def  _SCREAMING_SNAKE_CASE		(      ):
     _A    		=  hf_hub_download(
         repo_id='hf-internal-testing/fixtures_ade20k'   ,		repo_type='dataset'   ,		filename='ADE_val_00000001.jpg'				)
     _A    		=  Image.open(lowerCamelCase_				).convert('RGB'				)
     return image







@require_torch
@require_vision
@slow
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			Dict:
        _A    		=  AutoImageProcessor.from_pretrained('openmmlab/upernet-swin-tiny'     )
        _A    		=  UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-swin-tiny'     ).to(lowerCamelCase_     )

        _A    		=  prepare_img()
        _A    		=  processor(images=lowerCamelCase_, return_tensors='pt'     ).to(lowerCamelCase_     )

        with torch.no_grad():
             _A    		=  model(**lowerCamelCase_     )

        _A    		=  torch.Size((1, model.config.num_labels, 5_12, 5_12)     )
        self.assertEqual(outputs.logits.shape, lowerCamelCase_     )

        _A    		=  torch.tensor(
            [[-7.5_958, -7.5_958, -7.4_302], [-7.5_958, -7.5_958, -7.4_302], [-7.4_797, -7.4_797, -7.3_068]]     ).to(lowerCamelCase_     )
        self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3], lowerCamelCase_, atol=1e-4     )     )

   def 	__UpperCAmelCase   (      self      :			Any     )  ->			List[Any]:
        _A    		=  AutoImageProcessor.from_pretrained('openmmlab/upernet-convnext-tiny'     )
        _A    		=  UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-convnext-tiny'     ).to(lowerCamelCase_     )

        _A    		=  prepare_img()
        _A    		=  processor(images=lowerCamelCase_, return_tensors='pt'     ).to(lowerCamelCase_     )

        with torch.no_grad():
             _A    		=  model(**lowerCamelCase_     )

        _A    		=  torch.Size((1, model.config.num_labels, 5_12, 5_12)     )
        self.assertEqual(outputs.logits.shape, lowerCamelCase_     )

        _A    		=  torch.tensor(
            [[-8.8_110, -8.8_110, -8.6_521], [-8.8_110, -8.8_110, -8.6_521], [-8.7_746, -8.7_746, -8.6_130]]     ).to(lowerCamelCase_     )
        self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3], lowerCamelCase_, atol=1e-4     )     )










'''simple docstring'''




import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
							from PIL import Image

							from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
							import torch

if is_tf_available():
							import tensorflow as tf




@require_vision
@require_torchvision
class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			tempfile.mkdtemp()
							SCREAMING_SNAKE_CASE :				List[Any]		=			SamImageProcessor()
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			SamProcessor(lowerCamelCase_						)
							processor.save_pretrained(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			Dict      ,						**lowerCamelCase_				:			List[str]						):

							'''simple docstring'''



							return AutoProcessor.from_pretrained(self.tmpdirname      ,						**lowerCamelCase_						).image_processor


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							shutil.rmtree(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			str						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			[np.random.randint(2_55      ,						size=(3, 30, 4_00)      ,						dtype=np.uinta						)]

							SCREAMING_SNAKE_CASE :				Optional[int]		=			[Image.fromarray(np.moveaxis(lowerCamelCase_      ,						0      ,						-1						)						) for x in image_inputs]

							return image_inputs


					def lowerCamelCase_			(						self				:			Any						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[Any]		=			SamProcessor(image_processor=self.get_image_processor()						)
							processor.save_pretrained(self.tmpdirname						)

							SCREAMING_SNAKE_CASE :				int		=			self.get_image_processor(do_normalize=lowerCamelCase_      ,						padding_value=1.0						)

							SCREAMING_SNAKE_CASE :				Tuple		=			SamProcessor.from_pretrained(self.tmpdirname      ,						do_normalize=lowerCamelCase_      ,						padding_value=1.0						)

							self.assertEqual(processor.image_processor.to_json_string()      ,						image_processor_add_kwargs.to_json_string()						)
							self.assertIsInstance(processor.image_processor      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				List[Any]		=			SamProcessor(image_processor=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Optional[int]		=			self.prepare_image_inputs()

							SCREAMING_SNAKE_CASE :				List[str]		=			image_processor(lowerCamelCase_      ,						return_tensors="""np"""						)
							SCREAMING_SNAKE_CASE :				Dict		=			processor(images=lowerCamelCase_      ,						return_tensors="""np"""						)

							input_feat_extract.pop("""original_sizes"""						)  # pop original_sizes as it is popped in the processor
							input_feat_extract.pop("""reshaped_input_sizes"""						)  # pop original_sizes as it is popped in the processor

							for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()      ,						input_processor[key].sum()      ,						delta=1e-2						)



					@require_torch
					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				List[str]		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			SamProcessor(image_processor=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Any		=			[torch.ones((1, 3, 5, 5)						)]

							SCREAMING_SNAKE_CASE :				int		=			[[17_64, 26_46]]

							SCREAMING_SNAKE_CASE :				Any		=			[[6_83, 10_24]]
							SCREAMING_SNAKE_CASE :				str		=			processor.post_process_masks(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_						)
							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							SCREAMING_SNAKE_CASE :				str		=			processor.post_process_masks(
							    lowerCamelCase_      ,						torch.tensor(lowerCamelCase_						)      ,						torch.tensor(lowerCamelCase_						)						)
							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							# should also work with np
							SCREAMING_SNAKE_CASE :				Optional[int]		=			[np.ones((1, 3, 5, 5)						)]
							SCREAMING_SNAKE_CASE :				Optional[int]		=			processor.post_process_masks(lowerCamelCase_      ,						np.array(lowerCamelCase_						)      ,						np.array(lowerCamelCase_						)						)

							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							SCREAMING_SNAKE_CASE :				Tuple		=			[[1, 0], [0, 1]]
							with self.assertRaises(lowerCamelCase_						):
									SCREAMING_SNAKE_CASE :				Tuple		=			processor.post_process_masks(lowerCamelCase_      ,						np.array(lowerCamelCase_						)      ,						np.array(lowerCamelCase_						)						)







@require_vision
@require_tf
class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			tempfile.mkdtemp()
							SCREAMING_SNAKE_CASE :				Optional[Any]		=			SamImageProcessor()
							SCREAMING_SNAKE_CASE :				Optional[int]		=			SamProcessor(lowerCamelCase_						)
							processor.save_pretrained(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			Any      ,						**lowerCamelCase_				:			str						):

							'''simple docstring'''



							return AutoProcessor.from_pretrained(self.tmpdirname      ,						**lowerCamelCase_						).image_processor


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



							shutil.rmtree(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			Union[str, Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			[np.random.randint(2_55      ,						size=(3, 30, 4_00)      ,						dtype=np.uinta						)]

							SCREAMING_SNAKE_CASE :				str		=			[Image.fromarray(np.moveaxis(lowerCamelCase_      ,						0      ,						-1						)						) for x in image_inputs]

							return image_inputs


					def lowerCamelCase_			(						self				:			List[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			SamProcessor(image_processor=self.get_image_processor()						)
							processor.save_pretrained(self.tmpdirname						)

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			self.get_image_processor(do_normalize=lowerCamelCase_      ,						padding_value=1.0						)

							SCREAMING_SNAKE_CASE :				List[Any]		=			SamProcessor.from_pretrained(self.tmpdirname      ,						do_normalize=lowerCamelCase_      ,						padding_value=1.0						)

							self.assertEqual(processor.image_processor.to_json_string()      ,						image_processor_add_kwargs.to_json_string()						)
							self.assertIsInstance(processor.image_processor      ,						lowerCamelCase_						)


					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				Dict		=			SamProcessor(image_processor=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				int		=			self.prepare_image_inputs()

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			image_processor(lowerCamelCase_      ,						return_tensors="""np"""						)
							SCREAMING_SNAKE_CASE :				List[Any]		=			processor(images=lowerCamelCase_      ,						return_tensors="""np"""						)

							input_feat_extract.pop("""original_sizes"""						)  # pop original_sizes as it is popped in the processor
							input_feat_extract.pop("""reshaped_input_sizes"""						)  # pop reshaped_input_sizes as it is popped in the processor

							for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()      ,						input_processor[key].sum()      ,						delta=1e-2						)



					@require_tf
					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Dict		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				Tuple		=			SamProcessor(image_processor=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			[tf.ones((1, 3, 5, 5)						)]

							SCREAMING_SNAKE_CASE :				Dict		=			[[17_64, 26_46]]

							SCREAMING_SNAKE_CASE :				Any		=			[[6_83, 10_24]]
							SCREAMING_SNAKE_CASE :				str		=			processor.post_process_masks(lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						return_tensors="""tf"""						)
							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							SCREAMING_SNAKE_CASE :				Optional[int]		=			processor.post_process_masks(
							    lowerCamelCase_      ,						tf.convert_to_tensor(lowerCamelCase_						)      ,						tf.convert_to_tensor(lowerCamelCase_						)      ,						return_tensors="""tf"""      ,						)
							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							# should also work with np
							SCREAMING_SNAKE_CASE :				Optional[int]		=			[np.ones((1, 3, 5, 5)						)]
							SCREAMING_SNAKE_CASE :				List[str]		=			processor.post_process_masks(
							    lowerCamelCase_      ,						np.array(lowerCamelCase_						)      ,						np.array(lowerCamelCase_						)      ,						return_tensors="""tf"""						)

							self.assertEqual(masks[0].shape      ,						(1, 3, 17_64, 26_46)						)

							SCREAMING_SNAKE_CASE :				str		=			[[1, 0], [0, 1]]
							with self.assertRaises(tf.errors.InvalidArgumentError						):
									SCREAMING_SNAKE_CASE :				Tuple		=			processor.post_process_masks(
									    lowerCamelCase_      ,						np.array(lowerCamelCase_						)      ,						np.array(lowerCamelCase_						)      ,						return_tensors="""tf"""						)







@require_vision
@require_torchvision
class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				int		=			tempfile.mkdtemp()
							SCREAMING_SNAKE_CASE :				int		=			SamImageProcessor()
							SCREAMING_SNAKE_CASE :				str		=			SamProcessor(lowerCamelCase_						)
							processor.save_pretrained(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			Tuple      ,						**lowerCamelCase_				:			List[Any]						):

							'''simple docstring'''



							return AutoProcessor.from_pretrained(self.tmpdirname      ,						**lowerCamelCase_						).image_processor


					def lowerCamelCase_			(						self				:			int						):

							'''simple docstring'''



							shutil.rmtree(self.tmpdirname						)


					def lowerCamelCase_			(						self				:			Dict						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			[np.random.randint(2_55      ,						size=(3, 30, 4_00)      ,						dtype=np.uinta						)]

							SCREAMING_SNAKE_CASE :				Dict		=			[Image.fromarray(np.moveaxis(lowerCamelCase_      ,						0      ,						-1						)						) for x in image_inputs]

							return image_inputs


					@is_pt_tf_cross_test
					def lowerCamelCase_			(						self				:			Optional[Any]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				str		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				Dict		=			SamProcessor(image_processor=lowerCamelCase_						)
							SCREAMING_SNAKE_CASE :				Any		=			np.random.randint(0      ,						2      ,						size=(1, 3, 5, 5)						).astype(np.floataa						)
							SCREAMING_SNAKE_CASE :				str		=			[tf.convert_to_tensor(lowerCamelCase_						)]
							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			[torch.tensor(lowerCamelCase_						)]

							SCREAMING_SNAKE_CASE :				Tuple		=			[[17_64, 26_46]]

							SCREAMING_SNAKE_CASE :				Optional[Any]		=			[[6_83, 10_24]]
							SCREAMING_SNAKE_CASE :				Tuple		=			processor.post_process_masks(
							    lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						return_tensors="""tf"""						)
							SCREAMING_SNAKE_CASE :				Any		=			processor.post_process_masks(
							    lowerCamelCase_      ,						lowerCamelCase_      ,						lowerCamelCase_      ,						return_tensors="""pt"""						)

							self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()						)						)



					@is_pt_tf_cross_test
					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			self.get_image_processor()

							SCREAMING_SNAKE_CASE :				Union[str, Any]		=			SamProcessor(image_processor=lowerCamelCase_						)

							SCREAMING_SNAKE_CASE :				Any		=			self.prepare_image_inputs()

							SCREAMING_SNAKE_CASE :				int		=			image_processor(lowerCamelCase_      ,						return_tensors="""pt"""						)["""pixel_values"""].numpy()
							SCREAMING_SNAKE_CASE :				Tuple		=			processor(images=lowerCamelCase_      ,						return_tensors="""pt"""						)["""pixel_values"""].numpy()

							SCREAMING_SNAKE_CASE :				Dict		=			image_processor(lowerCamelCase_      ,						return_tensors="""tf"""						)["""pixel_values"""].numpy()
							SCREAMING_SNAKE_CASE :				Dict		=			processor(images=lowerCamelCase_      ,						return_tensors="""tf"""						)["""pixel_values"""].numpy()

							self.assertTrue(np.allclose(lowerCamelCase_      ,						lowerCamelCase_						)						)
							self.assertTrue(np.allclose(lowerCamelCase_      ,						lowerCamelCase_						)						)
							self.assertTrue(np.allclose(lowerCamelCase_      ,						lowerCamelCase_						)						)



