'''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 lowerCamelCase							(	lowerCamelCase     ,		unittest.TestCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	BertTokenizer
  lowerCAmelCase__										=	BertTokenizerFast
  lowerCAmelCase__										=	True
  lowerCAmelCase__										=	True
  lowerCAmelCase__										=	filter_non_english






  def  lowerCAmelCase__ (      self			:       Optional[Any]  )				->str:
        super().setUp()

        UpperCAmelCase_            =  [
            '''[UNK]''',
            '''[CLS]''',
            '''[SEP]''',
            '''[PAD]''',
            '''[MASK]''',
            '''want''',
            '''##want''',
            '''##ed''',
            '''wa''',
            '''un''',
            '''runn''',
            '''##ing''',
            ''',''',
            '''low''',
            '''lowest''',
        ]
        UpperCAmelCase_            =  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  lowerCAmelCase__ (      self			:       Any  ,							UpperCAmelCase__			:       Any  )				->Tuple:
        UpperCAmelCase_            =  '''UNwant\u00E9d,running'''
        UpperCAmelCase_            =  '''unwanted, running'''
        return input_text, output_text






  def  lowerCAmelCase__ (      self			:       List[str]  )				->Tuple:
        UpperCAmelCase_            =  self.tokenizer_class(self.vocab_file  )

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






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->List[Any]:
        if not self.test_rust_tokenizer:
              return

        UpperCAmelCase_            =  self.get_tokenizer()
        UpperCAmelCase_            =  self.get_rust_tokenizer()

        UpperCAmelCase_            =  '''UNwant\u00E9d,running'''

        UpperCAmelCase_            =  tokenizer.tokenize(UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.tokenize(UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  tokenizer.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  self.get_rust_tokenizer()
        UpperCAmelCase_            =  tokenizer.encode(UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.encode(UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        # With lower casing
        UpperCAmelCase_            =  self.get_tokenizer(do_lower_case=UpperCAmelCase__  )
        UpperCAmelCase_            =  self.get_rust_tokenizer(do_lower_case=UpperCAmelCase__  )

        UpperCAmelCase_            =  '''UNwant\u00E9d,running'''

        UpperCAmelCase_            =  tokenizer.tokenize(UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.tokenize(UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  tokenizer.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )

        UpperCAmelCase_            =  self.get_rust_tokenizer()
        UpperCAmelCase_            =  tokenizer.encode(UpperCAmelCase__  )
        UpperCAmelCase_            =  rust_tokenizer.encode(UpperCAmelCase__  )
        self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       Dict  )				->Any:
        UpperCAmelCase_            =  BasicTokenizer()

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






  def  lowerCAmelCase__ (      self			:       Dict  )				->Union[str, Any]:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       List[str]  )				->Any:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  ,							strip_accents=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       List[str]  )				->Tuple:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  ,							strip_accents=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       int  )				->Any:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       Dict  )				->Union[str, Any]:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       List[str]  )				->List[Any]:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  ,							strip_accents=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       Optional[Any]  )				->Optional[int]:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  ,							strip_accents=UpperCAmelCase__  )

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






  def  lowerCAmelCase__ (      self			:       Any  )				->List[str]:
        UpperCAmelCase_            =  BasicTokenizer(do_lower_case=UpperCAmelCase__  ,							never_split=['''[UNK]''']  )

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






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






  def  lowerCAmelCase__ (      self			:       Optional[int]  )				->Dict:
        UpperCAmelCase_            =  ['''[UNK]''', '''[CLS]''', '''[SEP]''', '''want''', '''##want''', '''##ed''', '''wa''', '''un''', '''runn''', '''##ing''']

        UpperCAmelCase_            =  {}
        for i, token in enumerate(UpperCAmelCase__  ):
              UpperCAmelCase_            =  i
        UpperCAmelCase_            =  WordpieceTokenizer(vocab=UpperCAmelCase__  ,							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  lowerCAmelCase__ (      self			:       Optional[int]  )				->Union[str, 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  lowerCAmelCase__ (      self			:       List[Any]  )				->Optional[int]:
        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  lowerCAmelCase__ (      self			:       Union[str, Any]  )				->int:
        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  lowerCAmelCase__ (      self			:       List[Any]  )				->List[str]:
        UpperCAmelCase_            =  self.get_tokenizer()
        UpperCAmelCase_            =  self.get_rust_tokenizer()

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

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






  @slow
  def  lowerCAmelCase__ (      self			:       Any  )				->Union[str, Any]:
        UpperCAmelCase_            =  self.tokenizer_class.from_pretrained('''bert-base-uncased'''  )

        UpperCAmelCase_            =  tokenizer.encode('''sequence builders'''  ,							add_special_tokens=UpperCAmelCase__  )
        UpperCAmelCase_            =  tokenizer.encode('''multi-sequence build'''  ,							add_special_tokens=UpperCAmelCase__  )

        UpperCAmelCase_            =  tokenizer.build_inputs_with_special_tokens(UpperCAmelCase__  )
        UpperCAmelCase_            =  tokenizer.build_inputs_with_special_tokens(UpperCAmelCase__  ,							UpperCAmelCase__  )

        assert encoded_sentence == [101] + text + [102]
        assert encoded_pair == [101] + text + [102] + text_a + [102]






  def  lowerCAmelCase__ (      self			:       Tuple  )				->Union[str, Any]:
        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""  ):
                    UpperCAmelCase_            =  self.rust_tokenizer_class.from_pretrained(UpperCAmelCase__  ,							**UpperCAmelCase__  )

                    UpperCAmelCase_            =  f"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                    UpperCAmelCase_            =  tokenizer_r.encode_plus(
                        UpperCAmelCase__  ,							return_attention_mask=UpperCAmelCase__  ,							return_token_type_ids=UpperCAmelCase__  ,							return_offsets_mapping=UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  ,							)

                    UpperCAmelCase_            =  tokenizer_r.do_lower_case if hasattr(UpperCAmelCase__  ,							'''do_lower_case'''  ) else False
                    UpperCAmelCase_            =  (
                        [
                            ((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  lowerCAmelCase__ (      self			:       Union[str, Any]  )				->int:
        UpperCAmelCase_            =  ['''的''', '''人''', '''有''']
        UpperCAmelCase_            =  ''''''.join(UpperCAmelCase__  )
        for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""  ):
                    UpperCAmelCase_            =  True
                    UpperCAmelCase_            =  self.tokenizer_class.from_pretrained(UpperCAmelCase__  ,							**UpperCAmelCase__  )
                    UpperCAmelCase_            =  self.rust_tokenizer_class.from_pretrained(UpperCAmelCase__  ,							**UpperCAmelCase__  )

                    UpperCAmelCase_            =  tokenizer_p.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
                    UpperCAmelCase_            =  tokenizer_r.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )

                    UpperCAmelCase_            =  tokenizer_r.convert_ids_to_tokens(UpperCAmelCase__  )
                    UpperCAmelCase_            =  tokenizer_p.convert_ids_to_tokens(UpperCAmelCase__  )

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

                    UpperCAmelCase_            =  False
                    UpperCAmelCase_            =  self.rust_tokenizer_class.from_pretrained(UpperCAmelCase__  ,							**UpperCAmelCase__  )
                    UpperCAmelCase_            =  self.tokenizer_class.from_pretrained(UpperCAmelCase__  ,							**UpperCAmelCase__  )

                    UpperCAmelCase_            =  tokenizer_r.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )
                    UpperCAmelCase_            =  tokenizer_p.encode(UpperCAmelCase__  ,							add_special_tokens=UpperCAmelCase__  )

                    UpperCAmelCase_            =  tokenizer_r.convert_ids_to_tokens(UpperCAmelCase__  )
                    UpperCAmelCase_            =  tokenizer_p.convert_ids_to_tokens(UpperCAmelCase__  )

                    # it is expected that only the first Chinese character is not preceded by "##".
                    UpperCAmelCase_            =  [
                        f"""##{token}""" if idx != 0 else token for idx, token in enumerate(UpperCAmelCase__  )
                    ]
                    self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )
                    self.assertListEqual(UpperCAmelCase__  ,							UpperCAmelCase__  )






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

import numpy as np

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


if is_torch_available():
      import torch

if is_vision_available():
      import PIL


lowercase__  :      Optional[int]        =					logging.get_logger(__name__)



def  __lowerCamelCase       (      _UpperCamelCase  :  np.ndarray							,    _UpperCamelCase  :  Union[int, Iterable[int]]							,    _UpperCamelCase  :  bool							,    _UpperCamelCase  :  int					):


      '''simple docstring'''


      def constraint_to_multiple_of(_UpperCamelCase  :  int							,    _UpperCamelCase  :  Tuple							,    _UpperCamelCase  :  Optional[int]=0							,    _UpperCamelCase  :  str=None					):
            UpperCAmelCase_            =  round(val / multiple					) * multiple

            if max_val is not None and x > max_val:
                  UpperCAmelCase_            =  math.floor(val / multiple					) * multiple

            if x < min_val:
                  UpperCAmelCase_            =  math.ceil(val / multiple					) * multiple

            return x

      UpperCAmelCase_            =  (output_size, output_size) if isinstance(_UpperCamelCase							,    _UpperCamelCase					) else output_size

      UpperCAmelCase_      ,		UpperCAmelCase_            =  get_image_size(_UpperCamelCase					)
      UpperCAmelCase_      ,		UpperCAmelCase_            =  output_size

      # determine new height and width
      UpperCAmelCase_            =  output_height / input_height
      UpperCAmelCase_            =  output_width / input_width

      if keep_aspect_ratio:
            # scale as little as possible
            if abs(1 - scale_width					) < abs(1 - scale_height					):
                  # fit width
                  UpperCAmelCase_            =  scale_width
            else:
                  # fit height
                  UpperCAmelCase_            =  scale_height

      UpperCAmelCase_            =  constraint_to_multiple_of(scale_height * input_height							,    multiple=_UpperCamelCase					)
      UpperCAmelCase_            =  constraint_to_multiple_of(scale_width * input_width							,    multiple=_UpperCamelCase					)

      return (new_height, new_width)







class lowerCamelCase							(	lowerCamelCase					):




  '''simple docstring'''



  lowerCAmelCase__										=	['''pixel_values''']






  def __init__(      self			:       Any  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Dict[str, int] = None  ,							UpperCAmelCase__			:       PILImageResampling = PILImageResampling.BILINEAR  ,							UpperCAmelCase__			:       bool = False  ,							UpperCAmelCase__			:       int = 1  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Union[int, float] = 1 / 255  ,							UpperCAmelCase__			:       bool = True  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							**UpperCAmelCase__			:       str  ,							)				->None:
        super().__init__(**UpperCAmelCase__  )
        UpperCAmelCase_            =  size if size is not None else {'''height''': 384, '''width''': 384}
        UpperCAmelCase_            =  get_size_dict(UpperCAmelCase__  )
        UpperCAmelCase_            =  do_resize
        UpperCAmelCase_            =  size
        UpperCAmelCase_            =  keep_aspect_ratio
        UpperCAmelCase_            =  ensure_multiple_of
        UpperCAmelCase_            =  resample
        UpperCAmelCase_            =  do_rescale
        UpperCAmelCase_            =  rescale_factor
        UpperCAmelCase_            =  do_normalize
        UpperCAmelCase_            =  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
        UpperCAmelCase_            =  image_std if image_std is not None else IMAGENET_STANDARD_STD






  def  lowerCAmelCase__ (      self			:       Union[str, Any]  ,							UpperCAmelCase__			:       np.ndarray  ,							UpperCAmelCase__			:       Dict[str, int]  ,							UpperCAmelCase__			:       bool = False  ,							UpperCAmelCase__			:       int = 1  ,							UpperCAmelCase__			:       PILImageResampling = PILImageResampling.BICUBIC  ,							UpperCAmelCase__			:       Optional[Union[str, ChannelDimension]] = None  ,							**UpperCAmelCase__			:       List[str]  ,							)				->np.ndarray:
        UpperCAmelCase_            =  get_size_dict(UpperCAmelCase__  )
        if "height" not in size or "width" not in size:
              raise ValueError(f"""The size dictionary must contain the keys 'height' and 'width'. Got {size.keys()}"""  )
        UpperCAmelCase_            =  get_resize_output_image_size(
            UpperCAmelCase__  ,							output_size=(size['''height'''], size['''width'''])  ,							keep_aspect_ratio=UpperCAmelCase__  ,							multiple=UpperCAmelCase__  ,							)
        return resize(UpperCAmelCase__  ,							size=UpperCAmelCase__  ,							resample=UpperCAmelCase__  ,							data_format=UpperCAmelCase__  ,							**UpperCAmelCase__  )






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






  def  lowerCAmelCase__ (      self			:       List[Any]  ,							UpperCAmelCase__			:       np.ndarray  ,							UpperCAmelCase__			:       Union[float, List[float]]  ,							UpperCAmelCase__			:       Union[float, List[float]]  ,							UpperCAmelCase__			:       Optional[Union[str, ChannelDimension]] = None  ,							**UpperCAmelCase__			:       Optional[int]  ,							)				->np.ndarray:
        return normalize(UpperCAmelCase__  ,							mean=UpperCAmelCase__  ,							std=UpperCAmelCase__  ,							data_format=UpperCAmelCase__  ,							**UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       str  ,							UpperCAmelCase__			:       ImageInput  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       int = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       int = None  ,							UpperCAmelCase__			:       PILImageResampling = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       float = None  ,							UpperCAmelCase__			:       bool = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[float, List[float]]] = None  ,							UpperCAmelCase__			:       Optional[Union[str, TensorType]] = None  ,							UpperCAmelCase__			:       ChannelDimension = ChannelDimension.FIRST  ,							**UpperCAmelCase__			:       Any  ,							)				->PIL.Image.Image:
        UpperCAmelCase_            =  do_resize if do_resize is not None else self.do_resize
        UpperCAmelCase_            =  size if size is not None else self.size
        UpperCAmelCase_            =  get_size_dict(UpperCAmelCase__  )
        UpperCAmelCase_            =  keep_aspect_ratio if keep_aspect_ratio is not None else self.keep_aspect_ratio
        UpperCAmelCase_            =  ensure_multiple_of if ensure_multiple_of is not None else self.ensure_multiple_of
        UpperCAmelCase_            =  resample if resample is not None else self.resample
        UpperCAmelCase_            =  do_rescale if do_rescale is not None else self.do_rescale
        UpperCAmelCase_            =  rescale_factor if rescale_factor is not None else self.rescale_factor
        UpperCAmelCase_            =  do_normalize if do_normalize is not None else self.do_normalize
        UpperCAmelCase_            =  image_mean if image_mean is not None else self.image_mean
        UpperCAmelCase_            =  image_std if image_std is not None else self.image_std

        UpperCAmelCase_            =  make_list_of_images(UpperCAmelCase__  )

        if not valid_images(UpperCAmelCase__  ):
              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 or resample is None:
              raise ValueError('''Size and resample must be specified if do_resize 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.
        UpperCAmelCase_            =  [to_numpy_array(UpperCAmelCase__  ) for image in images]

        if do_resize:
              UpperCAmelCase_            =  [self.resize(image=UpperCAmelCase__  ,							size=UpperCAmelCase__  ,							resample=UpperCAmelCase__  ) for image in images]

        if do_rescale:
              UpperCAmelCase_            =  [self.rescale(image=UpperCAmelCase__  ,							scale=UpperCAmelCase__  ) for image in images]

        if do_normalize:
              UpperCAmelCase_            =  [self.normalize(image=UpperCAmelCase__  ,							mean=UpperCAmelCase__  ,							std=UpperCAmelCase__  ) for image in images]

        UpperCAmelCase_            =  [to_channel_dimension_format(UpperCAmelCase__  ,							UpperCAmelCase__  ) for image in images]

        UpperCAmelCase_            =  {'''pixel_values''': images}
        return BatchFeature(data=UpperCAmelCase__  ,							tensor_type=UpperCAmelCase__  )






  def  lowerCAmelCase__ (      self			:       List[str]  ,							UpperCAmelCase__			:       List[Any]  ,							UpperCAmelCase__			:       List[Tuple] = None  )				->Optional[Any]:
        UpperCAmelCase_            =  outputs.logits

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

              if is_torch_tensor(UpperCAmelCase__  ):
                    UpperCAmelCase_            =  target_sizes.numpy()

              UpperCAmelCase_            =  []

              for idx in range(len(UpperCAmelCase__  )  ):
                    UpperCAmelCase_            =  torch.nn.functional.interpolate(
                        logits[idx].unsqueeze(dim=0  )  ,							size=target_sizes[idx]  ,							mode='''bilinear'''  ,							align_corners=UpperCAmelCase__  )
                    UpperCAmelCase_            =  resized_logits[0].argmax(dim=0  )
                    semantic_segmentation.append(UpperCAmelCase__  )
        else:
              UpperCAmelCase_            =  logits.argmax(dim=1  )
              UpperCAmelCase_            =  [semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]  )]

        return semantic_segmentation





