






'''simple docstring'''
import os
import unittest

from transformers import BertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    BertTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english






@require_tokenizers
class        __SCREAMING_SNAKE_CASE (     lowerCamelCase		,			unittest.TestCase			):
 snake_case_												=							BertTokenizer
 snake_case_												=							BertTokenizerFast
 snake_case_												=							True
 snake_case_												=							True
 snake_case_												=							filter_non_english




 def        __magic_name__		( self		:							Optional[int] )		->  List[Any]:
       super().setUp()

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=[
           '''[UNK]''',
           '''[CLS]''',
           '''[SEP]''',
           '''[PAD]''',
           '''[MASK]''',
           '''want''',
           '''##want''',
           '''##ed''',
           '''wa''',
           '''un''',
           '''runn''',
           '''##ing''',
           ''',''',
           '''low''',
           '''lowest''',
       ]
       SCREAMING_SNAKE_CASE__       :			int													=os.path.join(self.tmpdirname   , VOCAB_FILES_NAMES['''vocab_file'''] )
       with open(self.vocab_file   , '''w'''   , encoding='''utf-8''' ) as vocab_writer:
             vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens] ) )




 def        __magic_name__		( self		:							int   , __lowercase		:							Optional[int] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			str													='''UNwant\u00E9d,running'''
       SCREAMING_SNAKE_CASE__       :			List[str]													='''unwanted, running'''
       return input_text, output_text




 def        __magic_name__		( self		:							Optional[Any] )		->  int:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.tokenizer_class(self.vocab_file )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer.tokenize('''UNwant\u00E9d,running''' )
       self.assertListEqual(__lowercase   , ['''un''', '''##want''', '''##ed''', ''',''', '''runn''', '''##ing'''] )
       self.assertListEqual(tokenizer.convert_tokens_to_ids(__lowercase )   , [9, 6, 7, 12, 10, 11] )




 def        __magic_name__		( self		:							Tuple )		->  Dict:
       if not self.test_rust_tokenizer:
             return

       SCREAMING_SNAKE_CASE__       :			Dict													=self.get_tokenizer()
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=self.get_rust_tokenizer()

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													='''UNwant\u00E9d,running'''

       SCREAMING_SNAKE_CASE__       :			List[str]													=tokenizer.tokenize(__lowercase )
       SCREAMING_SNAKE_CASE__       :			List[str]													=rust_tokenizer.tokenize(__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			str													=tokenizer.encode(__lowercase   , add_special_tokens=__lowercase )
       SCREAMING_SNAKE_CASE__       :			str													=rust_tokenizer.encode(__lowercase   , add_special_tokens=__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			List[str]													=self.get_rust_tokenizer()
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=tokenizer.encode(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=rust_tokenizer.encode(__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )

       # With lower casing
       SCREAMING_SNAKE_CASE__       :			Any													=self.get_tokenizer(do_lower_case=__lowercase )
       SCREAMING_SNAKE_CASE__       :			str													=self.get_rust_tokenizer(do_lower_case=__lowercase )

       SCREAMING_SNAKE_CASE__       :			Dict													='''UNwant\u00E9d,running'''

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer.tokenize(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=rust_tokenizer.tokenize(__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			Tuple													=tokenizer.encode(__lowercase   , add_special_tokens=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Tuple													=rust_tokenizer.encode(__lowercase   , add_special_tokens=__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )

       SCREAMING_SNAKE_CASE__       :			int													=self.get_rust_tokenizer()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=tokenizer.encode(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=rust_tokenizer.encode(__lowercase )
       self.assertListEqual(__lowercase   , __lowercase )




 def        __magic_name__		( self		:							int )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=BasicTokenizer()

       self.assertListEqual(tokenizer.tokenize('''ah\u535A\u63A8zz''' )   , ['''ah''', '''\u535A''', '''\u63A8''', '''zz'''] )




 def        __magic_name__		( self		:							Optional[int] )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			Any													=BasicTokenizer(do_lower_case=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  ''' )   , ['''hello''', '''!''', '''how''', '''are''', '''you''', '''?'''] )
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo''' )   , ['''hello'''] )




 def        __magic_name__		( self		:							List[str] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Dict													=BasicTokenizer(do_lower_case=__lowercase   , strip_accents=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  ''' )   , ['''hällo''', '''!''', '''how''', '''are''', '''you''', '''?'''] )
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo''' )   , ['''h\u00E9llo'''] )




 def        __magic_name__		( self		:							Optional[Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=BasicTokenizer(do_lower_case=__lowercase   , strip_accents=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  ''' )   , ['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?'''] )
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo''' )   , ['''hello'''] )




 def        __magic_name__		( self		:							Tuple )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Dict													=BasicTokenizer(do_lower_case=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  ''' )   , ['''hallo''', '''!''', '''how''', '''are''', '''you''', '''?'''] )
       self.assertListEqual(tokenizer.tokenize('''H\u00E9llo''' )   , ['''hello'''] )




 def        __magic_name__		( self		:							str )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=BasicTokenizer(do_lower_case=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU?  ''' )   , ['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?'''] )




 def        __magic_name__		( self		:							List[str] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			str													=BasicTokenizer(do_lower_case=__lowercase   , strip_accents=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  ''' )   , ['''HäLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?'''] )




 def        __magic_name__		( self		:							int )		->  int:
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=BasicTokenizer(do_lower_case=__lowercase   , strip_accents=__lowercase )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHäLLo!how  \n Are yoU?  ''' )   , ['''HaLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?'''] )




 def        __magic_name__		( self		:							Union[str, Any] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=BasicTokenizer(do_lower_case=__lowercase   , never_split=['''[UNK]'''] )

       self.assertListEqual(
           tokenizer.tokenize(''' \tHeLLo!how  \n Are yoU? [UNK]''' )   , ['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''', '''[UNK]'''] )




 def        __magic_name__		( self		:							List[str] )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Dict													=BasicTokenizer()
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													='''a\n\'ll !!to?\'d of, can\'t.'''
       SCREAMING_SNAKE_CASE__       :			Tuple													=['''a''', '''\'''', '''ll''', '''!''', '''!''', '''to''', '''?''', '''\'''', '''d''', '''of''', ''',''', '''can''', '''\'''', '''t''', '''.''']
       self.assertListEqual(tokenizer.tokenize(__lowercase )   , __lowercase )




 def        __magic_name__		( self		:							List[str] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			int													=['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

       SCREAMING_SNAKE_CASE__       :			int													={}
       for i, token in enumerate(__lowercase ):
             SCREAMING_SNAKE_CASE__       :			List[Any]													=i
       SCREAMING_SNAKE_CASE__       :			str													=WordpieceTokenizer(vocab=__lowercase   , unk_token='''[UNK]''' )

       self.assertListEqual(tokenizer.tokenize('''''' )   , [] )

       self.assertListEqual(tokenizer.tokenize('''unwanted running''' )   , ['''un''', '''##want''', '''##ed''', '''runn''', '''##ing'''] )

       self.assertListEqual(tokenizer.tokenize('''unwantedX running''' )   , ['''[UNK]''', '''runn''', '''##ing'''] )




 def        __magic_name__		( self		:							Tuple )		->  Optional[Any]:
       self.assertTrue(_is_whitespace(''' ''' ) )
       self.assertTrue(_is_whitespace('''\t''' ) )
       self.assertTrue(_is_whitespace('''\r''' ) )
       self.assertTrue(_is_whitespace('''\n''' ) )
       self.assertTrue(_is_whitespace('''\u00A0''' ) )

       self.assertFalse(_is_whitespace('''A''' ) )
       self.assertFalse(_is_whitespace('''-''' ) )




 def        __magic_name__		( self		:							Union[str, Any] )		->  List[str]:
       self.assertTrue(_is_control('''\u0005''' ) )

       self.assertFalse(_is_control('''A''' ) )
       self.assertFalse(_is_control(''' ''' ) )
       self.assertFalse(_is_control('''\t''' ) )
       self.assertFalse(_is_control('''\r''' ) )




 def        __magic_name__		( self		:							int )		->  List[Any]:
       self.assertTrue(_is_punctuation('''-''' ) )
       self.assertTrue(_is_punctuation('''$''' ) )
       self.assertTrue(_is_punctuation('''`''' ) )
       self.assertTrue(_is_punctuation('''.''' ) )

       self.assertFalse(_is_punctuation('''A''' ) )
       self.assertFalse(_is_punctuation(''' ''' ) )




 def        __magic_name__		( self		:							Any )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			str													=self.get_tokenizer()
       SCREAMING_SNAKE_CASE__       :			int													=self.get_rust_tokenizer()

       # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
       self.assertListEqual([tokenizer.tokenize(__lowercase ) for t in ['''Test''', '''\xad''', '''test''']]   , [['''[UNK]'''], [], ['''[UNK]''']] )

       self.assertListEqual(
           [rust_tokenizer.tokenize(__lowercase ) for t in ['''Test''', '''\xad''', '''test''']]   , [['''[UNK]'''], [], ['''[UNK]''']] )




 @slow
 def        __magic_name__		( self		:							Optional[int] )		->  Optional[int]:
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.tokenizer_class.from_pretrained('''bert-base-uncased''' )

       SCREAMING_SNAKE_CASE__       :			int													=tokenizer.encode('''sequence builders'''   , add_special_tokens=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Any													=tokenizer.encode('''multi-sequence build'''   , add_special_tokens=__lowercase )

       SCREAMING_SNAKE_CASE__       :			int													=tokenizer.build_inputs_with_special_tokens(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Dict													=tokenizer.build_inputs_with_special_tokens(__lowercase   , __lowercase )

       assert encoded_sentence == [1_01] + text + [1_02]
       assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]




 def        __magic_name__		( self		:							Any )		->  str:
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})" ):
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=self.rust_tokenizer_class.from_pretrained(__lowercase   , **__lowercase )

                   SCREAMING_SNAKE_CASE__       :			Tuple													=F"A, naïve {tokenizer_r.mask_token} AllenNLP sentence."
                   SCREAMING_SNAKE_CASE__       :			Optional[int]													=tokenizer_r.encode_plus(
                       __lowercase   , return_attention_mask=__lowercase   , return_token_type_ids=__lowercase   , return_offsets_mapping=__lowercase   , add_special_tokens=__lowercase   , )

                   SCREAMING_SNAKE_CASE__       :			List[str]													=tokenizer_r.do_lower_case if hasattr(__lowercase   , '''do_lower_case''' ) else False
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=(
                       [
                           ((0, 0), tokenizer_r.cls_token),
                           ((0, 1), '''A'''),
                           ((1, 2), ''','''),
                           ((3, 5), '''na'''),
                           ((5, 6), '''##ï'''),
                           ((6, 8), '''##ve'''),
                           ((9, 15), tokenizer_r.mask_token),
                           ((16, 21), '''Allen'''),
                           ((21, 23), '''##NL'''),
                           ((23, 24), '''##P'''),
                           ((25, 33), '''sentence'''),
                           ((33, 34), '''.'''),
                           ((0, 0), tokenizer_r.sep_token),
                       ]
                       if not do_lower_case
                       else [
                           ((0, 0), tokenizer_r.cls_token),
                           ((0, 1), '''a'''),
                           ((1, 2), ''','''),
                           ((3, 8), '''naive'''),
                           ((9, 15), tokenizer_r.mask_token),
                           ((16, 21), '''allen'''),
                           ((21, 23), '''##nl'''),
                           ((23, 24), '''##p'''),
                           ((25, 33), '''sentence'''),
                           ((33, 34), '''.'''),
                           ((0, 0), tokenizer_r.sep_token),
                       ]
                   )

                   self.assertEqual(
                       [e[1] for e in expected_results]   , tokenizer_r.convert_ids_to_tokens(tokens['''input_ids'''] ) )
                   self.assertEqual([e[0] for e in expected_results]   , tokens['''offset_mapping'''] )




 def        __magic_name__		( self		:							List[str] )		->  Union[str, Any]:
       SCREAMING_SNAKE_CASE__       :			int													=['''的''', '''人''', '''有''']
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=''''''.join(__lowercase )
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})" ):
                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=True
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.tokenizer_class.from_pretrained(__lowercase   , **__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=self.rust_tokenizer_class.from_pretrained(__lowercase   , **__lowercase )

                   SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer_p.encode(__lowercase   , add_special_tokens=__lowercase )
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer_r.encode(__lowercase   , add_special_tokens=__lowercase )

                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=tokenizer_r.convert_ids_to_tokens(__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer_p.convert_ids_to_tokens(__lowercase )

                   # it is expected that each Chinese character is not preceded by "##"
                   self.assertListEqual(__lowercase   , __lowercase )
                   self.assertListEqual(__lowercase   , __lowercase )

                   SCREAMING_SNAKE_CASE__       :			List[Any]													=False
                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.rust_tokenizer_class.from_pretrained(__lowercase   , **__lowercase )
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=self.tokenizer_class.from_pretrained(__lowercase   , **__lowercase )

                   SCREAMING_SNAKE_CASE__       :			int													=tokenizer_r.encode(__lowercase   , add_special_tokens=__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[int]													=tokenizer_p.encode(__lowercase   , add_special_tokens=__lowercase )

                   SCREAMING_SNAKE_CASE__       :			Any													=tokenizer_r.convert_ids_to_tokens(__lowercase )
                   SCREAMING_SNAKE_CASE__       :			List[str]													=tokenizer_p.convert_ids_to_tokens(__lowercase )

                   # it is expected that only the first Chinese character is not preceded by "##".
                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=[
                       F"##{token}" if idx != 0 else token for idx, token in enumerate(__lowercase )
                   ]
                   self.assertListEqual(__lowercase   , __lowercase )
                   self.assertListEqual(__lowercase   , __lowercase )







'''simple docstring'''
from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
  import torch


a_					=	logging.get_logger(__name__)






class        __SCREAMING_SNAKE_CASE (     lowerCamelCase			):
 snake_case_												=							["""pixel_values"""]




 def __init__( self		:							List[str]   , __lowercase		:							bool = True   , __lowercase		:							Optional[Dict[str, int]] = None   , __lowercase		:							PILImageResampling = PILImageResampling.BILINEAR   , __lowercase		:							bool = True   , __lowercase		:							Dict[str, int] = None   , __lowercase		:							bool = True   , __lowercase		:							Union[int, float] = 1 / 2_55   , __lowercase		:							bool = True   , __lowercase		:							Optional[Union[float, List[float]]] = None   , __lowercase		:							Optional[Union[float, List[float]]] = None   , **__lowercase		:							List[Any]   , )		->  None:
       super().__init__(**__lowercase )
       SCREAMING_SNAKE_CASE__       :			Any													=size if size is not None else {'''shortest_edge''': 2_56}
       SCREAMING_SNAKE_CASE__       :			str													=get_size_dict(__lowercase   , default_to_square=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Dict													=crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
       SCREAMING_SNAKE_CASE__       :			Tuple													=get_size_dict(__lowercase   , param_name='''crop_size''' )
       SCREAMING_SNAKE_CASE__       :			int													=do_resize
       SCREAMING_SNAKE_CASE__       :			Dict													=size
       SCREAMING_SNAKE_CASE__       :			List[str]													=resample
       SCREAMING_SNAKE_CASE__       :			List[Any]													=do_center_crop
       SCREAMING_SNAKE_CASE__       :			str													=crop_size
       SCREAMING_SNAKE_CASE__       :			List[str]													=do_rescale
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=rescale_factor
       SCREAMING_SNAKE_CASE__       :			List[str]													=do_normalize
       SCREAMING_SNAKE_CASE__       :			Any													=image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=image_std if image_std is not None else IMAGENET_STANDARD_STD




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							np.ndarray   , __lowercase		:							Dict[str, int]   , __lowercase		:							PILImageResampling = PILImageResampling.BICUBIC   , __lowercase		:							Optional[Union[str, ChannelDimension]] = None   , **__lowercase		:							Optional[Any]   , )		->  np.ndarray:
       SCREAMING_SNAKE_CASE__       :			str													=get_size_dict(__lowercase   , default_to_square=__lowercase )
       if "shortest_edge" not in size:
             raise ValueError(F"The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}" )
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=get_resize_output_image_size(__lowercase   , size=size['''shortest_edge''']   , default_to_square=__lowercase )
       return resize(__lowercase   , size=__lowercase   , resample=__lowercase   , data_format=__lowercase   , **__lowercase )




 def        __magic_name__		( self		:							int   , __lowercase		:							np.ndarray   , __lowercase		:							Dict[str, int]   , __lowercase		:							Optional[Union[str, ChannelDimension]] = None   , **__lowercase		:							Any   , )		->  np.ndarray:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=get_size_dict(__lowercase )
       if "height" not in size or "width" not in size:
             raise ValueError(F"The `size` parameter must contain the keys `height` and `width`. Got {size.keys()}" )
       return center_crop(__lowercase   , size=(size['''height'''], size['''width'''])   , data_format=__lowercase   , **__lowercase )




 def        __magic_name__		( self		:							Optional[Any]   , __lowercase		:							np.ndarray   , __lowercase		:							float   , __lowercase		:							Optional[Union[str, ChannelDimension]] = None   , **__lowercase		:							Tuple )		->  np.ndarray:
       return rescale(__lowercase   , scale=__lowercase   , data_format=__lowercase   , **__lowercase )




 def        __magic_name__		( self		:							Dict   , __lowercase		:							np.ndarray   , __lowercase		:							Union[float, List[float]]   , __lowercase		:							Union[float, List[float]]   , __lowercase		:							Optional[Union[str, ChannelDimension]] = None   , **__lowercase		:							str   , )		->  np.ndarray:
       return normalize(__lowercase   , mean=__lowercase   , std=__lowercase   , data_format=__lowercase   , **__lowercase )




 def        __magic_name__		( self		:							List[Any]   , __lowercase		:							ImageInput   , __lowercase		:							Optional[bool] = None   , __lowercase		:							Dict[str, int] = None   , __lowercase		:							PILImageResampling = None   , __lowercase		:							bool = None   , __lowercase		:							Dict[str, int] = None   , __lowercase		:							Optional[bool] = None   , __lowercase		:							Optional[float] = None   , __lowercase		:							Optional[bool] = None   , __lowercase		:							Optional[Union[float, List[float]]] = None   , __lowercase		:							Optional[Union[float, List[float]]] = None   , __lowercase		:							Optional[Union[str, TensorType]] = None   , __lowercase		:							Union[str, ChannelDimension] = ChannelDimension.FIRST   , **__lowercase		:							int   , )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=do_resize if do_resize is not None else self.do_resize
       SCREAMING_SNAKE_CASE__       :			int													=size if size is not None else self.size
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=get_size_dict(__lowercase   , default_to_square=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Any													=resample if resample is not None else self.resample
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=do_center_crop if do_center_crop is not None else self.do_center_crop
       SCREAMING_SNAKE_CASE__       :			List[str]													=crop_size if crop_size is not None else self.crop_size
       SCREAMING_SNAKE_CASE__       :			int													=get_size_dict(__lowercase   , param_name='''crop_size''' )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=do_rescale if do_rescale is not None else self.do_rescale
       SCREAMING_SNAKE_CASE__       :			int													=rescale_factor if rescale_factor is not None else self.rescale_factor
       SCREAMING_SNAKE_CASE__       :			List[str]													=do_normalize if do_normalize is not None else self.do_normalize
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=image_mean if image_mean is not None else self.image_mean
       SCREAMING_SNAKE_CASE__       :			Any													=image_std if image_std is not None else self.image_std

       SCREAMING_SNAKE_CASE__       :			str													=make_list_of_images(__lowercase )

       if not valid_images(__lowercase ):
             raise ValueError(
                 '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
                 '''torch.Tensor, tf.Tensor or jax.ndarray.''' )

       if do_resize and size is None:
             raise ValueError('''Size must be specified if do_resize is True.''' )

       if do_center_crop and crop_size is None:
             raise ValueError('''Crop size must be specified if do_center_crop is True.''' )

       if do_rescale and rescale_factor is None:
             raise ValueError('''Rescale factor must be specified if do_rescale is True.''' )

       if do_normalize and (image_mean is None or image_std is None):
             raise ValueError('''Image mean and std must be specified if do_normalize is True.''' )

       # All transformations expect numpy arrays.
       SCREAMING_SNAKE_CASE__       :			Dict													=[to_numpy_array(__lowercase ) for image in images]

       if do_resize:
             SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=[self.resize(image=__lowercase   , size=__lowercase   , resample=__lowercase ) for image in images]

       if do_center_crop:
             SCREAMING_SNAKE_CASE__       :			List[Any]													=[self.center_crop(image=__lowercase   , size=__lowercase ) for image in images]

       if do_rescale:
             SCREAMING_SNAKE_CASE__       :			List[Any]													=[self.rescale(image=__lowercase   , scale=__lowercase ) for image in images]

       if do_normalize:
             SCREAMING_SNAKE_CASE__       :			Tuple													=[self.normalize(image=__lowercase   , mean=__lowercase   , std=__lowercase ) for image in images]

       SCREAMING_SNAKE_CASE__       :			str													=[to_channel_dimension_format(__lowercase   , __lowercase ) for image in images]

       SCREAMING_SNAKE_CASE__       :			Any													={'''pixel_values''': images}
       return BatchFeature(data=__lowercase   , tensor_type=__lowercase )




 def        __magic_name__		( self		:							Optional[int]   , __lowercase		:							Tuple   , __lowercase		:							List[Tuple] = None )		->  Any:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=outputs.logits

       # Resize logits and compute semantic segmentation maps
       if target_sizes is not None:
             if len(__lowercase ) != len(__lowercase ):
                   raise ValueError(
                       '''Make sure that you pass in as many target sizes as the batch dimension of the logits''' )

             if is_torch_tensor(__lowercase ):
                   SCREAMING_SNAKE_CASE__       :			int													=target_sizes.numpy()

             SCREAMING_SNAKE_CASE__       :			List[Any]													=[]

             for idx in range(len(__lowercase ) ):
                   SCREAMING_SNAKE_CASE__       :			Any													=torch.nn.functional.interpolate(
                       logits[idx].unsqueeze(dim=0 )   , size=target_sizes[idx]   , mode='''bilinear'''   , align_corners=__lowercase )
                   SCREAMING_SNAKE_CASE__       :			List[str]													=resized_logits[0].argmax(dim=0 )
                   semantic_segmentation.append(__lowercase )
       else:
             SCREAMING_SNAKE_CASE__       :			Any													=logits.argmax(dim=1 )
             SCREAMING_SNAKE_CASE__       :			Optional[int]													=[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0] )]

       return semantic_segmentation