





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   _SCREAMING_SNAKE_CASE		(      __SCREAMING_SNAKE_CASE       ):







 '''simple docstring'''

 def 				SCREAMING_SNAKE_CASE_   (self							:  List[str])			->List[str]:



   '''simple docstring'''



   lowerCamelCase__: Dict         =self.config_class(**self.inputs_dict)
   self.parent.assertTrue(hasattr(UpperCAmelCase_			,					"tf_padding"))
   self.parent.assertTrue(hasattr(UpperCAmelCase_			,					"depth_multiplier"))



class   _SCREAMING_SNAKE_CASE		:







 '''simple docstring'''

 def __init__(self							:  Optional[Any]			,					UpperCAmelCase_							:  List[str]			,					UpperCAmelCase_							:  Dict=13			,					UpperCAmelCase_							:  List[str]=3			,					UpperCAmelCase_							:  List[Any]=32			,					UpperCAmelCase_							:  Optional[Any]=0.25			,					UpperCAmelCase_							:  Tuple=8			,					UpperCAmelCase_							:  Optional[int]=True			,					UpperCAmelCase_							:  Tuple=1_024			,					UpperCAmelCase_							:  Optional[int]=32			,					UpperCAmelCase_							:  Union[str, Any]="relu6"			,					UpperCAmelCase_							:  Tuple=0.1			,					UpperCAmelCase_							:  Optional[int]=0.02			,					UpperCAmelCase_							:  Dict=True			,					UpperCAmelCase_							:  List[Any]=True			,					UpperCAmelCase_							:  Any=10			,					UpperCAmelCase_							:  Tuple=None			,					)			->Any:



   '''simple docstring'''



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

 def 				SCREAMING_SNAKE_CASE_   (self							:  Union[str, Any])			->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__: List[Any]         =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__: str         =ids_tensor([self.batch_size]			,					self.num_labels)
     lowerCamelCase__: Dict         =ids_tensor([self.batch_size, self.image_size, self.image_size]			,					self.num_labels)

   lowerCamelCase__: Union[str, Any]         =self.get_config()

   return config, pixel_values, labels, pixel_labels

 def 				SCREAMING_SNAKE_CASE_   (self							:  str)			->Dict:



   '''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 				SCREAMING_SNAKE_CASE_   (self							:  List[Any]			,					UpperCAmelCase_							:  List[str]			,					UpperCAmelCase_							:  Optional[int]			,					UpperCAmelCase_							:  int			,					UpperCAmelCase_							:  int)			->Tuple:



   '''simple docstring'''



   lowerCamelCase__: Optional[int]         =MobileNetVaModel(config=UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__: Optional[int]         =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 				SCREAMING_SNAKE_CASE_   (self							:  List[Any]			,					UpperCAmelCase_							:  int			,					UpperCAmelCase_							:  Optional[int]			,					UpperCAmelCase_							:  Dict			,					UpperCAmelCase_							:  Union[str, Any])			->Optional[int]:



   '''simple docstring'''



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







 def 				SCREAMING_SNAKE_CASE_   (self							:  Dict)			->Tuple:



   '''simple docstring'''



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



@require_torch
class   _SCREAMING_SNAKE_CASE		(      __SCREAMING_SNAKE_CASE       ,				__SCREAMING_SNAKE_CASE       ,				unittest.TestCase       ):







 '''simple docstring'''
 lowercase_						=     (MobileNetVaModel, MobileNetVaForImageClassification) if is_torch_available() else ()
 lowercase_						=     (
     {"feature-extraction": MobileNetVaModel, "image-classification": MobileNetVaForImageClassification}
     if is_torch_available()
     else {}
 )

 lowercase_						=     False
 lowercase_						=     False
 lowercase_						=     False
 lowercase_						=     False

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



   '''simple docstring'''



   lowerCamelCase__: Any         =MobileNetVaModelTester(self)
   lowerCamelCase__: Any         =MobileNetVaConfigTester(self			,					config_class=UpperCAmelCase_			,					has_text_modality=UpperCAmelCase_)

 def 				SCREAMING_SNAKE_CASE_   (self							:  Optional[int])			->Union[str, Any]:



   '''simple docstring'''



   self.config_tester.run_common_tests()

 @unittest.skip(reason="MobileNetV1 does not use inputs_embeds")
 def 				SCREAMING_SNAKE_CASE_   (self							:  Union[str, Any])			->int:



   '''simple docstring'''



   pass

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



   '''simple docstring'''



   pass

 @unittest.skip(reason="MobileNetV1 does not output attentions")
 def 				SCREAMING_SNAKE_CASE_   (self							:  str)			->str:



   '''simple docstring'''



   pass

 def 				SCREAMING_SNAKE_CASE_   (self							:  Tuple)			->int:



   '''simple docstring'''



   lowerCamelCase__    ,   lowerCamelCase__: Optional[int]         =self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowerCamelCase__: Tuple         =model_class(UpperCAmelCase_)
     lowerCamelCase__: int         =inspect.signature(model.forward)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     lowerCamelCase__: Union[str, Any]         =[*signature.parameters.keys()]

     lowerCamelCase__: Union[str, Any]         =["pixel_values"]
     self.assertListEqual(arg_names[:1]			,					UpperCAmelCase_)

 def 				SCREAMING_SNAKE_CASE_   (self							:  Optional[Any])			->List[Any]:



   '''simple docstring'''



   lowerCamelCase__: List[str]         =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*UpperCAmelCase_)

 def 				SCREAMING_SNAKE_CASE_   (self							:  Any)			->Any:



   '''simple docstring'''



   def check_hidden_states_output(UpperCAmelCase_							:  Optional[Any]			,					UpperCAmelCase_							:  Optional[int]			,					UpperCAmelCase_							:  Tuple):
     lowerCamelCase__: int         =model_class(UpperCAmelCase_)
     model.to(UpperCAmelCase_)
     model.eval()

     with torch.no_grad():
       lowerCamelCase__: int         =model(**self._prepare_for_class(UpperCAmelCase_			,					UpperCAmelCase_))

     lowerCamelCase__: Optional[Any]         =outputs.hidden_states

     lowerCamelCase__: List[str]         =26
     self.assertEqual(len(UpperCAmelCase_)			,					UpperCAmelCase_)

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

   for model_class in self.all_model_classes:
     lowerCamelCase__: List[str]         =True
     check_hidden_states_output(UpperCAmelCase_			,					UpperCAmelCase_			,					UpperCAmelCase_)

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

     check_hidden_states_output(UpperCAmelCase_			,					UpperCAmelCase_			,					UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__: Any         =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase_)







 @slow
 def 				SCREAMING_SNAKE_CASE_   (self							:  Any)			->List[Any]:



   '''simple docstring'''



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





def 	lowerCAmelCase_					(			)	->						int:







  """simple docstring"""





  lowerCamelCase__: Tuple         =Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
  return image






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







 '''simple docstring'''

 @cached_property
 def 				SCREAMING_SNAKE_CASE_   (self							:  Union[str, Any])			->Dict:



   '''simple docstring'''



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







 @slow
 def 				SCREAMING_SNAKE_CASE_   (self							:  Optional[Any])			->Any:



   '''simple docstring'''



   lowerCamelCase__: Any         =MobileNetVaForImageClassification.from_pretrained("google/mobilenet_v1_1.0_224").to(UpperCAmelCase_)

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

   # forward pass
   with torch.no_grad():
     lowerCamelCase__: List[str]         =model(**UpperCAmelCase_)

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

   lowerCamelCase__: Tuple         =torch.tensor([-4.1739, -1.1233, 3.1205]).to(UpperCAmelCase_)

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







'''simple docstring'''


from collections import defaultdict
def 						lowerCamelCase__   (				a    ,	a							):
						__snake_case						 =   first_str.lower().strip()
						__snake_case						 =   second_str.lower().strip()

						# Remove whitespace
						__snake_case						 =   first_str.replace(' '    ,	''							)
						__snake_case						 =   second_str.replace(' '    ,	''							)

						# Strings of different lengths are not anagrams
						if len(a							) != len(a							):
												return False

						# Default values for count should be 0
						__snake_case						 =   defaultdict(a							)

						# For each character in input strings,
						# increment count in the corresponding
						for i in range(len(a							)							):
												count[first_str[i]] += 1
												count[second_str[i]] -= 1

						return all(_count == 0 for _count in count.values()							)


if __name__ == "__main__":
	from doctest import testmod

	testmod()
	_lowercase  =			input("""Enter the first string """).strip()
	_lowercase  =			input("""Enter the second string """).strip()

	_lowercase  =			check_anagrams(input_a, input_b)
	print(f'''{input_a} and {input_b} are {'' if status else 'not '}anagrams.''')

