



"""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, prepare_image_inputs


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import MobileNetVaImageProcessor



class  _lowerCAmelCase     (					unittest.TestCase		):





		"""simple docstring"""






		def __init__(       self				,     _lowercase				,     _lowercase=7				,     _lowercase=3				,     _lowercase=1_8				,     _lowercase=3_0				,     _lowercase=4_0_0				,     _lowercase=True				,     _lowercase=None				,     _lowercase=True				,     _lowercase=None				,     )			->    Union[str, Any]:







								'''simple docstring'''

								snake_case_ :			Optional[int]            =      size if size is not None else {"""shortest_edge""": 2_0}
								snake_case_ :			Optional[int]            =      crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
								snake_case_ :			Optional[Any]            =      parent
								snake_case_ :			Union[str, Any]            =      batch_size
								snake_case_ :			Any            =      num_channels
								snake_case_ :			List[Any]            =      image_size
								snake_case_ :			Dict            =      min_resolution
								snake_case_ :			int            =      max_resolution
								snake_case_ :			List[Any]            =      do_resize
								snake_case_ :			Dict            =      size
								snake_case_ :			Optional[Any]            =      do_center_crop
								snake_case_ :			List[str]            =      crop_size





		def  UpperCAmelCase__				(       self )			->    Any:







								'''simple docstring'''

								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_center_crop": self.do_center_crop,
								    "crop_size": self.crop_size,
								}




@require_torch
@require_vision
class  _lowerCAmelCase     (					SCREAMING_SNAKE_CASE__	,					unittest.TestCase		):





		"""simple docstring"""






		_lowerCamelCase      	=							MobileNetVaImageProcessor if is_vision_available() else None





		def  UpperCAmelCase__				(       self )			->    Dict:







								'''simple docstring'''

								snake_case_ :			str            =      MobileNetVaImageProcessingTester(self )





		@property
		def  UpperCAmelCase__				(       self )			->    List[Any]:







								'''simple docstring'''

								return self.image_processor_tester.prepare_image_processor_dict()





		def  UpperCAmelCase__				(       self )			->    str:







								'''simple docstring'''

								snake_case_ :			List[Any]            =      self.image_processing_class(**self.image_processor_dict )
								self.assertTrue(hasattr(_lowercase				,     """do_resize""" ) )
								self.assertTrue(hasattr(_lowercase				,     """size""" ) )
								self.assertTrue(hasattr(_lowercase				,     """do_center_crop""" ) )
								self.assertTrue(hasattr(_lowercase				,     """crop_size""" ) )





		def  UpperCAmelCase__				(       self )			->    Any:







								'''simple docstring'''

								snake_case_ :			str            =      self.image_processing_class.from_dict(self.image_processor_dict )
								self.assertEqual(image_processor.size				,     {"""shortest_edge""": 2_0} )
								self.assertEqual(image_processor.crop_size				,     {"""height""": 1_8, """width""": 1_8} )

								snake_case_ :			Tuple            =      self.image_processing_class.from_dict(self.image_processor_dict				,     size=4_2				,     crop_size=8_4 )
								self.assertEqual(image_processor.size				,     {"""shortest_edge""": 4_2} )
								self.assertEqual(image_processor.crop_size				,     {"""height""": 8_4, """width""": 8_4} )





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







								'''simple docstring'''

								pass





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







								'''simple docstring'''

								snake_case_ :			Dict            =      self.image_processing_class(**self.image_processor_dict )
								# create random PIL images
								snake_case_ :			Union[str, Any]            =      prepare_image_inputs(self.image_processor_tester				,     equal_resolution=_lowercase )
								for image in image_inputs:
														self.assertIsInstance(_lowercase				,     Image.Image )

								# Test not batched input
								snake_case_ :			Optional[int]            =      image_processing(image_inputs[0]				,     return_tensors="""pt""" ).pixel_values
								self.assertEqual(
								    encoded_images.shape				,     (
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    )				,     )

								# Test batched
								snake_case_ :			int            =      image_processing(_lowercase				,     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.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    )				,     )





		def  UpperCAmelCase__				(       self )			->    Optional[int]:







								'''simple docstring'''

								snake_case_ :			Tuple            =      self.image_processing_class(**self.image_processor_dict )
								# create random numpy tensors
								snake_case_ :			Optional[Any]            =      prepare_image_inputs(self.image_processor_tester				,     equal_resolution=_lowercase				,     numpify=_lowercase )
								for image in image_inputs:
														self.assertIsInstance(_lowercase				,     np.ndarray )

								# Test not batched input
								snake_case_ :			int            =      image_processing(image_inputs[0]				,     return_tensors="""pt""" ).pixel_values
								self.assertEqual(
								    encoded_images.shape				,     (
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    )				,     )

								# Test batched
								snake_case_ :			List[Any]            =      image_processing(_lowercase				,     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.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    )				,     )





		def  UpperCAmelCase__				(       self )			->    Tuple:







								'''simple docstring'''

								snake_case_ :			Dict            =      self.image_processing_class(**self.image_processor_dict )
								# create random PyTorch tensors
								snake_case_ :			Optional[int]            =      prepare_image_inputs(self.image_processor_tester				,     equal_resolution=_lowercase				,     torchify=_lowercase )
								for image in image_inputs:
														self.assertIsInstance(_lowercase				,     torch.Tensor )

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

								# Test batched
								snake_case_ :			List[str]            =      image_processing(_lowercase				,     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.crop_size["""height"""],
								        self.image_processor_tester.crop_size["""width"""],
								    )				,     )









"""simple docstring"""
import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_mobilebert import MobileBertTokenizer


snake_case : Optional[Any]     		=		logging.get_logger(__name__)

snake_case : str     		=		{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

snake_case : List[Any]     		=		{
    """vocab_file""": {"""mobilebert-uncased""": """https://huggingface.co/google/mobilebert-uncased/resolve/main/vocab.txt"""},
    """tokenizer_file""": {
        """mobilebert-uncased""": """https://huggingface.co/google/mobilebert-uncased/resolve/main/tokenizer.json"""
    },
}

snake_case : Tuple     		=		{"""mobilebert-uncased""": 5_1_2}


snake_case : List[str]     		=		{}



class        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = VOCAB_FILES_NAMES
    __UpperCAmelCase           = PRETRAINED_VOCAB_FILES_MAP
    __UpperCAmelCase           = PRETRAINED_INIT_CONFIGURATION
    __UpperCAmelCase           = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __UpperCAmelCase           = MobileBertTokenizer







    def __init__(		self :	Optional[int]				,    UpperCamelCase_ :	Optional[int]=None				,    UpperCamelCase_ :	str=None				,    UpperCamelCase_ :	Tuple=True				,    UpperCamelCase_ :	Any="[UNK]"				,    UpperCamelCase_ :	str="[SEP]"				,    UpperCamelCase_ :	Any="[PAD]"				,    UpperCamelCase_ :	Dict="[CLS]"				,    UpperCamelCase_ :	str="[MASK]"				,    UpperCamelCase_ :	Union[str, Any]=True				,    UpperCamelCase_ :	Dict=None				,    **UpperCamelCase_ :	Dict				,    ):





           '''simple docstring'''

           super().__init__(
               UpperCamelCase_				,    tokenizer_file=UpperCamelCase_				,    do_lower_case=UpperCamelCase_				,    unk_token=UpperCamelCase_				,    sep_token=UpperCamelCase_				,    pad_token=UpperCamelCase_				,    cls_token=UpperCamelCase_				,    mask_token=UpperCamelCase_				,    tokenize_chinese_chars=UpperCamelCase_				,    strip_accents=UpperCamelCase_				,    **UpperCamelCase_				,    )

           __magic_name__      				=    json.loads(self.backend_tokenizer.normalizer.__getstate__() )
           if (
               normalizer_state.get('lowercase'				,    UpperCamelCase_ ) != do_lower_case
               or normalizer_state.get('strip_accents'				,    UpperCamelCase_ ) != strip_accents
               or normalizer_state.get('handle_chinese_chars'				,    UpperCamelCase_ ) != tokenize_chinese_chars
           ):
                  __magic_name__      				=    getattr(UpperCamelCase_				,    normalizer_state.pop('type' ) )
                  __magic_name__      				=    do_lower_case
                  __magic_name__      				=    strip_accents
                  __magic_name__      				=    tokenize_chinese_chars
                  __magic_name__      				=    normalizer_class(**UpperCamelCase_ )

           __magic_name__      				=    do_lower_case







    def 				a__			(		self :	Dict				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	List[Any]=None ):





           '''simple docstring'''

           __magic_name__      				=    [self.cls_token_id] + token_ids_a + [self.sep_token_id]

           if token_ids_a:
                  output += token_ids_a + [self.sep_token_id]

           return output







    def 				a__			(		self :	List[Any]				,    UpperCamelCase_ :	List[int]				,    UpperCamelCase_ :	Optional[List[int]] = None ):





           '''simple docstring'''

           __magic_name__      				=    [self.sep_token_id]
           __magic_name__      				=    [self.cls_token_id]
           if token_ids_a is None:
                  return len(cls + token_ids_a + sep ) * [0]
           return len(cls + token_ids_a + sep ) * [0] + len(token_ids_a + sep ) * [1]







    def 				a__			(		self :	List[str]				,    UpperCamelCase_ :	str				,    UpperCamelCase_ :	Optional[str] = None ):





           '''simple docstring'''

           __magic_name__      				=    self._tokenizer.model.save(UpperCamelCase_				,    name=UpperCamelCase_ )
           return tuple(UpperCamelCase_ )