"""simple docstring"""






from __future__ import annotations

import inspect
import unittest

import numpy as np

from transformers import SwinConfig
from transformers.testing_utils import require_tf, require_vision, slow, to_atuple
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers.models.swin.modeling_tf_swin import (
						    TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFSwinForImageClassification,
						    TFSwinForMaskedImageModeling,
						    TFSwinModel,
						)


if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor
class 							snake_case			:




					"""simple docstring"""

					def __init__(							self  :      Any       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      Optional[Any]=13       ,lowerCamelCase__  :      Optional[int]=32       ,lowerCamelCase__  :      List[str]=2       ,lowerCamelCase__  :      Any=3       ,lowerCamelCase__  :      Union[str, Any]=16       ,lowerCamelCase__  :      Optional[Any]=[1, 2, 1]       ,lowerCamelCase__  :      str=[2, 2, 4]       ,lowerCamelCase__  :      Any=2       ,lowerCamelCase__  :      List[str]=2.0       ,lowerCamelCase__  :      Union[str, Any]=True       ,lowerCamelCase__  :      str=0.0       ,lowerCamelCase__  :      Union[str, Any]=0.0       ,lowerCamelCase__  :      Optional[Any]=0.1       ,lowerCamelCase__  :      Optional[int]="gelu"       ,lowerCamelCase__  :      Any=False       ,lowerCamelCase__  :      List[Any]=True       ,lowerCamelCase__  :      Union[str, Any]=0.0_2       ,lowerCamelCase__  :      List[str]=1e-5       ,lowerCamelCase__  :      List[str]=True       ,lowerCamelCase__  :      List[str]=None       ,lowerCamelCase__  :      Optional[Any]=True       ,lowerCamelCase__  :      Any=10       ,lowerCamelCase__  :      Tuple=8       ,):
									UpperCAmelCase__			 =				parent
									UpperCAmelCase__			 =				batch_size
									UpperCAmelCase__			 =				image_size
									UpperCAmelCase__			 =				patch_size
									UpperCAmelCase__			 =				num_channels
									UpperCAmelCase__			 =				embed_dim
									UpperCAmelCase__			 =				depths
									UpperCAmelCase__			 =				num_heads
									UpperCAmelCase__			 =				window_size
									UpperCAmelCase__			 =				mlp_ratio
									UpperCAmelCase__			 =				qkv_bias
									UpperCAmelCase__			 =				hidden_dropout_prob
									UpperCAmelCase__			 =				attention_probs_dropout_prob
									UpperCAmelCase__			 =				drop_path_rate
									UpperCAmelCase__			 =				hidden_act
									UpperCAmelCase__			 =				use_absolute_embeddings
									UpperCAmelCase__			 =				patch_norm
									UpperCAmelCase__			 =				layer_norm_eps
									UpperCAmelCase__			 =				initializer_range
									UpperCAmelCase__			 =				is_training
									UpperCAmelCase__			 =				scope
									UpperCAmelCase__			 =				use_labels
									UpperCAmelCase__			 =				type_sequence_label_size
									UpperCAmelCase__			 =				encoder_stride







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

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

									UpperCAmelCase__			 =				self.get_config()

									return config, pixel_values, labels







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									return SwinConfig(
									    image_size=self.image_size       ,patch_size=self.patch_size       ,num_channels=self.num_channels       ,embed_dim=self.embed_dim       ,depths=self.depths       ,num_heads=self.num_heads       ,window_size=self.window_size       ,mlp_ratio=self.mlp_ratio       ,qkv_bias=self.qkv_bias       ,hidden_dropout_prob=self.hidden_dropout_prob       ,attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,drop_path_rate=self.drop_path_rate       ,hidden_act=self.hidden_act       ,use_absolute_embeddings=self.use_absolute_embeddings       ,path_norm=self.patch_norm       ,layer_norm_eps=self.layer_norm_eps       ,initializer_range=self.initializer_range       ,encoder_stride=self.encoder_stride       ,)







					def 						__lowerCAmelCase		(							self  :      Tuple       ,lowerCamelCase__  :      str       ,lowerCamelCase__  :      Tuple       ,lowerCamelCase__  :      Any     ):
									UpperCAmelCase__			 =				TFSwinModel(config=a_     )
									UpperCAmelCase__			 =				model(a_     )

									UpperCAmelCase__			 =				((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths     ) - 1))
									UpperCAmelCase__			 =				int(config.embed_dim * 2 ** (len(config.depths     ) - 1)     )

									self.parent.assertEqual(result.last_hidden_state.shape       ,(self.batch_size, expected_seq_len, expected_dim)     )







					def 						__lowerCAmelCase		(							self  :      int       ,lowerCamelCase__  :      Any       ,lowerCamelCase__  :      List[str]       ,lowerCamelCase__  :      List[str]     ):
									UpperCAmelCase__			 =				TFSwinForMaskedImageModeling(config=a_     )
									UpperCAmelCase__			 =				model(a_     )
									self.parent.assertEqual(
									    result.logits.shape       ,(self.batch_size, self.num_channels, self.image_size, self.image_size)     )

									# test greyscale images
									UpperCAmelCase__			 =				1
									UpperCAmelCase__			 =				TFSwinForMaskedImageModeling(a_     )

									UpperCAmelCase__			 =				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
									UpperCAmelCase__			 =				model(a_     )
									self.parent.assertEqual(result.logits.shape       ,(self.batch_size, 1, self.image_size, self.image_size)     )







					def 						__lowerCAmelCase		(							self  :      Dict       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      int       ,lowerCamelCase__  :      Dict     ):
									UpperCAmelCase__			 =				self.type_sequence_label_size
									UpperCAmelCase__			 =				TFSwinForImageClassification(a_     )
									UpperCAmelCase__			 =				model(a_       ,labels=a_     )
									self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.type_sequence_label_size)     )

									# test greyscale images
									UpperCAmelCase__			 =				1
									UpperCAmelCase__			 =				TFSwinForImageClassification(a_     )
									UpperCAmelCase__			 =				floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
									UpperCAmelCase__			 =				model(a_     )
									self.parent.assertEqual(result.logits.shape       ,(self.batch_size, self.type_sequence_label_size)     )







					def 						__lowerCAmelCase		(							self  :      Tuple     ):
									UpperCAmelCase__			 =				self.prepare_config_and_inputs()
									UpperCAmelCase__			 =				config_and_inputs
									UpperCAmelCase__			 =				{"""pixel_values""": pixel_values}
									return config, inputs_dict






@require_tf
class 							snake_case			(					_lowerCamelCase ,       _lowerCamelCase ,       unittest.TestCase							):




					"""simple docstring"""

					snake_case__							       =					(
					    (
					        TFSwinModel,
					        TFSwinForImageClassification,
					        TFSwinForMaskedImageModeling,
					    )
					    if is_tf_available()
					    else ()
					)
					snake_case__							       =					(
					    {"feature-extraction": TFSwinModel, "image-classification": TFSwinForImageClassification}
					    if is_tf_available()
					    else {}
					)

					snake_case__							       =					False
					snake_case__							       =					False
					snake_case__							       =					False
					snake_case__							       =					False







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				TFSwinModelTester(self     )
									UpperCAmelCase__			 =				ConfigTester(self       ,config_class=a_       ,embed_dim=37     )







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									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 						__lowerCAmelCase		(							self  :      List[Any]     ):
									return







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*a_     )







					def 						__lowerCAmelCase		(							self  :      int     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_image_modeling(*a_     )







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_image_classification(*a_     )







					@unittest.skip(reason='Swin does not use inputs_embeds'     )
					def 						__lowerCAmelCase		(							self  :      Union[str, Any]     ):
									pass







					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
													UpperCAmelCase__			 =				model_class(a_     )
													self.assertIsInstance(model.get_input_embeddings()       ,tf.keras.layers.Layer     )
													UpperCAmelCase__			 =				model.get_output_embeddings()
													self.assertTrue(x is None or isinstance(a_       ,tf.keras.layers.Dense     )     )







					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()

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

													UpperCAmelCase__			 =				["""pixel_values"""]
													self.assertListEqual(arg_names[:1]       ,a_     )







					def 						__lowerCAmelCase		(							self  :      Union[str, Any]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()
									UpperCAmelCase__			 =				True

									for model_class in self.all_model_classes:
													UpperCAmelCase__			 =				True
													UpperCAmelCase__			 =				False
													UpperCAmelCase__			 =				True
													UpperCAmelCase__			 =				model_class(a_     )
													UpperCAmelCase__			 =				model(**self._prepare_for_class(a_       ,a_     )     )
													UpperCAmelCase__			 =				outputs.attentions
													UpperCAmelCase__			 =				len(self.model_tester.depths     )
													self.assertEqual(len(a_     )       ,a_     )

													# check that output_attentions also work using config
													del inputs_dict["output_attentions"]
													UpperCAmelCase__			 =				True
													UpperCAmelCase__			 =				config.window_size**2
													UpperCAmelCase__			 =				model_class(a_     )
													UpperCAmelCase__			 =				model(**self._prepare_for_class(a_       ,a_     )     )
													UpperCAmelCase__			 =				outputs.attentions
													self.assertEqual(len(a_     )       ,a_     )

													self.assertListEqual(
													    list(attentions[0].shape[-3:]     )       ,[self.model_tester.num_heads[0], window_size_squared, window_size_squared]       ,)
													UpperCAmelCase__			 =				len(a_     )

													# Check attention is always last and order is fine
													UpperCAmelCase__			 =				True
													UpperCAmelCase__			 =				True
													UpperCAmelCase__			 =				model_class(a_     )
													UpperCAmelCase__			 =				model(**self._prepare_for_class(a_       ,a_     )     )

													if hasattr(self.model_tester       ,'num_hidden_states_types'     ):
																	UpperCAmelCase__			 =				self.model_tester.num_hidden_states_types
													else:
																	# also another +1 for reshaped_hidden_states
																	UpperCAmelCase__			 =				2
													self.assertEqual(out_len + added_hidden_states       ,len(a_     )     )

													UpperCAmelCase__			 =				outputs.attentions

													self.assertEqual(len(a_     )       ,a_     )

													self.assertListEqual(
													    list(self_attentions[0].shape[-3:]     )       ,[self.model_tester.num_heads[0], window_size_squared, window_size_squared]       ,)







					def 						__lowerCAmelCase		(							self  :      Optional[Any]       ,lowerCamelCase__  :      Tuple       ,lowerCamelCase__  :      int       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      Any     ):
									UpperCAmelCase__			 =				model_class(a_     )
									UpperCAmelCase__			 =				model(**self._prepare_for_class(a_       ,a_     )     )
									UpperCAmelCase__			 =				outputs.hidden_states

									UpperCAmelCase__			 =				getattr(
									    self.model_tester       ,'expected_num_hidden_layers'       ,len(self.model_tester.depths     ) + 1     )
									self.assertEqual(len(a_     )       ,a_     )

									# Swin has a different seq_length
									UpperCAmelCase__			 =				to_atuple(config.patch_size     )

									UpperCAmelCase__			 =				(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

									self.assertListEqual(
									    list(hidden_states[0].shape[-2:]     )       ,[num_patches, self.model_tester.embed_dim]       ,)

									UpperCAmelCase__			 =				outputs.reshaped_hidden_states
									self.assertEqual(len(a_     )       ,a_     )

									UpperCAmelCase__			 =				reshaped_hidden_states[0].shape

									UpperCAmelCase__			 =				tf.reshape(reshaped_hidden_states[0]       ,(batch_size, num_channels, height * width)     )
									UpperCAmelCase__			 =				tf.transpose(a_       ,(0, 2, 1)     )

									self.assertListEqual(
									    list(reshaped_hidden_states.shape[-2:]     )       ,[num_patches, self.model_tester.embed_dim]       ,)







					def 						__lowerCAmelCase		(							self  :      Optional[int]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()

									UpperCAmelCase__			 =				to_atuple(self.model_tester.image_size     )

									for model_class in self.all_model_classes:
													UpperCAmelCase__			 =				True
													self.check_hidden_states_output(a_       ,a_       ,a_       ,a_     )

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

													self.check_hidden_states_output(a_       ,a_       ,a_       ,a_     )







					def 						__lowerCAmelCase		(							self  :      List[Any]     ):
									UpperCAmelCase__			 =				self.model_tester.prepare_config_and_inputs_for_common()
									UpperCAmelCase__			 =				3

									UpperCAmelCase__			 =				to_atuple(self.model_tester.image_size     )
									UpperCAmelCase__			 =				to_atuple(config.patch_size     )

									UpperCAmelCase__			 =				image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
									UpperCAmelCase__			 =				image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

									for model_class in self.all_model_classes:
													UpperCAmelCase__			 =				True
													self.check_hidden_states_output(a_       ,a_       ,a_       ,(padded_height, padded_width)     )

													# check that output_hidden_states also work using config
													del inputs_dict["output_hidden_states"]
													UpperCAmelCase__			 =				True
													self.check_hidden_states_output(a_       ,a_       ,a_       ,(padded_height, padded_width)     )







					@slow
					def 						__lowerCAmelCase		(							self  :      Dict     ):
									for model_name in TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCAmelCase__			 =				TFSwinModel.from_pretrained(a_     )
													self.assertIsNotNone(a_     )






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




					"""simple docstring"""

					@cached_property
					def 						__lowerCAmelCase		(							self  :      Dict     ):
									return (
									    AutoImageProcessor.from_pretrained('microsoft/swin-tiny-patch4-window7-224'     )
									    if is_vision_available()
									    else None
									)







					@slow
					def 						__lowerCAmelCase		(							self  :      List[str]     ):
									UpperCAmelCase__			 =				TFSwinForImageClassification.from_pretrained('microsoft/swin-tiny-patch4-window7-224'     )
									UpperCAmelCase__			 =				self.default_image_processor

									UpperCAmelCase__			 =				Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
									UpperCAmelCase__			 =				image_processor(images=a_       ,return_tensors='tf'     )

									# forward pass
									UpperCAmelCase__			 =				model(a_     )

									# verify the logits
									UpperCAmelCase__			 =				tf.TensorShape((1, 1_000)     )
									self.assertEqual(outputs.logits.shape       ,a_     )
									UpperCAmelCase__			 =				tf.constant([-0.0_9_4_8, -0.6_4_5_4, -0.0_9_2_1]     )
									self.assertTrue(np.allclose(outputs.logits[0, :3]       ,a_       ,atol=1e-4     )     )








'''simple docstring'''






import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import BlipImageProcessor



class 				lowercase			(    unittest.TestCase							):


 """simple docstring"""


 def __init__(				self    ,a_    ,a_=7    ,a_=3    ,a_=18    ,a_=30    ,a_=400    ,a_=True    ,a_=None    ,a_=True    ,a_=False    ,a_=[0.4814_5466, 0.457_8275, 0.4082_1073]    ,a_=[0.2686_2954, 0.2613_0258, 0.2757_7711]    ,a_=True    ,)						->  Optional[int]:
        _UpperCAmelCase    :		Dict     	=					size if size is not None else {"""height""": 20, """width""": 20}
        _UpperCAmelCase    :		Dict     	=					parent
        _UpperCAmelCase    :		Tuple     	=					batch_size
        _UpperCAmelCase    :		Optional[int]     	=					num_channels
        _UpperCAmelCase    :		int     	=					image_size
        _UpperCAmelCase    :		List[Any]     	=					min_resolution
        _UpperCAmelCase    :		str     	=					max_resolution
        _UpperCAmelCase    :		Tuple     	=					do_resize
        _UpperCAmelCase    :		Union[str, Any]     	=					size
        _UpperCAmelCase    :		int     	=					do_normalize
        _UpperCAmelCase    :		List[str]     	=					image_mean
        _UpperCAmelCase    :		Any     	=					image_std
        _UpperCAmelCase    :		Union[str, Any]     	=					do_pad
        _UpperCAmelCase    :		Tuple     	=					do_convert_rgb







 def _snake_case					(				self				)						->  List[str]:
        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_convert_rgb": self.do_convert_rgb,
            "do_pad": self.do_pad,
        }







 def _snake_case					(				self    ,a_=False    ,a_=False    ,a_=False				)						->  Dict:
        assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

        if equal_resolution:
               _UpperCAmelCase    :		Union[str, Any]     	=					[]
               for i in range(self.batch_size				):
                      image_inputs.append(
                          np.random.randint(
                              255    ,size=(self.num_channels, self.max_resolution, self.max_resolution)    ,dtype=np.uinta				)				)
        else:
               _UpperCAmelCase    :		Optional[int]     	=					[]
               for i in range(self.batch_size				):
                      _UpperCAmelCase	,_UpperCAmelCase    :		int     	=					np.random.choice(np.arange(self.min_resolution    ,self.max_resolution				)    ,2				)
                      image_inputs.append(np.random.randint(255    ,size=(self.num_channels, width, height)    ,dtype=np.uinta				)				)

        if not numpify and not torchify:
               # PIL expects the channel dimension as last dimension
               _UpperCAmelCase    :		Any     	=					[Image.fromarray(np.moveaxis(a_    ,0    ,-1				)				) for x in image_inputs]

        if torchify:
               _UpperCAmelCase    :		Optional[int]     	=					[torch.from_numpy(a_				) for x in image_inputs]

        return image_inputs







@require_torch
@require_vision
class 				lowercase			(    _lowerCamelCase   ,   unittest.TestCase							):


 """simple docstring"""


 UpperCAmelCase		      =    BlipImageProcessor if is_vision_available() else None







 def _snake_case					(				self				)						->  List[Any]:
        _UpperCAmelCase    :		Dict     	=					BlipImageProcessingTester(self				)







 @property
 def _snake_case					(				self				)						->  str:
        return self.image_processor_tester.prepare_image_processor_dict()







 def _snake_case					(				self				)						->  Tuple:
        _UpperCAmelCase    :		List[str]     	=					self.image_processing_class(**self.image_processor_dict				)
        self.assertTrue(hasattr(a_    ,"""do_resize"""				)				)
        self.assertTrue(hasattr(a_    ,"""size"""				)				)
        self.assertTrue(hasattr(a_    ,"""do_normalize"""				)				)
        self.assertTrue(hasattr(a_    ,"""image_mean"""				)				)
        self.assertTrue(hasattr(a_    ,"""image_std"""				)				)
        self.assertTrue(hasattr(a_    ,"""do_convert_rgb"""				)				)







 def _snake_case					(				self				)						->  Any:
        pass







 def _snake_case					(				self				)						->  Union[str, Any]:
        # Initialize image_processor
        _UpperCAmelCase    :		List[str]     	=					self.image_processing_class(**self.image_processor_dict				)
        # create random PIL images
        _UpperCAmelCase    :		str     	=					self.image_processor_tester.prepare_inputs(equal_resolution=a_				)
        for image in image_inputs:
               self.assertIsInstance(a_    ,Image.Image				)

        # Test not batched input
        _UpperCAmelCase    :		List[str]     	=					image_processor(image_inputs[0]    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)

        # Test batched
        _UpperCAmelCase    :		List[str]     	=					image_processor(a_    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)







 def _snake_case					(				self				)						->  Optional[Any]:
        # Initialize image_processor
        _UpperCAmelCase    :		str     	=					self.image_processing_class(**self.image_processor_dict				)
        # create random numpy tensors
        _UpperCAmelCase    :		str     	=					self.image_processor_tester.prepare_inputs(equal_resolution=a_    ,numpify=a_				)
        for image in image_inputs:
               self.assertIsInstance(a_    ,np.ndarray				)

        # Test not batched input
        _UpperCAmelCase    :		Dict     	=					image_processor(image_inputs[0]    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)

        # Test batched
        _UpperCAmelCase    :		int     	=					image_processor(a_    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)







 def _snake_case					(				self				)						->  List[str]:
        # Initialize image_processor
        _UpperCAmelCase    :		Dict     	=					self.image_processing_class(**self.image_processor_dict				)
        # create random PyTorch tensors
        _UpperCAmelCase    :		Union[str, Any]     	=					self.image_processor_tester.prepare_inputs(equal_resolution=a_    ,torchify=a_				)
        for image in image_inputs:
               self.assertIsInstance(a_    ,torch.Tensor				)

        # Test not batched input
        _UpperCAmelCase    :		str     	=					image_processor(image_inputs[0]    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)

        # Test batched
        _UpperCAmelCase    :		Optional[Any]     	=					image_processor(a_    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)







@require_torch
@require_vision
class 				lowercase			(    _lowerCamelCase   ,   unittest.TestCase							):


 """simple docstring"""


 UpperCAmelCase		      =    BlipImageProcessor if is_vision_available() else None







 def _snake_case					(				self				)						->  Optional[Any]:
        _UpperCAmelCase    :		Optional[Any]     	=					BlipImageProcessingTester(self    ,num_channels=4				)
        _UpperCAmelCase    :		List[Any]     	=					3







 @property
 def _snake_case					(				self				)						->  int:
        return self.image_processor_tester.prepare_image_processor_dict()







 def _snake_case					(				self				)						->  Optional[Any]:
        _UpperCAmelCase    :		Optional[Any]     	=					self.image_processing_class(**self.image_processor_dict				)
        self.assertTrue(hasattr(a_    ,"""do_resize"""				)				)
        self.assertTrue(hasattr(a_    ,"""size"""				)				)
        self.assertTrue(hasattr(a_    ,"""do_normalize"""				)				)
        self.assertTrue(hasattr(a_    ,"""image_mean"""				)				)
        self.assertTrue(hasattr(a_    ,"""image_std"""				)				)
        self.assertTrue(hasattr(a_    ,"""do_convert_rgb"""				)				)







 def _snake_case					(				self				)						->  Union[str, Any]:
        pass







 def _snake_case					(				self				)						->  List[Any]:
        # Initialize image_processor
        _UpperCAmelCase    :		Any     	=					self.image_processing_class(**self.image_processor_dict				)
        # create random PIL images
        _UpperCAmelCase    :		Optional[Any]     	=					self.image_processor_tester.prepare_inputs(equal_resolution=a_				)
        for image in image_inputs:
               self.assertIsInstance(a_    ,Image.Image				)

        # Test not batched input
        _UpperCAmelCase    :		List[Any]     	=					image_processor(image_inputs[0]    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                1,
                self.expected_encoded_image_num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)

        # Test batched
        _UpperCAmelCase    :		Dict     	=					image_processor(a_    ,return_tensors="""pt"""				).pixel_values
        self.assertEqual(
            encoded_images.shape    ,(
                self.image_processor_tester.batch_size,
                self.expected_encoded_image_num_channels,
                self.image_processor_tester.size["""height"""],
                self.image_processor_tester.size["""width"""],
            )    ,)



