






'''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 _lowercase			(       _lowercase	):




							def 	lowerCamelCase_       (							self:       Optional[int]  ):
														lowerCamelCase__      :			Optional[Any] 						= self.config_class(**self.inputs_dict  )
														self.parent.assertTrue(hasattr(UpperCamelCase__    ,							"""tf_padding"""  )  )
														self.parent.assertTrue(hasattr(UpperCamelCase__    ,							"""depth_multiplier"""  )  )



class _lowercase			:




							def __init__(							self:       Tuple    ,							UpperCamelCase__:       str    ,							UpperCamelCase__:       List[str]=13    ,							UpperCamelCase__:       Optional[Any]=3    ,							UpperCamelCase__:       str=32    ,							UpperCamelCase__:       int=0.25    ,							UpperCamelCase__:       Dict=8    ,							UpperCamelCase__:       List[Any]=True    ,							UpperCamelCase__:       Optional[int]=1_024    ,							UpperCamelCase__:       Tuple=32    ,							UpperCamelCase__:       Union[str, Any]="relu6"    ,							UpperCamelCase__:       List[str]=0.1    ,							UpperCamelCase__:       str=0.02    ,							UpperCamelCase__:       Optional[int]=True    ,							UpperCamelCase__:       int=True    ,							UpperCamelCase__:       Dict=10    ,							UpperCamelCase__:       Dict=None    ,							):
														lowerCamelCase__      :			int 						= parent
														lowerCamelCase__      :			int 						= batch_size
														lowerCamelCase__      :			Optional[Any] 						= num_channels
														lowerCamelCase__      :			Union[str, Any] 						= image_size
														lowerCamelCase__      :			Optional[Any] 						= depth_multiplier
														lowerCamelCase__      :			Tuple 						= min_depth
														lowerCamelCase__      :			int 						= tf_padding
														lowerCamelCase__      :			Union[str, Any] 						= int(last_hidden_size * depth_multiplier  )
														lowerCamelCase__      :			Any 						= output_stride
														lowerCamelCase__      :			Optional[int] 						= hidden_act
														lowerCamelCase__      :			str 						= classifier_dropout_prob
														lowerCamelCase__      :			List[str] 						= use_labels
														lowerCamelCase__      :			List[str] 						= is_training
														lowerCamelCase__      :			List[Any] 						= num_labels
														lowerCamelCase__      :			Dict 						= initializer_range
														lowerCamelCase__      :			Any 						= scope




							def 	lowerCamelCase_       (							self:       List[str]  ):
														lowerCamelCase__      :			List[str] 						= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )

														lowerCamelCase__      :			Tuple 						= None
														lowerCamelCase__      :			Tuple 						= None
														if self.use_labels:
																					lowerCamelCase__      :			List[str] 						= ids_tensor([self.batch_size]    ,							self.num_labels  )
																					lowerCamelCase__      :			List[str] 						= ids_tensor([self.batch_size, self.image_size, self.image_size]    ,							self.num_labels  )

														lowerCamelCase__      :			List[str] 						= self.get_config()

														return config, pixel_values, labels, pixel_labels




							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														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 	lowerCamelCase_       (							self:       int    ,							UpperCamelCase__:       Tuple    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       int    ,							UpperCamelCase__:       Union[str, Any]  ):
														lowerCamelCase__      :			Optional[int] 						= MobileNetVaModel(config=UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Union[str, Any] 						= model(UpperCamelCase__  )
														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 	lowerCamelCase_       (							self:       List[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       List[Any]    ,							UpperCamelCase__:       Union[str, Any]    ,							UpperCamelCase__:       Optional[Any]  ):
														lowerCamelCase__      :			Any 						= self.num_labels
														lowerCamelCase__      :			List[Any] 						= MobileNetVaForImageClassification(UpperCamelCase__  )
														model.to(UpperCamelCase__  )
														model.eval()
														lowerCamelCase__      :			Any 						= model(UpperCamelCase__    ,							labels=UpperCamelCase__  )
														self.parent.assertEqual(result.logits.shape    ,							(self.batch_size, self.num_labels)  )




							def 	lowerCamelCase_       (							self:       Tuple  ):
														lowerCamelCase__      :			Optional[int] 						= self.prepare_config_and_inputs()
														lowerCamelCase__						,	lowerCamelCase__						,	lowerCamelCase__						,	lowerCamelCase__      :			Optional[int] 						= config_and_inputs
														lowerCamelCase__      :			Union[str, Any] 						= {"""pixel_values""": pixel_values}
														return config, inputs_dict



@require_torch
class _lowercase			(       _lowercase       ,   _lowercase       ,   unittest.TestCase	):
							a          = (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
							a          = (
							    {"""feature-extraction""": MobileNetVaModel, """image-classification""": MobileNetVaForImageClassification}
							    if is_torch_available()
							    else {}
							)

							a          = False
							a          = False
							a          = False
							a          = False




							def 	lowerCamelCase_       (							self:       List[Any]  ):
														lowerCamelCase__      :			Any 						= MobileNetVaModelTester(self  )
														lowerCamelCase__      :			Union[str, Any] 						= MobileNetVaConfigTester(self    ,							config_class=UpperCamelCase__    ,							has_text_modality=UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       List[str]  ):
														self.config_tester.run_common_tests()




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




							@unittest.skip(reason="""MobileNetV1 does not support input and output embeddings"""  )
							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														pass




							@unittest.skip(reason="""MobileNetV1 does not output attentions"""  )
							def 	lowerCamelCase_       (							self:       Tuple  ):
														pass




							def 	lowerCamelCase_       (							self:       Any  ):
														lowerCamelCase__						,	lowerCamelCase__      :			Optional[Any] 						= self.model_tester.prepare_config_and_inputs_for_common()

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

																					lowerCamelCase__      :			Optional[Any] 						= ["""pixel_values"""]
																					self.assertListEqual(arg_names[:1]    ,							UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														lowerCamelCase__      :			Any 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       str  ):
														def check_hidden_states_output(UpperCamelCase__:       str    ,							UpperCamelCase__:       Optional[int]    ,							UpperCamelCase__:       Optional[Any]  ):
																					lowerCamelCase__      :			Dict 						= model_class(UpperCamelCase__  )
																					model.to(UpperCamelCase__  )
																					model.eval()

																					with torch.no_grad():
																												lowerCamelCase__      :			List[Any] 						= model(**self._prepare_for_class(UpperCamelCase__    ,							UpperCamelCase__  )  )

																					lowerCamelCase__      :			Any 						= outputs.hidden_states

																					lowerCamelCase__      :			Dict 						= 26
																					self.assertEqual(len(UpperCamelCase__  )    ,							UpperCamelCase__  )

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

														for model_class in self.all_model_classes:
																					lowerCamelCase__      :			Any 						= True
																					check_hidden_states_output(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__  )

																					# check that output_hidden_states also work using config
																					del inputs_dict["output_hidden_states"]
																					lowerCamelCase__      :			List[str] 						= True

																					check_hidden_states_output(UpperCamelCase__    ,							UpperCamelCase__    ,							UpperCamelCase__  )




							def 	lowerCamelCase_       (							self:       Any  ):
														lowerCamelCase__      :			int 						= self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__  )




							@slow
							def 	lowerCamelCase_       (							self:       Union[str, Any]  ):
														for model_name in MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					lowerCamelCase__      :			Optional[Any] 						= MobileNetVaModel.from_pretrained(UpperCamelCase__  )
																					self.assertIsNotNone(UpperCamelCase__  )





def 				SCREAMING_SNAKE_CASE_ ()   -> Optional[Any]:
							lowerCamelCase__      :			Tuple 						= Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""   )
							return image



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




							@cached_property
							def 	lowerCamelCase_       (							self:       Optional[Any]  ):
														return (
														    MobileNetVaImageProcessor.from_pretrained("""google/mobilenet_v1_1.0_224"""  ) if is_vision_available() else None
														)




							@slow
							def 	lowerCamelCase_       (							self:       str  ):
														lowerCamelCase__      :			List[str] 						= MobileNetVaForImageClassification.from_pretrained("""google/mobilenet_v1_1.0_224"""  ).to(UpperCamelCase__  )

														lowerCamelCase__      :			Union[str, Any] 						= self.default_image_processor
														lowerCamelCase__      :			List[Any] 						= prepare_img()
														lowerCamelCase__      :			Optional[Any] 						= image_processor(images=UpperCamelCase__    ,							return_tensors="""pt"""  ).to(UpperCamelCase__  )

														# forward pass
														with torch.no_grad():
																					lowerCamelCase__      :			Optional[int] 						= model(**UpperCamelCase__  )

														# verify the logits
														lowerCamelCase__      :			Tuple 						= torch.Size((1, 1_001)  )
														self.assertEqual(outputs.logits.shape    ,							UpperCamelCase__  )

														lowerCamelCase__      :			Tuple 						= torch.tensor([-4.1_739, -1.1_233, 3.1_205]  ).to(UpperCamelCase__  )

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









'''simple docstring'''







import sys
import turtle





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase   )   -> tuple[float, float]:
							return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase       ,    UpperCamelCase       ,    )   -> None:
							my_pen.up()
							my_pen.goto(vertexa[0]       ,    vertexa[1]   )
							my_pen.down()
							my_pen.goto(vertexa[0]       ,    vertexa[1]   )
							my_pen.goto(vertexa[0]       ,    vertexa[1]   )
							my_pen.goto(vertexa[0]       ,    vertexa[1]   )

							if depth == 0:
														return

							triangle(UpperCamelCase       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    depth - 1   )
							triangle(UpperCamelCase       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    depth - 1   )
							triangle(UpperCamelCase       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    get_mid(UpperCamelCase       ,    UpperCamelCase   )       ,    depth - 1   )


if __name__ == "__main__":
			if len(sys.argv) != 2:
						raise ValueError(
						    '''Correct format for using this script: '''
						    '''python fractals.py <int:depth_for_fractal>'''
						)
			_A			:    Any					  =turtle.Turtle()
			my_pen.ht()
			my_pen.speed(5)
			my_pen.pencolor('''red''')

			_A			:    Dict					  =[(-175, -125), (0, 175), (175, -125)]  # vertices of triangle
			triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))

