






"""simple docstring"""




import inspect
import unittest

import numpy as np

from transformers import ViTConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
					import jax

					from transformers.models.vit.modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel




class    lowercase_    (unittest.TestCase     ):






						def __init__(    self     ,     a_     ,     a_=1_3     ,     a_=3_0     ,     a_=2     ,     a_=3     ,     a_=True     ,     a_=True     ,     a_=3_2     ,     a_=5     ,     a_=4     ,     a_=3_7     ,     a_="gelu"     ,     a_=0.1     ,     a_=0.1     ,     a_=1_0     ,     a_=0.02     ,     )	->List[Any]:







								'''simple docstring'''


								_a							=	parent
								_a							=	batch_size
								_a							=	image_size
								_a							=	patch_size
								_a							=	num_channels
								_a							=	is_training
								_a							=	use_labels
								_a							=	hidden_size
								_a							=	num_hidden_layers
								_a							=	num_attention_heads
								_a							=	intermediate_size
								_a							=	hidden_act
								_a							=	hidden_dropout_prob
								_a							=	attention_probs_dropout_prob
								_a							=	type_sequence_label_size
								_a							=	initializer_range

								# in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
								_a							=	(image_size // patch_size) ** 2
								_a							=	num_patches + 1






						def 			lowerCamelCase__    (    self	)	->Tuple:







								'''simple docstring'''


								_a							=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

								_a							=	ViTConfig(
								    image_size=self.image_size     ,     patch_size=self.patch_size     ,     num_channels=self.num_channels     ,     hidden_size=self.hidden_size     ,     num_hidden_layers=self.num_hidden_layers     ,     num_attention_heads=self.num_attention_heads     ,     intermediate_size=self.intermediate_size     ,     hidden_act=self.hidden_act     ,     hidden_dropout_prob=self.hidden_dropout_prob     ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,     is_decoder=__A     ,     initializer_range=self.initializer_range     ,     )

								return config, pixel_values






						def 			lowerCamelCase__    (    self     ,     a_     ,     a_	)	->Optional[int]:







								'''simple docstring'''


								_a							=	FlaxViTModel(config=__A	)
								_a							=	model(__A	)
								# expected sequence length = num_patches + 1 (we add 1 for the [CLS] token)
								_a							=	(self.image_size, self.image_size)
								_a							=	(self.patch_size, self.patch_size)
								_a							=	(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
								self.parent.assertEqual(result.last_hidden_state.shape     ,     (self.batch_size, num_patches + 1, self.hidden_size)	)






						def 			lowerCamelCase__    (    self     ,     a_     ,     a_	)	->Union[str, Any]:







								'''simple docstring'''


								_a							=	self.type_sequence_label_size
								_a							=	FlaxViTForImageClassification(config=__A	)
								_a							=	model(__A	)
								self.parent.assertEqual(result.logits.shape     ,     (self.batch_size, self.type_sequence_label_size)	)

								# test greyscale images
								_a							=	1
								_a							=	FlaxViTForImageClassification(__A	)

								_a							=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]	)
								_a							=	model(__A	)






						def 			lowerCamelCase__    (    self	)	->List[Any]:







								'''simple docstring'''


								_a							=	self.prepare_config_and_inputs()
								(
								    _a		
								)							=	config_and_inputs
								_a							=	{"pixel_values": pixel_values}
								return config, inputs_dict







@require_flax
class    lowercase_    (UpperCamelCase_,    unittest.TestCase     ):
						A__	:		Optional[Any]       			=				(FlaxViTModel, FlaxViTForImageClassification) if is_flax_available() else ()






						def 			lowerCamelCase__    (    self	)	->Optional[Any]:







								'''simple docstring'''


								_a							=	FlaxViTModelTester(self	)
								_a							=	ConfigTester(self     ,     config_class=__A     ,     has_text_modality=__A     ,     hidden_size=3_7	)






						def 			lowerCamelCase__    (    self	)	->str:







								'''simple docstring'''


								self.config_tester.run_common_tests()






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







								'''simple docstring'''


								_a							=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__A	)






						def 			lowerCamelCase__    (    self	)	->str:







								'''simple docstring'''


								_a							=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*__A	)






						def 			lowerCamelCase__    (    self	)	->Tuple:







								'''simple docstring'''


								_a							=	self.model_tester.prepare_config_and_inputs_for_common()

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

										_a							=	["pixel_values"]
										self.assertListEqual(arg_names[:1]     ,     __A	)






						def 			lowerCamelCase__    (    self	)	->Any:







								'''simple docstring'''


								_a							=	self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
										with self.subTest(model_class.__name__	):
												_a							=	self._prepare_for_class(__A     ,     __A	)
												_a							=	model_class(__A	)

												@jax.jit
												def model_jitted(a_     ,     **a_	):
														return model(pixel_values=__A     ,     **__A	)

												with self.subTest("JIT Enabled"	):
														_a							=	model_jitted(**__A	).to_tuple()

												with self.subTest("JIT Disabled"	):
														with jax.disable_jit():
																_a							=	model_jitted(**__A	).to_tuple()

												self.assertEqual(len(__A	)     ,     len(__A	)	)
												for jitted_output, output in zip(__A     ,     __A	):
														self.assertEqual(jitted_output.shape     ,     output.shape	)






						@slow
						def 			lowerCamelCase__    (    self	)	->Optional[int]:







								'''simple docstring'''


								for model_class_name in self.all_model_classes:
										_a							=	model_class_name.from_pretrained("google/vit-base-patch16-224"	)
										_a							=	model(np.ones((1, 3, 2_2_4, 2_2_4)	)	)
										self.assertIsNotNone(__A	)










"""simple docstring"""




import warnings

from ...utils import logging
from .image_processing_yolos import YolosImageProcessor


UpperCamelCase							       =    logging.get_logger(__name__)




class    lowercase_    (_UpperCAmelCase     ):






      def __init__(    self     ,     *a_     ,     **a_	)	->None:







        '''simple docstring'''


        warnings.warn(
            "The class YolosFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"
            " use YolosImageProcessor instead."     ,     a_     ,     )
        super().__init__(*a_     ,     **a_	)


