from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, 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_vision_available, logging


if is_vision_available():
      import PIL


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






class 		_lowerCamelCase		(   UpperCamelCase_    ):
    __a  =      ["pixel_values"]
    def __init__(  self , lowerCAmelCase = True , lowerCAmelCase = None , lowerCAmelCase = PIL.Image.BICUBIC , lowerCAmelCase = True , lowerCAmelCase = None , lowerCAmelCase = 1 / 255 , lowerCAmelCase = True , lowerCAmelCase = True , lowerCAmelCase = None , lowerCAmelCase = None , **lowerCAmelCase , )       ->					int:
     super().__init__(**UpperCamelCase__   )
     SCREAMING_SNAKE_CASE__:   List[str]=      size if size is not None else {'''height''': 256, '''width''': 256}
     SCREAMING_SNAKE_CASE__:   Dict=      get_size_dict(UpperCamelCase__   )
     SCREAMING_SNAKE_CASE__:   List[str]=      crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
     SCREAMING_SNAKE_CASE__:   Optional[int]=      get_size_dict(UpperCamelCase__ , param_name='''crop_size'''   )

     SCREAMING_SNAKE_CASE__:   str=      do_resize
     SCREAMING_SNAKE_CASE__:   int=      size
     SCREAMING_SNAKE_CASE__:   Dict=      resample
     SCREAMING_SNAKE_CASE__:   str=      do_center_crop
     SCREAMING_SNAKE_CASE__:   Dict=      crop_size
     SCREAMING_SNAKE_CASE__:   Optional[Any]=      do_rescale
     SCREAMING_SNAKE_CASE__:   List[str]=      rescale_factor
     SCREAMING_SNAKE_CASE__:   Tuple=      do_normalize
     SCREAMING_SNAKE_CASE__:   List[Any]=      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
     SCREAMING_SNAKE_CASE__:   int=      image_std if image_std is not None else IMAGENET_STANDARD_STD
    def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase = PIL.Image.BICUBIC , lowerCAmelCase = None , **lowerCAmelCase , )       ->					Union[str, Any]:
     SCREAMING_SNAKE_CASE__:   List[str]=      get_size_dict(UpperCamelCase__   )
     if "height" not in size or "width" not in size:
      raise ValueError(f'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'   )
     return resize(
         UpperCamelCase__ , size=(size['''height'''], size['''width''']) , resample=UpperCamelCase__ , data_format=UpperCamelCase__ , **UpperCamelCase__   )
    def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase = None , **lowerCAmelCase , )       ->					List[Any]:
     SCREAMING_SNAKE_CASE__:   Optional[Any]=      get_size_dict(UpperCamelCase__   )
     if "height" not in size or "width" not in size:
      raise ValueError(f'The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'   )
     return center_crop(UpperCamelCase__ , size=(size['''height'''], size['''width''']) , data_format=UpperCamelCase__ , **UpperCamelCase__   )
    def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase = None , **lowerCAmelCase , )       ->					Optional[Any]:
     return rescale(UpperCamelCase__ , scale=UpperCamelCase__ , data_format=UpperCamelCase__ , **UpperCamelCase__   )
    def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase , lowerCAmelCase = None , **lowerCAmelCase , )       ->					Any:
     return normalize(UpperCamelCase__ , mean=UpperCamelCase__ , std=UpperCamelCase__ , data_format=UpperCamelCase__ , **UpperCamelCase__   )



    def 						UpperCamelCase_				(  self , lowerCAmelCase , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase=None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = ChannelDimension.FIRST , **lowerCAmelCase , )       ->					int:
     SCREAMING_SNAKE_CASE__:   Tuple=      do_resize if do_resize is not None else self.do_resize
     SCREAMING_SNAKE_CASE__:   int=      resample if resample is not None else self.resample
     SCREAMING_SNAKE_CASE__:   Tuple=      do_center_crop if do_center_crop is not None else self.do_center_crop
     SCREAMING_SNAKE_CASE__:   str=      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__:   int=      do_normalize if do_normalize is not None else self.do_normalize
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      image_mean if image_mean is not None else self.image_mean
     SCREAMING_SNAKE_CASE__:   List[Any]=      image_std if image_std is not None else self.image_std

     SCREAMING_SNAKE_CASE__:   Any=      size if size is not None else self.size
     SCREAMING_SNAKE_CASE__:   Tuple=      get_size_dict(UpperCamelCase__   )
     SCREAMING_SNAKE_CASE__:   Optional[Any]=      crop_size if crop_size is not None else self.crop_size
     SCREAMING_SNAKE_CASE__:   Dict=      get_size_dict(UpperCamelCase__ , param_name='''crop_size'''   )

     SCREAMING_SNAKE_CASE__:   List[str]=      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_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(UpperCamelCase__   ) for image in images]

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

     if do_center_crop:
      SCREAMING_SNAKE_CASE__:   Optional[int]=      [self.center_crop(image=UpperCamelCase__ , size=UpperCamelCase__   ) for image in images]

     if do_rescale:
      SCREAMING_SNAKE_CASE__:   int=      [self.rescale(image=UpperCamelCase__ , scale=UpperCamelCase__   ) for image in images]

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

     SCREAMING_SNAKE_CASE__:   Optional[Any]=      [to_channel_dimension_format(UpperCamelCase__ , UpperCamelCase__   ) for image in images]

     SCREAMING_SNAKE_CASE__:   int=      {'''pixel_values''': images}
     return BatchFeature(data=UpperCamelCase__ , tensor_type=UpperCamelCase__   )


# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowercase_     :   List[str] 				=				abspath(join(dirname(dirname(__file__)), 'src'))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='ignore', category=FutureWarning)







def 			A__      (	snake_case_ :		Optional[int]      ):
 from diffusers.utils.testing_utils import pytest_addoption_shared

 pytest_addoption_shared(snake_case_      )







def 			A__      (	snake_case_ :		Optional[int]      ):
 from diffusers.utils.testing_utils import pytest_terminal_summary_main

 SCREAMING_SNAKE_CASE__:   Optional[int]=      terminalreporter.config.getoption('''--make-reports'''      )
 if make_reports:
  pytest_terminal_summary_main(snake_case_       ,				id=snake_case_      )

