


import json
import os
import re
import unicodedata
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
from ...utils import logging


_A		:					int          =							logging.get_logger(__name__)

_A		:					Any          =							{
    '''vocab_file''': '''vocab.json''',
    '''merges_file''': '''merges.txt''',
}

_A		:					int          =							{
    '''vocab_file''': {'''openai-gpt''': '''https://huggingface.co/openai-gpt/resolve/main/vocab.json'''},
    '''merges_file''': {'''openai-gpt''': '''https://huggingface.co/openai-gpt/resolve/main/merges.txt'''},
}

_A		:					Any          =							{
    '''openai-gpt''': 512,
}



def      __lowerCAmelCase    (				snake_case						:     Tuple			)							->				Tuple:
   __lowerCamelCase:					Any	 =						text.strip()
   if not text:
      return []
   __lowerCamelCase:					Union[str, Any]	 =						text.split()
   return tokens



class 							a       (      _UpperCAmelCase ):





     def __init__(     self       :					Optional[Any]     ,						SCREAMING_SNAKE_CASE_       :					int=True     ,						SCREAMING_SNAKE_CASE_       :					Any=None     ,						SCREAMING_SNAKE_CASE_       :					str=True     ,						SCREAMING_SNAKE_CASE_       :					List[Any]=None     ,						SCREAMING_SNAKE_CASE_       :					Any=True     ,						):
        if never_split is None:
           __lowerCamelCase:					Optional[Any]	 =						[]
        __lowerCamelCase:					Tuple	 =						do_lower_case
        __lowerCamelCase:					List[str]	 =						set(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					List[Any]	 =						tokenize_chinese_chars
        __lowerCamelCase:					Tuple	 =						strip_accents
        __lowerCamelCase:					str	 =						do_split_on_punc





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]     ,						SCREAMING_SNAKE_CASE_       :					str     ,						SCREAMING_SNAKE_CASE_       :					Optional[int]=None				):
        __lowerCamelCase:					int	 =						self.never_split.union(set(SCREAMING_SNAKE_CASE_				)				) if never_split else self.never_split
        __lowerCamelCase:					int	 =						self._clean_text(SCREAMING_SNAKE_CASE_				)

        # This was added on November 1st, 2018 for the multilingual and Chinese
        # models. This is also applied to the English models now, but it doesn't
        # matter since the English models were not trained on any Chinese data
        # and generally don't have any Chinese data in them (there are Chinese
        # characters in the vocabulary because Wikipedia does have some Chinese
        # words in the English Wikipedia.).
        if self.tokenize_chinese_chars:
           __lowerCamelCase:					Any	 =						self._tokenize_chinese_chars(SCREAMING_SNAKE_CASE_				)
        # prevents treating the same character with different unicode codepoints as different characters
        __lowerCamelCase:					Optional[Any]	 =						unicodedata.normalize("""NFC"""     ,						SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					Optional[int]	 =						whitespace_tokenize(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					List[str]	 =						[]
        for token in orig_tokens:
           if token not in never_split:
              if self.do_lower_case:
                 __lowerCamelCase:					Tuple	 =						token.lower()
                 if self.strip_accents is not False:
                    __lowerCamelCase:					str	 =						self._run_strip_accents(SCREAMING_SNAKE_CASE_				)
              elif self.strip_accents:
                 __lowerCamelCase:					Optional[int]	 =						self._run_strip_accents(SCREAMING_SNAKE_CASE_				)
           split_tokens.extend(self._run_split_on_punc(SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_				)				)

        __lowerCamelCase:					Union[str, Any]	 =						whitespace_tokenize(""" """.join(SCREAMING_SNAKE_CASE_				)				)
        return output_tokens





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any     ,						SCREAMING_SNAKE_CASE_       :					Tuple				):
        __lowerCamelCase:					int	 =						unicodedata.normalize("""NFD"""     ,						SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					Any	 =						[]
        for char in text:
           __lowerCamelCase:					List[Any]	 =						unicodedata.category(SCREAMING_SNAKE_CASE_				)
           if cat == "Mn":
              continue
           output.append(SCREAMING_SNAKE_CASE_				)
        return "".join(SCREAMING_SNAKE_CASE_				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Union[str, Any]     ,						SCREAMING_SNAKE_CASE_       :					Union[str, Any]     ,						SCREAMING_SNAKE_CASE_       :					Optional[int]=None				):
        if not self.do_split_on_punc or (never_split is not None and text in never_split):
           return [text]
        __lowerCamelCase:					List[str]	 =						list(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					Dict	 =						0
        __lowerCamelCase:					Any	 =						True
        __lowerCamelCase:					List[str]	 =						[]
        while i < len(SCREAMING_SNAKE_CASE_				):
           __lowerCamelCase:					Optional[int]	 =						chars[i]
           if _is_punctuation(SCREAMING_SNAKE_CASE_				):
              output.append([char]				)
              __lowerCamelCase:					Tuple	 =						True
           else:
              if start_new_word:
                 output.append([]				)
              __lowerCamelCase:					Any	 =						False
              output[-1].append(SCREAMING_SNAKE_CASE_				)
           i += 1

        return ["".join(SCREAMING_SNAKE_CASE_				) for x in output]





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Union[str, Any]     ,						SCREAMING_SNAKE_CASE_       :					Any				):
        __lowerCamelCase:					Tuple	 =						[]
        for char in text:
           __lowerCamelCase:					int	 =						ord(SCREAMING_SNAKE_CASE_				)
           if self._is_chinese_char(SCREAMING_SNAKE_CASE_				):
              output.append(""" """				)
              output.append(SCREAMING_SNAKE_CASE_				)
              output.append(""" """				)
           else:
              output.append(SCREAMING_SNAKE_CASE_				)
        return "".join(SCREAMING_SNAKE_CASE_				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					int     ,						SCREAMING_SNAKE_CASE_       :					Tuple				):
        # This defines a "chinese character" as anything in the CJK Unicode block:
        #   https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block)
        #
        # Note that the CJK Unicode block is NOT all Japanese and Korean characters,
        # despite its name. The modern Korean Hangul alphabet is a different block,
        # as is Japanese Hiragana and Katakana. Those alphabets are used to write
        # space-separated words, so they are not treated specially and handled
        # like the all of the other languages.
        if (
            (cp >= 0x4_E_0_0 and cp <= 0x9_F_F_F)
            or (cp >= 0x3_4_0_0 and cp <= 0x4_D_B_F)  #
            or (cp >= 0x2_0_0_0_0 and cp <= 0x2_A_6_D_F)  #
            or (cp >= 0x2_A_7_0_0 and cp <= 0x2_B_7_3_F)  #
            or (cp >= 0x2_B_7_4_0 and cp <= 0x2_B_8_1_F)  #
            or (cp >= 0x2_B_8_2_0 and cp <= 0x2_C_E_A_F)  #
            or (cp >= 0xF_9_0_0 and cp <= 0xF_A_F_F)
            or (cp >= 0x2_F_8_0_0 and cp <= 0x2_F_A_1_F)  #
        ):  #
           return True

        return False







     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					int				):
        __lowerCamelCase:					int	 =						[]
        for char in text:
           __lowerCamelCase:					int	 =						ord(SCREAMING_SNAKE_CASE_				)
           if cp == 0 or cp == 0xF_F_F_D or _is_control(SCREAMING_SNAKE_CASE_				):
              continue
           if _is_whitespace(SCREAMING_SNAKE_CASE_				):
              output.append(""" """				)
           else:
              output.append(SCREAMING_SNAKE_CASE_				)
        return "".join(SCREAMING_SNAKE_CASE_				)



def      __lowerCAmelCase    (				snake_case						:     Tuple			)							->				List[str]:
   __lowerCamelCase:					Optional[Any]	 =						set()
   __lowerCamelCase:					Any	 =						word[0]
   for char in word[1:]:
      pairs.add((prev_char, char)			)
      __lowerCamelCase:					Optional[int]	 =						char
   return pairs



def      __lowerCAmelCase    (				snake_case						:     Dict			)							->				List[str]:
   __lowerCamelCase:					List[str]	 =						text.replace("""—"""    ,   """-"""			)
   __lowerCamelCase:					int	 =						text.replace("""–"""    ,   """-"""			)
   __lowerCamelCase:					Tuple	 =						text.replace("""―"""    ,   """-"""			)
   __lowerCamelCase:					Any	 =						text.replace("""…"""    ,   """..."""			)
   __lowerCamelCase:					Any	 =						text.replace("""´"""    ,   """'"""			)
   __lowerCamelCase:					Union[str, Any]	 =						re.sub(r"""(-+|~+|!+|\"+|;+|\?+|\++|,+|\)+|\(+|\\+|\/+|\*+|\[+|\]+|}+|{+|\|+|_+)"""    ,   r""" \1 """    ,   snake_case			)
   __lowerCamelCase:					Optional[int]	 =						re.sub(r"""\s*\n\s*"""    ,   """ \n """    ,   snake_case			)
   __lowerCamelCase:					Optional[Any]	 =						re.sub(r"""[^\S\n]+"""    ,   """ """    ,   snake_case			)
   return text.strip()







class 							a       (      _UpperCAmelCase ):
     UpperCAmelCase__			:	Optional[Any]       =						VOCAB_FILES_NAMES
     UpperCAmelCase__			:	Optional[int]       =						PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__			:	Optional[Any]       =						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__			:	List[Any]       =						["input_ids", "attention_mask"]





     def __init__(     self       :					List[str]     ,						SCREAMING_SNAKE_CASE_       :					str     ,						SCREAMING_SNAKE_CASE_       :					int     ,						SCREAMING_SNAKE_CASE_       :					Optional[Any]="<unk>"     ,						**SCREAMING_SNAKE_CASE_       :					List[Any]				):
        super().__init__(unk_token=SCREAMING_SNAKE_CASE_     ,						**SCREAMING_SNAKE_CASE_				)

        try:
           import ftfy
           from spacy.lang.en import English

           __lowerCamelCase:					Optional[Any]	 =						English()
           __lowerCamelCase:					List[str]	 =						_nlp.tokenizer
           __lowerCamelCase:					Tuple	 =						ftfy.fix_text
        except ImportError:
           logger.warning("""ftfy or spacy is not installed using BERT BasicTokenizer instead of SpaCy & ftfy."""				)
           __lowerCamelCase:					Dict	 =						BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE_				)
           __lowerCamelCase:					List[str]	 =						None

        with open(SCREAMING_SNAKE_CASE_     ,						encoding="""utf-8"""				) as vocab_handle:
           __lowerCamelCase:					List[Any]	 =						json.load(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					Tuple	 =						{v: k for k, v in self.encoder.items()}
        with open(SCREAMING_SNAKE_CASE_     ,						encoding="""utf-8"""				) as merges_handle:
           __lowerCamelCase:					Dict	 =						merges_handle.read().split("""\n"""				)[1:-1]
        __lowerCamelCase:					List[str]	 =						[tuple(merge.split()				) for merge in merges]
        __lowerCamelCase:					Union[str, Any]	 =						dict(zip(SCREAMING_SNAKE_CASE_     ,						range(len(SCREAMING_SNAKE_CASE_				)				)				)				)
        __lowerCamelCase:					Optional[int]	 =						{}





     @property
     def 			SCREAMING_SNAKE_CASE__							(     self       :					int				):
        return True





     @property
     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any				):
        return len(self.encoder				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Dict				):
        return dict(self.encoder     ,						**self.added_tokens_encoder				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					str     ,						SCREAMING_SNAKE_CASE_       :					int				):
        __lowerCamelCase:					Union[str, Any]	 =						tuple(token[:-1]				) + (token[-1] + """</w>""",)
        if token in self.cache:
           return self.cache[token]
        __lowerCamelCase:					Any	 =						get_pairs(SCREAMING_SNAKE_CASE_				)

        if not pairs:
           return token + "</w>"

        while True:
           __lowerCamelCase:					List[str]	 =						min(SCREAMING_SNAKE_CASE_     ,						key=lambda SCREAMING_SNAKE_CASE_				: self.bpe_ranks.get(SCREAMING_SNAKE_CASE_     ,						float("""inf"""				)				)				)
           if bigram not in self.bpe_ranks:
              break
           __lowerCamelCase ,  __lowerCamelCase:					str	 =						bigram
           __lowerCamelCase:					Optional[Any]	 =						[]
           __lowerCamelCase:					Union[str, Any]	 =						0
           while i < len(SCREAMING_SNAKE_CASE_				):
              try:
                 __lowerCamelCase:					Tuple	 =						word.index(SCREAMING_SNAKE_CASE_     ,						SCREAMING_SNAKE_CASE_				)
              except ValueError:
                 new_word.extend(word[i:]				)
                 break
              else:
                 new_word.extend(word[i:j]				)
                 __lowerCamelCase:					Dict	 =						j

              if word[i] == first and i < len(SCREAMING_SNAKE_CASE_				) - 1 and word[i + 1] == second:
                 new_word.append(first + second				)
                 i += 2
              else:
                 new_word.append(word[i]				)
                 i += 1
           __lowerCamelCase:					List[Any]	 =						tuple(SCREAMING_SNAKE_CASE_				)
           __lowerCamelCase:					str	 =						new_word
           if len(SCREAMING_SNAKE_CASE_				) == 1:
              break
           else:
              __lowerCamelCase:					int	 =						get_pairs(SCREAMING_SNAKE_CASE_				)
        __lowerCamelCase:					Any	 =						""" """.join(SCREAMING_SNAKE_CASE_				)
        if word == "\n  </w>":
           __lowerCamelCase:					Dict	 =						"""\n</w>"""
        __lowerCamelCase:					Optional[int]	 =						word
        return word





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Union[str, Any]     ,						SCREAMING_SNAKE_CASE_       :					Optional[Any]				):
        __lowerCamelCase:					Any	 =						[]
        if self.fix_text is None:
           # Using BERT's BasicTokenizer
           __lowerCamelCase:					Dict	 =						self.nlp.tokenize(SCREAMING_SNAKE_CASE_				)
           for token in text:
              split_tokens.extend(list(self.bpe(SCREAMING_SNAKE_CASE_				).split(""" """				)				)				)
        else:
           # Using SpaCy & ftfy (original tokenization process of OpenAI GPT)
           __lowerCamelCase:					Optional[int]	 =						self.nlp(text_standardize(self.fix_text(SCREAMING_SNAKE_CASE_				)				)				)
           for token in text:
              split_tokens.extend(list(self.bpe(token.text.lower()				).split(""" """				)				)				)
        return split_tokens





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[Any]     ,						SCREAMING_SNAKE_CASE_       :					Optional[Any]				):
        return self.encoder.get(SCREAMING_SNAKE_CASE_     ,						self.encoder.get(self.unk_token				)				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[Any]     ,						SCREAMING_SNAKE_CASE_       :					Optional[Any]				):
        return self.decoder.get(SCREAMING_SNAKE_CASE_     ,						self.unk_token				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]     ,						SCREAMING_SNAKE_CASE_       :					str				):
        __lowerCamelCase:					int	 =						"""""".join(SCREAMING_SNAKE_CASE_				).replace("""</w>"""     ,						""" """				).strip()
        return out_string







     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any     ,						SCREAMING_SNAKE_CASE_       :					str     ,						SCREAMING_SNAKE_CASE_       :					Optional[str] = None				):
        if not os.path.isdir(SCREAMING_SNAKE_CASE_				):
           logger.error(F'Vocabulary path ({save_directory}) should be a directory'				)
           return
        __lowerCamelCase:					Dict	 =						os.path.join(
            SCREAMING_SNAKE_CASE_     ,						(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]				)
        __lowerCamelCase:					int	 =						os.path.join(
            SCREAMING_SNAKE_CASE_     ,						(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]				)

        with open(SCREAMING_SNAKE_CASE_     ,						"""w"""     ,						encoding="""utf-8"""				) as f:
           f.write(json.dumps(self.encoder     ,						indent=2     ,						sort_keys=SCREAMING_SNAKE_CASE_     ,						ensure_ascii=SCREAMING_SNAKE_CASE_				) + """\n"""				)

        __lowerCamelCase:					List[str]	 =						0
        with open(SCREAMING_SNAKE_CASE_     ,						"""w"""     ,						encoding="""utf-8"""				) as writer:
           writer.write("""#version: 0.2\n"""				)
           for bpe_tokens, token_index in sorted(self.bpe_ranks.items()     ,						key=lambda SCREAMING_SNAKE_CASE_				: kv[1]				):
              if index != token_index:
                 logger.warning(
                     F'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
                     """ Please check that the tokenizer is not corrupted!"""				)
                 __lowerCamelCase:					Union[str, Any]	 =						token_index
              writer.write(""" """.join(SCREAMING_SNAKE_CASE_				) + """\n"""				)
              index += 1

        return vocab_file, merge_file






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 							a       (      unittest.TestCase ):





     def __init__(     self       :					Optional[int]     ,						SCREAMING_SNAKE_CASE_       :					str     ,						SCREAMING_SNAKE_CASE_       :					List[str]=7     ,						SCREAMING_SNAKE_CASE_       :					Union[str, Any]=3     ,						SCREAMING_SNAKE_CASE_       :					List[Any]=18     ,						SCREAMING_SNAKE_CASE_       :					List[str]=30     ,						SCREAMING_SNAKE_CASE_       :					List[Any]=400     ,						SCREAMING_SNAKE_CASE_       :					Dict=True     ,						SCREAMING_SNAKE_CASE_       :					Any=None     ,						SCREAMING_SNAKE_CASE_       :					List[str]=True     ,						SCREAMING_SNAKE_CASE_       :					Any=None     ,						):
        __lowerCamelCase:					List[Any]	 =						size if size is not None else {"""shortest_edge""": 20}
        __lowerCamelCase:					Tuple	 =						crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
        __lowerCamelCase:					List[Any]	 =						parent
        __lowerCamelCase:					Optional[int]	 =						batch_size
        __lowerCamelCase:					str	 =						num_channels
        __lowerCamelCase:					Dict	 =						image_size
        __lowerCamelCase:					Tuple	 =						min_resolution
        __lowerCamelCase:					Union[str, Any]	 =						max_resolution
        __lowerCamelCase:					Tuple	 =						do_resize
        __lowerCamelCase:					List[str]	 =						size
        __lowerCamelCase:					int	 =						do_center_crop
        __lowerCamelCase:					Tuple	 =						crop_size







     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[Any]				):
        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 							a       (      _UpperCAmelCase  ,unittest.TestCase ):
     UpperCAmelCase__			:	int       =						MobileNetVaImageProcessor if is_vision_available() else None





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]				):
        __lowerCamelCase:					Tuple	 =						MobileNetVaImageProcessingTester(self				)





     @property
     def 			SCREAMING_SNAKE_CASE__							(     self       :					str				):
        return self.image_processor_tester.prepare_image_processor_dict()





     def 			SCREAMING_SNAKE_CASE__							(     self       :					List[str]				):
        __lowerCamelCase:					List[Any]	 =						self.image_processing_class(**self.image_processor_dict				)
        self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_     ,						"""do_resize"""				)				)
        self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_     ,						"""size"""				)				)
        self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_     ,						"""do_center_crop"""				)				)
        self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_     ,						"""center_crop"""				)				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Any				):
        __lowerCamelCase:					str	 =						self.image_processing_class.from_dict(self.image_processor_dict				)
        self.assertEqual(image_processor.size     ,						{"""shortest_edge""": 20}				)
        self.assertEqual(image_processor.crop_size     ,						{"""height""": 18, """width""": 18}				)

        __lowerCamelCase:					Optional[int]	 =						self.image_processing_class.from_dict(self.image_processor_dict     ,						size=42     ,						crop_size=84				)
        self.assertEqual(image_processor.size     ,						{"""shortest_edge""": 42}				)
        self.assertEqual(image_processor.crop_size     ,						{"""height""": 84, """width""": 84}				)





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[Any]				):
        pass





     def 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]				):
        # Initialize image_processing
        __lowerCamelCase:					List[str]	 =						self.image_processing_class(**self.image_processor_dict				)
        # create random PIL images
        __lowerCamelCase:					str	 =						prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE_				)
        for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE_     ,						Image.Image				)

        # Test not batched input
        __lowerCamelCase:					Optional[Any]	 =						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
        __lowerCamelCase:					Tuple	 =						image_processing(SCREAMING_SNAKE_CASE_     ,						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 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]				):
        # Initialize image_processing
        __lowerCamelCase:					Union[str, Any]	 =						self.image_processing_class(**self.image_processor_dict				)
        # create random numpy tensors
        __lowerCamelCase:					Tuple	 =						prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE_     ,						numpify=SCREAMING_SNAKE_CASE_				)
        for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE_     ,						np.ndarray				)

        # Test not batched input
        __lowerCamelCase:					List[Any]	 =						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
        __lowerCamelCase:					Optional[Any]	 =						image_processing(SCREAMING_SNAKE_CASE_     ,						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 			SCREAMING_SNAKE_CASE__							(     self       :					Optional[int]				):
        # Initialize image_processing
        __lowerCamelCase:					str	 =						self.image_processing_class(**self.image_processor_dict				)
        # create random PyTorch tensors
        __lowerCamelCase:					List[str]	 =						prepare_image_inputs(self.image_processor_tester     ,						equal_resolution=SCREAMING_SNAKE_CASE_     ,						torchify=SCREAMING_SNAKE_CASE_				)
        for image in image_inputs:
           self.assertIsInstance(SCREAMING_SNAKE_CASE_     ,						torch.Tensor				)

        # Test not batched input
        __lowerCamelCase:					Union[str, Any]	 =						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
        __lowerCamelCase:					Optional[int]	 =						image_processing(SCREAMING_SNAKE_CASE_     ,						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"""],
            )     ,						)


