






'''simple docstring'''
import shutil
import tempfile
import unittest

from transformers import SPIECE_UNDERLINE, BatchEncoding, MBartaaTokenizer, MBartaaTokenizerFast, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
    slow,
)

from ...test_tokenization_common import TokenizerTesterMixin


a_					=	get_tests_dir('fixtures/test_sentencepiece.model')

if is_torch_available():
  from transformers.models.mbart.modeling_mbart import shift_tokens_right

a_					=	2_5_0_0_0_4
a_					=	2_5_0_0_2_0






@require_sentencepiece
@require_tokenizers
class        __SCREAMING_SNAKE_CASE (     lowerCamelCase		,			unittest.TestCase			):
 snake_case_												=							MBartaaTokenizer
 snake_case_												=							MBartaaTokenizerFast
 snake_case_												=							True
 snake_case_												=							True




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

       # We have a SentencePiece fixture for testing
       SCREAMING_SNAKE_CASE__       :			int													=MBartaaTokenizer(__lowercase   , src_lang='''en_XX'''   , tgt_lang='''ro_RO'''   , keep_accents=__lowercase )
       tokenizer.save_pretrained(self.tmpdirname )




 def        __magic_name__		( self		:							Any )		->  Tuple:
       SCREAMING_SNAKE_CASE__       :			List[str]													='''<s>'''
       SCREAMING_SNAKE_CASE__       :			List[str]													=0

       self.assertEqual(self.get_tokenizer()._convert_token_to_id(__lowercase )   , __lowercase )
       self.assertEqual(self.get_tokenizer()._convert_id_to_token(__lowercase )   , __lowercase )




 def        __magic_name__		( self		:							Optional[int] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=list(self.get_tokenizer().get_vocab().keys() )

       self.assertEqual(vocab_keys[0]   , '''<s>''' )
       self.assertEqual(vocab_keys[1]   , '''<pad>''' )
       self.assertEqual(vocab_keys[-1]   , '''<mask>''' )
       self.assertEqual(len(__lowercase )   , 10_54 )




 def        __magic_name__		( self		:							Optional[int] )		->  Tuple:
       self.assertEqual(self.get_tokenizer().vocab_size   , 10_54 )




 def        __magic_name__		( self		:							Tuple )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			List[Any]													=MBartaaTokenizer(__lowercase   , src_lang='''en_XX'''   , tgt_lang='''ro_RO'''   , keep_accents=__lowercase )

       SCREAMING_SNAKE_CASE__       :			Dict													=tokenizer.tokenize('''This is a test''' )
       self.assertListEqual(__lowercase   , ['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est'''] )

       self.assertListEqual(
           tokenizer.convert_tokens_to_ids(__lowercase )   , [value + tokenizer.fairseq_offset for value in [2_85, 46, 10, 1_70, 3_82]]   , )

       SCREAMING_SNAKE_CASE__       :			Any													=tokenizer.tokenize('''I was born in 92000, and this is falsé.''' )
       self.assertListEqual(
           __lowercase   , [SPIECE_UNDERLINE + '''I''', SPIECE_UNDERLINE + '''was''', SPIECE_UNDERLINE + '''b''', '''or''', '''n''', SPIECE_UNDERLINE + '''in''', SPIECE_UNDERLINE + '''''', '''9''', '''2''', '''0''', '''0''', '''0''', ''',''', SPIECE_UNDERLINE + '''and''', SPIECE_UNDERLINE + '''this''', SPIECE_UNDERLINE + '''is''', SPIECE_UNDERLINE + '''f''', '''al''', '''s''', '''é''', '''.''']   , )
       SCREAMING_SNAKE_CASE__       :			List[str]													=tokenizer.convert_tokens_to_ids(__lowercase )
       self.assertListEqual(
           __lowercase   , [
               value + tokenizer.fairseq_offset
               for value in [8, 21, 84, 55, 24, 19, 7, 2, 6_02, 3_47, 3_47, 3_47, 3, 12, 66, 46, 72, 80, 6, 2, 4]
           ]   , )

       SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer.convert_ids_to_tokens(__lowercase )
       self.assertListEqual(
           __lowercase   , [SPIECE_UNDERLINE + '''I''', SPIECE_UNDERLINE + '''was''', SPIECE_UNDERLINE + '''b''', '''or''', '''n''', SPIECE_UNDERLINE + '''in''', SPIECE_UNDERLINE + '''''', '''<unk>''', '''2''', '''0''', '''0''', '''0''', ''',''', SPIECE_UNDERLINE + '''and''', SPIECE_UNDERLINE + '''this''', SPIECE_UNDERLINE + '''is''', SPIECE_UNDERLINE + '''f''', '''al''', '''s''', '''<unk>''', '''.''']   , )




 @slow
 def        __magic_name__		( self		:							Optional[int] )		->  Optional[Any]:
       # fmt: off
       SCREAMING_SNAKE_CASE__       :			List[str]													={'''input_ids''': [[25_00_04, 1_10_62, 8_27_72, 7, 15, 8_27_72, 5_38, 5_15_29, 2_37, 1_71_98, 12_90, 2_06, 9, 21_51_75, 13_14, 1_36, 1_71_98, 12_90, 2_06, 9, 5_63_59, 42, 12_20_09, 9, 1_64_66, 16, 8_73_44, 45_37, 9, 47_17, 7_83_81, 6, 15_99_58, 7, 15, 2_44_80, 6_18, 4, 5_27, 2_26_93, 54_28, 4, 27_77, 2_44_80, 98_74, 4, 4_35_23, 5_94, 4, 8_03, 1_83_92, 3_31_89, 18, 4, 4_35_23, 2_44_47, 1_23_99, 1_00, 2_49_55, 8_36_58, 96_26, 14_40_57, 15, 8_39, 2_23_35, 16, 1_36, 2_49_55, 8_36_58, 8_34_79, 15, 3_91_02, 7_24, 16, 6_78, 6_45, 27_89, 13_28, 45_89, 42, 12_20_09, 11_57_74, 23, 8_05, 13_28, 4_68_76, 7, 1_36, 5_38_94, 19_40, 4_22_27, 4_11_59, 1_77_21, 8_23, 4_25, 4, 2_75_12, 9_87_22, 2_06, 1_36, 55_31, 49_70, 9_19, 1_73_36, 5, 2], [25_00_04, 2_00_80, 6_18, 83, 8_27_75, 47, 4_79, 9, 15_17, 73, 5_38_94, 3_33, 8_05_81, 11_01_17, 1_88_11, 52_56, 12_95, 51, 15_25_26, 2_97, 79_86, 3_90, 12_44_16, 5_38, 3_54_31, 2_14, 98, 1_50_44, 2_57_37, 1_36, 71_08, 4_37_01, 23, 7_56, 13_53_55, 7, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [25_00_04, 5_81, 6_37_73, 11_94_55, 6, 14_77_97, 8_82_03, 7, 6_45, 70, 21, 32_85, 1_02_69, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], '''attention_mask''': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
       # fmt: on

       self.tokenizer_integration_test_util(
           expected_encoding=__lowercase   , model_name='''facebook/mbart-large-50'''   , revision='''d3913889c59cd5c9e456b269c376325eabad57e2'''   , )




 def        __magic_name__		( self		:							int )		->  Optional[Any]:
       if not self.test_slow_tokenizer:
             # as we don't have a slow version, we can't compare the outputs between slow and fast versions
             return

       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=(self.rust_tokenizer_class, '''hf-internal-testing/tiny-random-mbart50''', {})
       for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
             with self.subTest(F"{tokenizer.__class__.__name__} ({pretrained_name})" ):
                   SCREAMING_SNAKE_CASE__       :			Tuple													=self.rust_tokenizer_class.from_pretrained(__lowercase   , **__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Dict													=self.tokenizer_class.from_pretrained(__lowercase   , **__lowercase )

                   SCREAMING_SNAKE_CASE__       :			Optional[int]													=tempfile.mkdtemp()

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

                   # Checks it save with the same files + the tokenizer.json file for the fast one
                   self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files ) )
                   SCREAMING_SNAKE_CASE__       :			Tuple													=tuple(f for f in tokenizer_r_files if '''tokenizer.json''' not in f )
                   self.assertSequenceEqual(__lowercase   , __lowercase )

                   # Checks everything loads correctly in the same way
                   SCREAMING_SNAKE_CASE__       :			int													=tokenizer_r.from_pretrained(__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Dict													=tokenizer_p.from_pretrained(__lowercase )

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(__lowercase   , __lowercase ) )
                         # self.assertEqual(getattr(tokenizer_rp, key), getattr(tokenizer_pp, key))
                         # self.assertEqual(getattr(tokenizer_rp, key + "_id"), getattr(tokenizer_pp, key + "_id"))

                   shutil.rmtree(__lowercase )

                   # Save tokenizer rust, legacy_format=True
                   SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=tempfile.mkdtemp()

                   SCREAMING_SNAKE_CASE__       :			List[str]													=tokenizer_r.save_pretrained(__lowercase   , legacy_format=__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer_p.save_pretrained(__lowercase )

                   # Checks it save with the same files
                   self.assertSequenceEqual(__lowercase   , __lowercase )

                   # Checks everything loads correctly in the same way
                   SCREAMING_SNAKE_CASE__       :			List[Any]													=tokenizer_r.from_pretrained(__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[int]													=tokenizer_p.from_pretrained(__lowercase )

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(__lowercase   , __lowercase ) )

                   shutil.rmtree(__lowercase )

                   # Save tokenizer rust, legacy_format=False
                   SCREAMING_SNAKE_CASE__       :			Optional[int]													=tempfile.mkdtemp()

                   SCREAMING_SNAKE_CASE__       :			Any													=tokenizer_r.save_pretrained(__lowercase   , legacy_format=__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Dict													=tokenizer_p.save_pretrained(__lowercase )

                   # Checks it saved the tokenizer.json file
                   self.assertTrue(any('''tokenizer.json''' in f for f in tokenizer_r_files ) )

                   # Checks everything loads correctly in the same way
                   SCREAMING_SNAKE_CASE__       :			Tuple													=tokenizer_r.from_pretrained(__lowercase )
                   SCREAMING_SNAKE_CASE__       :			Optional[Any]													=tokenizer_p.from_pretrained(__lowercase )

                   # Check special tokens are set accordingly on Rust and Python
                   for key in tokenizer_pp.special_tokens_map:
                         self.assertTrue(hasattr(__lowercase   , __lowercase ) )

                   shutil.rmtree(__lowercase )






@require_torch
@require_sentencepiece
@require_tokenizers
class        __SCREAMING_SNAKE_CASE (     unittest.TestCase			):
 snake_case_												=							"""facebook/mbart-large-50-one-to-many-mmt"""
 snake_case_												=							[
     """ UN Chief Says There Is No Military Solution in Syria""",
     """ Secretary-General Ban Ki-moon says his response to Russia's stepped up military support for Syria is that \"there is no military solution\" to the nearly five-year conflict and more weapons will only worsen the violence and misery for millions of people.""",
 ]
 snake_case_												=							[
     """Şeful ONU declară că nu există o soluţie militară în Siria""",
     """Secretarul General Ban Ki-moon declară că răspunsul său la intensificarea sprijinului militar al Rusiei"""
     """ pentru Siria este că \"nu există o soluţie militară\" la conflictul de aproape cinci ani şi că noi arme nu vor"""
     """ face decât să înrăutăţească violenţele şi mizeria pentru milioane de oameni.""",
 ]
 snake_case_												=							[EN_CODE, 8274, 12_7873, 2_5916, 7, 8622, 2071, 438, 6_7485, 53, 18_7895, 23, 5_1712, 2]




 @classmethod
 def        __magic_name__		( cls		:							List[str] )		->  List[str]:
       SCREAMING_SNAKE_CASE__       :			MBartaaTokenizer													=MBartaaTokenizer.from_pretrained(
           cls.checkpoint_name   , src_lang='''en_XX'''   , tgt_lang='''ro_RO''' )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=1
       return cls




 def        __magic_name__		( self		:							int )		->  Optional[int]:
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ar_AR''']   , 25_00_01 )
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''en_EN''']   , 25_00_04 )
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''ro_RO''']   , 25_00_20 )
       self.assertEqual(self.tokenizer.fairseq_tokens_to_ids['''mr_IN''']   , 25_00_38 )




 def        __magic_name__		( self		:							Any )		->  Dict:
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=self.tokenizer.batch_encode_plus(self.src_text ).input_ids[0]
       self.assertListEqual(self.expected_src_tokens   , __lowercase )




 def        __magic_name__		( self		:							Tuple )		->  int:
       self.assertIn(__lowercase   , self.tokenizer.all_special_ids )
       SCREAMING_SNAKE_CASE__       :			Tuple													=[RO_CODE, 8_84, 90_19, 96, 9, 9_16, 8_67_92, 36, 1_87_43, 1_55_96, 5, 2]
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.tokenizer.decode(__lowercase   , skip_special_tokens=__lowercase )
       SCREAMING_SNAKE_CASE__       :			Dict													=self.tokenizer.decode(generated_ids[1:]   , skip_special_tokens=__lowercase )
       self.assertEqual(__lowercase   , __lowercase )
       self.assertNotIn(self.tokenizer.eos_token   , __lowercase )




 def        __magic_name__		( self		:							str )		->  int:
       SCREAMING_SNAKE_CASE__       :			Dict													=['''this is gunna be a long sentence ''' * 20]
       assert isinstance(src_text[0]   , __lowercase )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=10
       SCREAMING_SNAKE_CASE__       :			str													=self.tokenizer(__lowercase   , max_length=__lowercase   , truncation=__lowercase ).input_ids[0]
       self.assertEqual(ids[0]   , __lowercase )
       self.assertEqual(ids[-1]   , 2 )
       self.assertEqual(len(__lowercase )   , __lowercase )




 def        __magic_name__		( self		:							Optional[int] )		->  str:
       self.assertListEqual(self.tokenizer.convert_tokens_to_ids(['''<mask>''', '''ar_AR'''] )   , [25_00_53, 25_00_01] )




 def        __magic_name__		( self		:							Tuple )		->  Any:
       SCREAMING_SNAKE_CASE__       :			Dict													=tempfile.mkdtemp()
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.tokenizer.fairseq_tokens_to_ids
       self.tokenizer.save_pretrained(__lowercase )
       SCREAMING_SNAKE_CASE__       :			Optional[int]													=MBartaaTokenizer.from_pretrained(__lowercase )
       self.assertDictEqual(new_tok.fairseq_tokens_to_ids   , __lowercase )




 @require_torch
 def        __magic_name__		( self		:							Optional[int] )		->  List[Any]:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.tokenizer(self.src_text   , text_target=self.tgt_text   , padding=__lowercase   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=shift_tokens_right(batch['''labels''']   , self.tokenizer.pad_token_id )

       # fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
       assert batch.input_ids[1][0] == EN_CODE
       assert batch.input_ids[1][-1] == 2
       assert batch.labels[1][0] == RO_CODE
       assert batch.labels[1][-1] == 2
       assert batch.decoder_input_ids[1][:2].tolist() == [2, RO_CODE]




 @require_torch
 def        __magic_name__		( self		:							List[Any] )		->  int:
       SCREAMING_SNAKE_CASE__       :			Tuple													=self.tokenizer(
           self.src_text   , text_target=self.tgt_text   , padding=__lowercase   , truncation=__lowercase   , max_length=len(self.expected_src_tokens )   , return_tensors='''pt'''   , )
       SCREAMING_SNAKE_CASE__       :			Tuple													=shift_tokens_right(batch['''labels''']   , self.tokenizer.pad_token_id )

       self.assertIsInstance(__lowercase   , __lowercase )

       self.assertEqual((2, 14)   , batch.input_ids.shape )
       self.assertEqual((2, 14)   , batch.attention_mask.shape )
       SCREAMING_SNAKE_CASE__       :			Optional[Any]													=batch.input_ids.tolist()[0]
       self.assertListEqual(self.expected_src_tokens   , __lowercase )
       self.assertEqual(2   , batch.decoder_input_ids[0, 0] )  # decoder_start_token_id
       # Test that special tokens are reset
       self.assertEqual(self.tokenizer.prefix_tokens   , [EN_CODE] )
       self.assertEqual(self.tokenizer.suffix_tokens   , [self.tokenizer.eos_token_id] )




 def        __magic_name__		( self		:							List[Any] )		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__       :			Union[str, Any]													=self.tokenizer(self.src_text   , padding=__lowercase   , truncation=__lowercase   , max_length=3   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			int													=self.tokenizer(
           text_target=self.tgt_text   , padding=__lowercase   , truncation=__lowercase   , max_length=10   , return_tensors='''pt''' )
       SCREAMING_SNAKE_CASE__       :			List[Any]													=targets['''input_ids''']
       SCREAMING_SNAKE_CASE__       :			Dict													=shift_tokens_right(__lowercase   , self.tokenizer.pad_token_id )

       self.assertEqual(batch.input_ids.shape[1]   , 3 )
       self.assertEqual(batch.decoder_input_ids.shape[1]   , 10 )




 @require_torch
 def        __magic_name__		( self		:							List[str] )		->  Any:
       SCREAMING_SNAKE_CASE__       :			List[str]													=self.tokenizer._build_translation_inputs(
           '''A test'''   , return_tensors='''pt'''   , src_lang='''en_XX'''   , tgt_lang='''ar_AR''' )

       self.assertEqual(
           nested_simplify(__lowercase )   , {
               # en_XX, A, test, EOS
               '''input_ids''': [[25_00_04, 62, 30_34, 2]],
               '''attention_mask''': [[1, 1, 1, 1]],
               # ar_AR
               '''forced_bos_token_id''': 25_00_01,
           }   , )







'''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