


"""simple docstring"""





snake_case__						:   str			 = [
    999,
    800,
    799,
    600,
    599,
    500,
    400,
    399,
    377,
    355,
    333,
    311,
    288,
    266,
    244,
    222,
    200,
    199,
    177,
    155,
    133,
    111,
    88,
    66,
    44,
    22,
    0,
]

snake_case__						:   Optional[Any]			 = [
    999,
    976,
    952,
    928,
    905,
    882,
    858,
    857,
    810,
    762,
    715,
    714,
    572,
    429,
    428,
    286,
    285,
    238,
    190,
    143,
    142,
    118,
    95,
    71,
    47,
    24,
    0,
]

snake_case__						:   Any			 = [
    999,
    988,
    977,
    966,
    955,
    944,
    933,
    922,
    911,
    900,
    899,
    879,
    859,
    840,
    820,
    800,
    799,
    766,
    733,
    700,
    699,
    650,
    600,
    599,
    500,
    499,
    400,
    399,
    350,
    300,
    299,
    266,
    233,
    200,
    199,
    179,
    159,
    140,
    120,
    100,
    99,
    88,
    77,
    66,
    55,
    44,
    33,
    22,
    11,
    0,
]

snake_case__						:   Optional[Any]			 = [
    999,
    995,
    992,
    989,
    985,
    981,
    978,
    975,
    971,
    967,
    964,
    961,
    957,
    956,
    951,
    947,
    942,
    937,
    933,
    928,
    923,
    919,
    914,
    913,
    908,
    903,
    897,
    892,
    887,
    881,
    876,
    871,
    870,
    864,
    858,
    852,
    846,
    840,
    834,
    828,
    827,
    820,
    813,
    806,
    799,
    792,
    785,
    784,
    777,
    770,
    763,
    756,
    749,
    742,
    741,
    733,
    724,
    716,
    707,
    699,
    698,
    688,
    677,
    666,
    656,
    655,
    645,
    634,
    623,
    613,
    612,
    598,
    584,
    570,
    569,
    555,
    541,
    527,
    526,
    505,
    484,
    483,
    462,
    440,
    439,
    396,
    395,
    352,
    351,
    308,
    307,
    264,
    263,
    220,
    219,
    176,
    132,
    88,
    44,
    0,
]

snake_case__						:   int			 = [
    999,
    997,
    995,
    992,
    990,
    988,
    986,
    984,
    981,
    979,
    977,
    975,
    972,
    970,
    968,
    966,
    964,
    961,
    959,
    957,
    956,
    954,
    951,
    949,
    946,
    944,
    941,
    939,
    936,
    934,
    931,
    929,
    926,
    924,
    921,
    919,
    916,
    914,
    913,
    910,
    907,
    905,
    902,
    899,
    896,
    893,
    891,
    888,
    885,
    882,
    879,
    877,
    874,
    871,
    870,
    867,
    864,
    861,
    858,
    855,
    852,
    849,
    846,
    843,
    840,
    837,
    834,
    831,
    828,
    827,
    824,
    821,
    817,
    814,
    811,
    808,
    804,
    801,
    798,
    795,
    791,
    788,
    785,
    784,
    780,
    777,
    774,
    770,
    766,
    763,
    760,
    756,
    752,
    749,
    746,
    742,
    741,
    737,
    733,
    730,
    726,
    722,
    718,
    714,
    710,
    707,
    703,
    699,
    698,
    694,
    690,
    685,
    681,
    677,
    673,
    669,
    664,
    660,
    656,
    655,
    650,
    646,
    641,
    636,
    632,
    627,
    622,
    618,
    613,
    612,
    607,
    602,
    596,
    591,
    586,
    580,
    575,
    570,
    569,
    563,
    557,
    551,
    545,
    539,
    533,
    527,
    526,
    519,
    512,
    505,
    498,
    491,
    484,
    483,
    474,
    466,
    457,
    449,
    440,
    439,
    428,
    418,
    407,
    396,
    395,
    381,
    366,
    352,
    351,
    330,
    308,
    307,
    286,
    264,
    263,
    242,
    220,
    219,
    176,
    175,
    132,
    131,
    88,
    44,
    0,
]

snake_case__						:   Union[str, Any]			 = [
    999,
    991,
    982,
    974,
    966,
    958,
    950,
    941,
    933,
    925,
    916,
    908,
    900,
    899,
    874,
    850,
    825,
    800,
    799,
    700,
    600,
    500,
    400,
    300,
    200,
    100,
    0,
]

snake_case__						:   List[Any]			 = [
    999,
    992,
    985,
    978,
    971,
    964,
    957,
    949,
    942,
    935,
    928,
    921,
    914,
    907,
    900,
    899,
    879,
    859,
    840,
    820,
    800,
    799,
    766,
    733,
    700,
    699,
    650,
    600,
    599,
    500,
    499,
    400,
    399,
    300,
    299,
    200,
    199,
    100,
    99,
    0,
]

snake_case__						:   Optional[int]			 = [
    999,
    996,
    992,
    989,
    985,
    982,
    979,
    975,
    972,
    968,
    965,
    961,
    958,
    955,
    951,
    948,
    944,
    941,
    938,
    934,
    931,
    927,
    924,
    920,
    917,
    914,
    910,
    907,
    903,
    900,
    899,
    891,
    884,
    876,
    869,
    861,
    853,
    846,
    838,
    830,
    823,
    815,
    808,
    800,
    799,
    788,
    777,
    766,
    755,
    744,
    733,
    722,
    711,
    700,
    699,
    688,
    677,
    666,
    655,
    644,
    633,
    622,
    611,
    600,
    599,
    585,
    571,
    557,
    542,
    528,
    514,
    500,
    499,
    485,
    471,
    457,
    442,
    428,
    414,
    400,
    399,
    379,
    359,
    340,
    320,
    300,
    299,
    279,
    259,
    240,
    220,
    200,
    199,
    166,
    133,
    100,
    99,
    66,
    33,
    0,
]






"""simple docstring"""





import unittest
from typing import Dict, List, Optional, Union

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 BridgeTowerImageProcessor



class 						snake_case_(				unittest.TestCase	):






     def __init__(		self     :    Union[str, Any]    , UpperCamelCase_     :    Optional[Any]    , UpperCamelCase_     :    bool = True    , UpperCamelCase_     :    Dict[str, int] = None    , UpperCamelCase_     :    int = 3_2    , UpperCamelCase_     :    bool = True    , UpperCamelCase_     :    Union[int, float] = 1 / 2_5_5    , UpperCamelCase_     :    bool = True    , UpperCamelCase_     :    bool = True    , UpperCamelCase_     :    Optional[Union[float, List[float]]] = [0.48_145_466, 0.4_578_275, 0.40_821_073]    , UpperCamelCase_     :    Optional[Union[float, List[float]]] = [0.26_862_954, 0.26_130_258, 0.27_577_711]    , UpperCamelCase_     :    bool = True    , UpperCamelCase_     :    Optional[int]=7    , UpperCamelCase_     :    int=3_0    , UpperCamelCase_     :    str=4_0_0    , UpperCamelCase_     :    List[Any]=3    , ):
           lowerCAmelCase    :		Union[str, Any]				=      parent
           lowerCAmelCase    :		Union[str, Any]				=      do_resize
           lowerCAmelCase    :		List[str]				=      size if size is not None else {'''shortest_edge''': 2_8_8}
           lowerCAmelCase    :		int				=      size_divisor
           lowerCAmelCase    :		List[str]				=      do_rescale
           lowerCAmelCase    :		Optional[Any]				=      rescale_factor
           lowerCAmelCase    :		Dict				=      do_normalize
           lowerCAmelCase    :		Any				=      do_center_crop
           lowerCAmelCase    :		Union[str, Any]				=      image_mean
           lowerCAmelCase    :		Optional[Any]				=      image_std
           lowerCAmelCase    :		Union[str, Any]				=      do_pad
           lowerCAmelCase    :		Union[str, Any]				=      batch_size
           lowerCAmelCase    :		Any				=      num_channels
           lowerCAmelCase    :		Union[str, Any]				=      min_resolution
           lowerCAmelCase    :		int				=      max_resolution






     def    lowerCamelCase__   (		self     :    Dict ):
           return {
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_normalize": self.do_normalize,
               "do_resize": self.do_resize,
               "size": self.size,
               "size_divisor": self.size_divisor,
           }






     def    lowerCamelCase__   (		self     :    Any    , UpperCamelCase_     :    int    , UpperCamelCase_     :    List[str]=False ):
           if not batched:
                 lowerCAmelCase    :		Dict				=      self.size['''shortest_edge''']
                 lowerCAmelCase    :		Dict				=      image_inputs[0]
                 if isinstance(UpperCamelCase_    , Image.Image ):
                       lowerCAmelCase,					lowerCAmelCase    :		Optional[int]				=      image.size
                 else:
                       lowerCAmelCase,					lowerCAmelCase    :		List[Any]				=      image.shape[1], image.shape[2]
                 lowerCAmelCase    :		Union[str, Any]				=      size / min(UpperCamelCase_    , UpperCamelCase_ )
                 if h < w:
                       lowerCAmelCase,					lowerCAmelCase    :		Dict				=      size, scale * w
                 else:
                       lowerCAmelCase,					lowerCAmelCase    :		Optional[int]				=      scale * h, size

                 lowerCAmelCase    :		List[Any]				=      int((1_3_3_3 / 8_0_0) * size )
                 if max(UpperCamelCase_    , UpperCamelCase_ ) > max_size:
                       lowerCAmelCase    :		int				=      max_size / max(UpperCamelCase_    , UpperCamelCase_ )
                       lowerCAmelCase    :		str				=      newh * scale
                       lowerCAmelCase    :		Tuple				=      neww * scale

                 lowerCAmelCase,					lowerCAmelCase    :		List[str]				=      int(newh + 0.5 ), int(neww + 0.5 )
                 lowerCAmelCase,					lowerCAmelCase    :		Tuple				=      (
                     newh // self.size_divisor * self.size_divisor,
                     neww // self.size_divisor * self.size_divisor,
                 )

           else:
                 lowerCAmelCase    :		Optional[int]				=      []
                 for image in image_inputs:
                       lowerCAmelCase,					lowerCAmelCase    :		List[str]				=      self.get_expected_values([image] )
                       expected_values.append((expected_height, expected_width) )
                 lowerCAmelCase    :		Union[str, Any]				=      max(UpperCamelCase_    , key=lambda UpperCamelCase_ : item[0] )[0]
                 lowerCAmelCase    :		Union[str, Any]				=      max(UpperCamelCase_    , key=lambda UpperCamelCase_ : item[1] )[1]

           return expected_height, expected_width



@require_torch
@require_vision
class 						snake_case_(				a__							,    unittest.TestCase	):
     __UpperCamelCase     =    BridgeTowerImageProcessor if is_vision_available() else None






     def    lowerCamelCase__   (		self     :    Optional[int] ):
           lowerCAmelCase    :		Optional[int]				=      BridgeTowerImageProcessingTester(self )






     @property
     def    lowerCamelCase__   (		self     :    List[str] ):
           return self.image_processor_tester.prepare_image_processor_dict()






     def    lowerCamelCase__   (		self     :    List[str] ):
           lowerCAmelCase    :		Optional[Any]				=      self.image_processing_class(**self.image_processor_dict )
           self.assertTrue(hasattr(UpperCamelCase_    , '''image_mean''' ) )
           self.assertTrue(hasattr(UpperCamelCase_    , '''image_std''' ) )
           self.assertTrue(hasattr(UpperCamelCase_    , '''do_normalize''' ) )
           self.assertTrue(hasattr(UpperCamelCase_    , '''do_resize''' ) )
           self.assertTrue(hasattr(UpperCamelCase_    , '''size''' ) )
           self.assertTrue(hasattr(UpperCamelCase_    , '''size_divisor''' ) )






     def    lowerCamelCase__   (		self     :    int ):
           pass






     def    lowerCamelCase__   (		self     :    Optional[Any] ):
           # Initialize image processor
           lowerCAmelCase    :		str				=      self.image_processing_class(**self.image_processor_dict )
           # create random PIL images
           lowerCAmelCase    :		Optional[int]				=      prepare_image_inputs(self.image_processor_tester    , equal_resolution=UpperCamelCase_ )
           for image in image_inputs:
                 self.assertIsInstance(UpperCamelCase_    , Image.Image )

           # Test not batched input
           lowerCAmelCase    :		Optional[int]				=      image_processing(image_inputs[0]    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		List[Any]				=      self.image_processor_tester.get_expected_values(UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (1, self.image_processor_tester.num_channels, expected_height, expected_width)    , )

           # Test batched
           lowerCAmelCase    :		Dict				=      image_processing(UpperCamelCase_    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		int				=      self.image_processor_tester.get_expected_values(UpperCamelCase_    , batched=UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   expected_height,
                   expected_width,
               )    , )






     def    lowerCamelCase__   (		self     :    Optional[Any] ):
           # Initialize image processor
           lowerCAmelCase    :		Tuple				=      self.image_processing_class(**self.image_processor_dict )
           # create random numpy tensors
           lowerCAmelCase    :		List[Any]				=      prepare_image_inputs(self.image_processor_tester    , equal_resolution=UpperCamelCase_    , numpify=UpperCamelCase_ )
           for image in image_inputs:
                 self.assertIsInstance(UpperCamelCase_    , np.ndarray )

           # Test not batched input
           lowerCAmelCase    :		Any				=      image_processing(image_inputs[0]    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		Optional[Any]				=      self.image_processor_tester.get_expected_values(UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (1, self.image_processor_tester.num_channels, expected_height, expected_width)    , )

           # Test batched
           lowerCAmelCase    :		Tuple				=      image_processing(UpperCamelCase_    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		str				=      self.image_processor_tester.get_expected_values(UpperCamelCase_    , batched=UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   expected_height,
                   expected_width,
               )    , )






     def    lowerCamelCase__   (		self     :    Optional[int] ):
           # Initialize image processor
           lowerCAmelCase    :		Union[str, Any]				=      self.image_processing_class(**self.image_processor_dict )
           # create random PyTorch tensors
           lowerCAmelCase    :		List[str]				=      prepare_image_inputs(self.image_processor_tester    , equal_resolution=UpperCamelCase_    , torchify=UpperCamelCase_ )
           for image in image_inputs:
                 self.assertIsInstance(UpperCamelCase_    , torch.Tensor )

           # Test not batched input
           lowerCAmelCase    :		Any				=      image_processing(image_inputs[0]    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		Tuple				=      self.image_processor_tester.get_expected_values(UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (1, self.image_processor_tester.num_channels, expected_height, expected_width)    , )

           # Test batched
           lowerCAmelCase    :		str				=      image_processing(UpperCamelCase_    , return_tensors='''pt''' ).pixel_values

           lowerCAmelCase,					lowerCAmelCase    :		str				=      self.image_processor_tester.get_expected_values(UpperCamelCase_    , batched=UpperCamelCase_ )
           self.assertEqual(
               encoded_images.shape    , (
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   expected_height,
                   expected_width,
               )    , )


