



'''simple docstring'''




import inspect
import unittest

from transformers import MobileNetVaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import MobileNetVaForImageClassification, MobileNetVaModel
						from transformers.models.mobilenet_va.modeling_mobilenet_va import MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import MobileNetVaImageProcessor






class 						_UpperCamelCase  (							lowerCamelCase__    ):


			'''simple docstring'''

			def UpperCamelCase__					(							self     : Optional[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		self.config_class(**self.inputs_dict						)
					self.parent.assertTrue(hasattr(lowerCAmelCase__							,     """tf_padding"""						)						)
					self.parent.assertTrue(hasattr(lowerCAmelCase__							,     """depth_multiplier"""						)						)






class 						_UpperCamelCase  :


			'''simple docstring'''

			def __init__(							self     : Dict							,     lowerCAmelCase__     : Optional[Any]							,     lowerCAmelCase__     : Optional[int]=1_3							,     lowerCAmelCase__     : Any=3							,     lowerCAmelCase__     : int=3_2							,     lowerCAmelCase__     : List[str]=0.25							,     lowerCAmelCase__     : Union[str, Any]=8							,     lowerCAmelCase__     : Union[str, Any]=True							,     lowerCAmelCase__     : List[Any]=1_0_2_4							,     lowerCAmelCase__     : Optional[int]=3_2							,     lowerCAmelCase__     : Tuple="relu6"							,     lowerCAmelCase__     : int=0.1							,     lowerCAmelCase__     : Optional[int]=0.02							,     lowerCAmelCase__     : Any=True							,     lowerCAmelCase__     : Dict=True							,     lowerCAmelCase__     : int=1_0							,     lowerCAmelCase__     : Dict=None							,     ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Any           =		parent
					__SCREAMING_SNAKE_CASE       :		Any           =		batch_size
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		num_channels
					__SCREAMING_SNAKE_CASE       :		Tuple           =		image_size
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		depth_multiplier
					__SCREAMING_SNAKE_CASE       :		Tuple           =		min_depth
					__SCREAMING_SNAKE_CASE       :		int           =		tf_padding
					__SCREAMING_SNAKE_CASE       :		Any           =		int(last_hidden_size * depth_multiplier						)
					__SCREAMING_SNAKE_CASE       :		List[Any]           =		output_stride
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		hidden_act
					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		classifier_dropout_prob
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		use_labels
					__SCREAMING_SNAKE_CASE       :		Tuple           =		is_training
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		num_labels
					__SCREAMING_SNAKE_CASE       :		Any           =		initializer_range
					__SCREAMING_SNAKE_CASE       :		List[str]           =		scope

			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		None
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		None
					if self.use_labels:
							__SCREAMING_SNAKE_CASE       :		int           =		ids_tensor([self.batch_size]							,     self.num_labels						)
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		ids_tensor([self.batch_size, self.image_size, self.image_size]							,     self.num_labels						)

					__SCREAMING_SNAKE_CASE       :		Any           =		self.get_config()

					return config, pixel_values, labels, pixel_labels

			def UpperCamelCase__					(							self     : int						):





					"""simple docstring"""






					return MobileNetVaConfig(
					    num_channels=self.num_channels							,     image_size=self.image_size							,     depth_multiplier=self.depth_multiplier							,     min_depth=self.min_depth							,     tf_padding=self.tf_padding							,     hidden_act=self.hidden_act							,     classifier_dropout_prob=self.classifier_dropout_prob							,     initializer_range=self.initializer_range							,     )

			def UpperCamelCase__					(							self     : int							,     lowerCAmelCase__     : List[Any]							,     lowerCAmelCase__     : List[Any]							,     lowerCAmelCase__     : Tuple							,     lowerCAmelCase__     : Any						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		MobileNetVaModel(config=lowerCAmelCase__						)
					model.to(lowerCAmelCase__						)
					model.eval()
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		model(lowerCAmelCase__						)
					self.parent.assertEqual(
					    result.last_hidden_state.shape							,     (
					        self.batch_size,
					        self.last_hidden_size,
					        self.image_size // self.output_stride,
					        self.image_size // self.output_stride,
					    )							,     )

			def UpperCamelCase__					(							self     : int							,     lowerCAmelCase__     : Union[str, Any]							,     lowerCAmelCase__     : Optional[int]							,     lowerCAmelCase__     : List[Any]							,     lowerCAmelCase__     : Tuple						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Any           =		self.num_labels
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		MobileNetVaForImageClassification(lowerCAmelCase__						)
					model.to(lowerCAmelCase__						)
					model.eval()
					__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		model(lowerCAmelCase__							,     labels=lowerCAmelCase__						)
					self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.num_labels)						)



			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Dict           =		self.prepare_config_and_inputs()
					__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       :		str           =		config_and_inputs
					__SCREAMING_SNAKE_CASE       :		int           =		{"""pixel_values""": pixel_values}
					return config, inputs_dict






@require_torch
class 						_UpperCamelCase  (							lowerCamelCase__    ,					lowerCamelCase__    ,					unittest.TestCase    ):


			'''simple docstring'''

			_A      :		List[Any]			    =		(MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
			_A      :		str			    =		(
			    {'''feature-extraction''': MobileNetVaModel, '''image-classification''': MobileNetVaForImageClassification}
			    if is_torch_available()
			    else {}
			)

			_A      :		Union[str, Any]			    =		False
			_A      :		int			    =		False
			_A      :		Union[str, Any]			    =		False
			_A      :		Optional[Any]			    =		False

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





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		MobileNetVaModelTester(self						)
					__SCREAMING_SNAKE_CASE       :		Tuple           =		MobileNetVaConfigTester(self							,     config_class=lowerCAmelCase__							,     has_text_modality=lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					self.config_tester.run_common_tests()

			@unittest.skip(reason="""MobileNetV1 does not use inputs_embeds"""						)
			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					pass

			@unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""						)
			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					pass

			@unittest.skip(reason="""MobileNetV1 does not output attentions"""						)
			def UpperCamelCase__					(							self     : Optional[Any]						):





					"""simple docstring"""






					pass

			def UpperCamelCase__					(							self     : str						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		self.model_tester.prepare_config_and_inputs_for_common()

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

							__SCREAMING_SNAKE_CASE       :		List[Any]           =		["""pixel_values"""]
							self.assertListEqual(arg_names[:1]							,     lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : List[str]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		Any           =		self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					def check_hidden_states_output(lowerCAmelCase__     : Dict							,     lowerCAmelCase__     : str							,     lowerCAmelCase__     : Optional[int]						):
							__SCREAMING_SNAKE_CASE       :		str           =		model_class(lowerCAmelCase__						)
							model.to(lowerCAmelCase__						)
							model.eval()

							with torch.no_grad():
									__SCREAMING_SNAKE_CASE       :		Tuple           =		model(**self._prepare_for_class(lowerCAmelCase__							,     lowerCAmelCase__						)						)

							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		outputs.hidden_states

							__SCREAMING_SNAKE_CASE       :		Optional[Any]           =		2_6
							self.assertEqual(len(lowerCAmelCase__						)							,     lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       :		Any           =		self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
							__SCREAMING_SNAKE_CASE       :		Union[str, Any]           =		True
							check_hidden_states_output(lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__						)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							__SCREAMING_SNAKE_CASE       :		Any           =		True

							check_hidden_states_output(lowerCAmelCase__							,     lowerCAmelCase__							,     lowerCAmelCase__						)

			def UpperCamelCase__					(							self     : Dict						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		int           =		self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__						)



			@slow
			def UpperCamelCase__					(							self     : Optional[int]						):





					"""simple docstring"""






					for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__SCREAMING_SNAKE_CASE       :		Any           =		MobileNetVaModel.from_pretrained(lowerCAmelCase__						)
							self.assertIsNotNone(lowerCAmelCase__						)


def 				lowerCAmelCase_   (	):
		__SCREAMING_SNAKE_CASE       :		List[str]           =		Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
		return image






@require_torch
@require_vision
class 						_UpperCamelCase  (							unittest.TestCase    ):


			'''simple docstring'''

			@cached_property
			def UpperCamelCase__					(							self     : Union[str, Any]						):





					"""simple docstring"""






					return (
					    MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""						) if is_vision_available() else None
					)



			@slow
			def UpperCamelCase__					(							self     : List[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE       :		str           =		MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""						).to(lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		Tuple           =		self.default_image_processor
					__SCREAMING_SNAKE_CASE       :		Optional[int]           =		prepare_img()
					__SCREAMING_SNAKE_CASE       :		str           =		image_processor(images=lowerCAmelCase__							,     return_tensors="""pt"""						).to(lowerCAmelCase__						)

					# forward pass
					with torch.no_grad():
							__SCREAMING_SNAKE_CASE       :		Tuple           =		model(**lowerCAmelCase__						)

					# verify the logits
					__SCREAMING_SNAKE_CASE       :		Tuple           =		torch.Size((1, 1_0_0_1)						)
					self.assertEqual(outputs.logits.shape							,     lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE       :		List[Any]           =		torch.tensor([-4.17_39, -1.12_33, 3.12_05]						).to(lowerCAmelCase__						)

					self.assertTrue(torch.allclose(outputs.logits[0, :3]							,     lowerCAmelCase__							,     atol=1E-4						)						)




'''simple docstring'''




def 				lowerCAmelCase_   (	_lowerCamelCase:   int					):
		__SCREAMING_SNAKE_CASE       :		str           =		int(_lowerCamelCase					)
		if n_element < 1:
				__SCREAMING_SNAKE_CASE       :		List[str]           =		ValueError("""a should be a positive number"""					)
				raise my_error

		__SCREAMING_SNAKE_CASE       :		List[Any]           =		[1]
		__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       ,						__SCREAMING_SNAKE_CASE       :		Optional[int]           =		(0, 0, 0)
		__SCREAMING_SNAKE_CASE       :		List[str]           =		1
		while index < n_element:
				while hamming_list[i] * 2 <= hamming_list[-1]:
						i += 1
				while hamming_list[j] * 3 <= hamming_list[-1]:
						j += 1
				while hamming_list[k] * 5 <= hamming_list[-1]:
						k += 1
				hamming_list.append(
				    min(hamming_list[i] * 2       ,      hamming_list[j] * 3       ,      hamming_list[k] * 5					)					)
				index += 1
		return hamming_list


if __name__ == "__main__":
						UpperCamelCase__       :	Optional[Any]    = input('''Enter the last number (nth term) of the Hamming Number Series: ''')
						print('''Formula of Hamming Number Series => 2^i * 3^j * 5^k''')
						UpperCamelCase__       :	List[str]    = hamming(int(n))
						print('''-----------------------------------------------------''')
						print(f"The list with nth numbers is: {hamming_numbers}")
						print('''-----------------------------------------------------''')