




'''simple docstring'''



import math
from dataclasses import dataclass
from typing import List, Optional, Tuple, Union

import numpy as np
import torch

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, logging, randn_tensor
from .scheduling_utils import KarrasDiffusionSchedulers, SchedulerMixin


UpperCAmelCase_    :					List[str]					      =						logging.get_logger(__name__)  # pylint: disable=invalid-name





@dataclass
# Copied from diffusers.schedulers.scheduling_ddpm.DDPMSchedulerOutput with DDPM->EulerAncestralDiscrete
class       lowerCAmelCase				(	__lowerCAmelCase):
       __lowercase					: torch.FloatTensor
       __lowercase					: Optional[torch.FloatTensor]	    =     None







def      _UpperCamelCase	(_lowerCamelCase							:       Tuple				,		_lowerCamelCase							:       Any=0.999				,		_lowerCamelCase							:       str="cosine"				,		)->				Tuple:




     '''simple docstring'''





     if alpha_transform_type == "cosine":

          def alpha_bar_fn(_lowerCamelCase							:       Dict		):
               return math.cos((t + 0.008) / 1.008 * math.pi / 2		) ** 2

     elif alpha_transform_type == "exp":

          def alpha_bar_fn(_lowerCamelCase							:       Any		):
               return math.exp(t * -12.0		)

     else:
          raise ValueError(f'''Unsupported alpha_tranform_type: {alpha_transform_type}'''		)

     __snake_case         =					[]
     for i in range(_lowerCamelCase		):
          __snake_case         =					i / num_diffusion_timesteps
          __snake_case         =					(i + 1) / num_diffusion_timesteps
          betas.append(min(1 - alpha_bar_fn(_lowerCamelCase		) / alpha_bar_fn(_lowerCamelCase		)				,		_lowerCamelCase		)		)
     return torch.tensor(_lowerCamelCase				,		dtype=torch.floataa		)







class       lowerCAmelCase				(	__lowerCAmelCase			,				__lowerCAmelCase):
       __lowercase					: Any	    =     [e.name for e in KarrasDiffusionSchedulers]
       __lowercase					: int	    =     1


       @register_to_config
       def __init__(				self      ,					__SCREAMING_SNAKE_CASE = 1000      ,					__SCREAMING_SNAKE_CASE = 0.0_001      ,					__SCREAMING_SNAKE_CASE = 0.02      ,					__SCREAMING_SNAKE_CASE = "linear"      ,					__SCREAMING_SNAKE_CASE = None      ,					__SCREAMING_SNAKE_CASE = "epsilon"      ,					__SCREAMING_SNAKE_CASE = "linspace"      ,					__SCREAMING_SNAKE_CASE = 0      ,					) ->					Dict:



            '''simple docstring'''




            if trained_betas is not None:
                 __snake_case         =					torch.tensor(__SCREAMING_SNAKE_CASE      ,					dtype=torch.floataa					)
            elif beta_schedule == "linear":
                 __snake_case         =					torch.linspace(__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					dtype=torch.floataa					)
            elif beta_schedule == "scaled_linear":
                 # this schedule is very specific to the latent diffusion model.
                 __snake_case         =					(
                     torch.linspace(beta_start**0.5      ,					beta_end**0.5      ,					__SCREAMING_SNAKE_CASE      ,					dtype=torch.floataa					) ** 2
                 )
            elif beta_schedule == "squaredcos_cap_v2":
                 # Glide cosine schedule
                 __snake_case         =					betas_for_alpha_bar(__SCREAMING_SNAKE_CASE					)
            else:
                 raise NotImplementedError(F'''{beta_schedule} does is not implemented for {self.__class__}'''					)

            __snake_case         =					1.0 - self.betas
            __snake_case         =					torch.cumprod(self.alphas      ,					dim=0					)

            __snake_case         =					np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5					)
            __snake_case         =					np.concatenate([sigmas[::-1], [0.0]]					).astype(np.floataa					)
            __snake_case         =					torch.from_numpy(__SCREAMING_SNAKE_CASE					)

            # setable values
            __snake_case         =					None
            __snake_case         =					np.linspace(0      ,					num_train_timesteps - 1      ,					__SCREAMING_SNAKE_CASE      ,					dtype=__SCREAMING_SNAKE_CASE					)[::-1].copy()
            __snake_case         =					torch.from_numpy(__SCREAMING_SNAKE_CASE					)
            __snake_case         =					False


       @property
       def  lowerCAmelCase (				self					) ->					Tuple:



            '''simple docstring'''




            if self.config.timestep_spacing in ["linspace", "trailing"]:
                 return self.sigmas.max()

            return (self.sigmas.max() ** 2 + 1) ** 0.5


       def  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE					) ->					torch.FloatTensor:



            '''simple docstring'''




            if isinstance(__SCREAMING_SNAKE_CASE      ,					torch.Tensor					):
                 __snake_case         =					timestep.to(self.timesteps.device					)
            __snake_case         =					(self.timesteps == timestep).nonzero().item()
            __snake_case         =					self.sigmas[step_index]
            __snake_case         =					sample / ((sigma**2 + 1) ** 0.5)
            __snake_case         =					True
            return sample


       def  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE = None					) ->					Any:



            '''simple docstring'''




            __snake_case         =					num_inference_steps

            # "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
            if self.config.timestep_spacing == "linspace":
                 __snake_case         =					np.linspace(0      ,					self.config.num_train_timesteps - 1      ,					__SCREAMING_SNAKE_CASE      ,					dtype=__SCREAMING_SNAKE_CASE					)[
                     ::-1
                 ].copy()
            elif self.config.timestep_spacing == "leading":
                 __snake_case         =					self.config.num_train_timesteps // self.num_inference_steps
                 # creates integer timesteps by multiplying by ratio
                 # casting to int to avoid issues when num_inference_step is power of 3
                 __snake_case         =					(np.arange(0      ,					__SCREAMING_SNAKE_CASE					) * step_ratio).round()[::-1].copy().astype(__SCREAMING_SNAKE_CASE					)
                 timesteps += self.config.steps_offset
            elif self.config.timestep_spacing == "trailing":
                 __snake_case         =					self.config.num_train_timesteps / self.num_inference_steps
                 # creates integer timesteps by multiplying by ratio
                 # casting to int to avoid issues when num_inference_step is power of 3
                 __snake_case         =					(np.arange(self.config.num_train_timesteps      ,					0      ,					-step_ratio					)).round().copy().astype(__SCREAMING_SNAKE_CASE					)
                 timesteps -= 1
            else:
                 raise ValueError(
                     F'''{self.config.timestep_spacing} is not supported. Please make sure to choose one of \'linspace\', \'leading\' or \'trailing\'.'''					)

            __snake_case         =					np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5					)
            __snake_case         =					np.interp(__SCREAMING_SNAKE_CASE      ,					np.arange(0      ,					len(__SCREAMING_SNAKE_CASE					)					)      ,					__SCREAMING_SNAKE_CASE					)
            __snake_case         =					np.concatenate([sigmas, [0.0]]					).astype(np.floataa					)
            __snake_case         =					torch.from_numpy(__SCREAMING_SNAKE_CASE					).to(device=__SCREAMING_SNAKE_CASE					)
            if str(__SCREAMING_SNAKE_CASE					).startswith('''mps'''					):
                 # mps does not support float64
                 __snake_case         =					torch.from_numpy(__SCREAMING_SNAKE_CASE					).to(__SCREAMING_SNAKE_CASE      ,					dtype=torch.floataa					)
            else:
                 __snake_case         =					torch.from_numpy(__SCREAMING_SNAKE_CASE					).to(device=__SCREAMING_SNAKE_CASE					)


       def  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE = None      ,					__SCREAMING_SNAKE_CASE = True      ,					) ->					Union[EulerAncestralDiscreteSchedulerOutput, Tuple]:



            '''simple docstring'''




            if (
                isinstance(__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE					)
                or isinstance(__SCREAMING_SNAKE_CASE      ,					torch.IntTensor					)
                or isinstance(__SCREAMING_SNAKE_CASE      ,					torch.LongTensor					)
            ):
                 raise ValueError(
                     (
                         '''Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to'''
                         ''' `EulerDiscreteScheduler.step()` is not supported. Make sure to pass'''
                         ''' one of the `scheduler.timesteps` as a timestep.'''
                     )      ,					)

            if not self.is_scale_input_called:
                 logger.warning(
                     '''The `scale_model_input` function should be called before `step` to ensure correct denoising. '''
                     '''See `StableDiffusionPipeline` for a usage example.'''					)

            if isinstance(__SCREAMING_SNAKE_CASE      ,					torch.Tensor					):
                 __snake_case         =					timestep.to(self.timesteps.device					)

            __snake_case         =					(self.timesteps == timestep).nonzero().item()
            __snake_case         =					self.sigmas[step_index]

            # 1. compute predicted original sample (x_0) from sigma-scaled predicted noise
            if self.config.prediction_type == "epsilon":
                 __snake_case         =					sample - sigma * model_output
            elif self.config.prediction_type == "v_prediction":
                 # * c_out + input * c_skip
                 __snake_case         =					model_output * (-sigma / (sigma**2 + 1) ** 0.5) + (sample / (sigma**2 + 1))
            elif self.config.prediction_type == "sample":
                 raise NotImplementedError('''prediction_type not implemented yet: sample'''					)
            else:
                 raise ValueError(
                     F'''prediction_type given as {self.config.prediction_type} must be one of `epsilon`, or `v_prediction`'''					)

            __snake_case         =					self.sigmas[step_index]
            __snake_case         =					self.sigmas[step_index + 1]
            __snake_case         =					(sigma_to**2 * (sigma_from**2 - sigma_to**2) / sigma_from**2) ** 0.5
            __snake_case         =					(sigma_to**2 - sigma_up**2) ** 0.5

            # 2. Convert to an ODE derivative
            __snake_case         =					(sample - pred_original_sample) / sigma

            __snake_case         =					sigma_down - sigma

            __snake_case         =					sample + derivative * dt

            __snake_case         =					model_output.device
            __snake_case         =					randn_tensor(model_output.shape      ,					dtype=model_output.dtype      ,					device=__SCREAMING_SNAKE_CASE      ,					generator=__SCREAMING_SNAKE_CASE					)

            __snake_case         =					prev_sample + noise * sigma_up

            if not return_dict:
                 return (prev_sample,)

            return EulerAncestralDiscreteSchedulerOutput(
                prev_sample=__SCREAMING_SNAKE_CASE      ,					pred_original_sample=__SCREAMING_SNAKE_CASE					)


       def  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE      ,					) ->					torch.FloatTensor:



            '''simple docstring'''




            __snake_case         =					self.sigmas.to(device=original_samples.device      ,					dtype=original_samples.dtype					)
            if original_samples.device.type == "mps" and torch.is_floating_point(__SCREAMING_SNAKE_CASE					):
                 # mps does not support float64
                 __snake_case         =					self.timesteps.to(original_samples.device      ,					dtype=torch.floataa					)
                 __snake_case         =					timesteps.to(original_samples.device      ,					dtype=torch.floataa					)
            else:
                 __snake_case         =					self.timesteps.to(original_samples.device					)
                 __snake_case         =					timesteps.to(original_samples.device					)

            __snake_case         =					[(schedule_timesteps == t).nonzero().item() for t in timesteps]

            __snake_case         =					sigmas[step_indices].flatten()
            while len(sigma.shape					) < len(original_samples.shape					):
                 __snake_case         =					sigma.unsqueeze(-1					)

            __snake_case         =					original_samples + noise * sigma
            return noisy_samples




       def __len__(				self					) ->					List[Any]:



            '''simple docstring'''




            return self.config.num_train_timesteps












'''simple docstring'''



import unittest

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


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import CLIPImageProcessor





class       lowerCAmelCase				(	unittest.TestCase):


       def __init__(				self      ,					__SCREAMING_SNAKE_CASE      ,					__SCREAMING_SNAKE_CASE=7      ,					__SCREAMING_SNAKE_CASE=3      ,					__SCREAMING_SNAKE_CASE=18      ,					__SCREAMING_SNAKE_CASE=30      ,					__SCREAMING_SNAKE_CASE=400      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=None      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=None      ,					__SCREAMING_SNAKE_CASE=True      ,					__SCREAMING_SNAKE_CASE=[0.48_145_466, 0.4_578_275, 0.40_821_073]      ,					__SCREAMING_SNAKE_CASE=[0.26_862_954, 0.26_130_258, 0.27_577_711]      ,					__SCREAMING_SNAKE_CASE=True      ,					) ->					Optional[Any]:



            '''simple docstring'''




            __snake_case         =					size if size is not None else {'''shortest_edge''': 20}
            __snake_case         =					crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
            __snake_case         =					parent
            __snake_case         =					batch_size
            __snake_case         =					num_channels
            __snake_case         =					image_size
            __snake_case         =					min_resolution
            __snake_case         =					max_resolution
            __snake_case         =					do_resize
            __snake_case         =					size
            __snake_case         =					do_center_crop
            __snake_case         =					crop_size
            __snake_case         =					do_normalize
            __snake_case         =					image_mean
            __snake_case         =					image_std
            __snake_case         =					do_convert_rgb


       def  lowerCAmelCase (				self					) ->					Optional[int]:



            '''simple docstring'''




            return {
                "do_resize": self.do_resize,
                "size": self.size,
                "do_center_crop": self.do_center_crop,
                "crop_size": self.crop_size,
                "do_normalize": self.do_normalize,
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_convert_rgb": self.do_convert_rgb,
            }




       def  lowerCAmelCase (				self      ,					__SCREAMING_SNAKE_CASE=False      ,					__SCREAMING_SNAKE_CASE=False      ,					__SCREAMING_SNAKE_CASE=False					) ->					str:



            '''simple docstring'''




            assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

            if equal_resolution:
                 __snake_case         =					[]
                 for i in range(self.batch_size					):
                      image_inputs.append(
                          np.random.randint(
                              255      ,					size=(self.num_channels, self.max_resolution, self.max_resolution)      ,					dtype=np.uinta					)					)
            else:
                 __snake_case         =					[]
                 for i in range(self.batch_size					):
                      __snake_case   ,      __snake_case         =					np.random.choice(np.arange(self.min_resolution      ,					self.max_resolution					)      ,					2					)
                      image_inputs.append(np.random.randint(255      ,					size=(self.num_channels, width, height)      ,					dtype=np.uinta					)					)

            if not numpify and not torchify:
                 # PIL expects the channel dimension as last dimension
                 __snake_case         =					[Image.fromarray(np.moveaxis(__SCREAMING_SNAKE_CASE      ,					0      ,					-1					)					) for x in image_inputs]

            if torchify:
                 __snake_case         =					[torch.from_numpy(__SCREAMING_SNAKE_CASE					) for x in image_inputs]

            return image_inputs





@require_torch
@require_vision
class       lowerCAmelCase				(	__lowerCAmelCase			,				unittest.TestCase):
       __lowercase					: Dict	    =     CLIPImageProcessor if is_vision_available() else None


       def  lowerCAmelCase (				self					) ->					int:



            '''simple docstring'''




            __snake_case         =					CLIPImageProcessingTester(self					)


       @property
       def  lowerCAmelCase (				self					) ->					List[str]:



            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()


       def  lowerCAmelCase (				self					) ->					Optional[Any]:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_resize'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''size'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_center_crop'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''center_crop'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_normalize'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''image_mean'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''image_std'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_convert_rgb'''					)					)


       def  lowerCAmelCase (				self					) ->					Optional[int]:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class.from_dict(self.image_processor_dict					)
            self.assertEqual(image_processor.size      ,					{'''shortest_edge''': 20}					)
            self.assertEqual(image_processor.crop_size      ,					{'''height''': 18, '''width''': 18}					)

            __snake_case         =					self.image_processing_class.from_dict(self.image_processor_dict      ,					size=42      ,					crop_size=84					)
            self.assertEqual(image_processor.size      ,					{'''shortest_edge''': 42}					)
            self.assertEqual(image_processor.crop_size      ,					{'''height''': 84, '''width''': 84}					)


       def  lowerCAmelCase (				self					) ->					Dict:



            '''simple docstring'''




            pass


       def  lowerCAmelCase (				self					) ->					str:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            # create random PIL images
            __snake_case         =					self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE					)
            for image in image_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE      ,					Image.Image					)

            # Test not batched input
            __snake_case         =					image_processing(image_inputs[0]      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)

            # Test batched
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)


       def  lowerCAmelCase (				self					) ->					Dict:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            # create random numpy tensors
            __snake_case         =					self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE      ,					numpify=__SCREAMING_SNAKE_CASE					)
            for image in image_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE      ,					np.ndarray					)

            # Test not batched input
            __snake_case         =					image_processing(image_inputs[0]      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)

            # Test batched
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)




       def  lowerCAmelCase (				self					) ->					int:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            # create random PyTorch tensors
            __snake_case         =					self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE      ,					torchify=__SCREAMING_SNAKE_CASE					)
            for image in image_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE      ,					torch.Tensor					)

            # Test not batched input
            __snake_case         =					image_processing(image_inputs[0]      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)

            # Test batched
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)





@require_torch
@require_vision
class       lowerCAmelCase				(	__lowerCAmelCase			,				unittest.TestCase):
       __lowercase					: Dict	    =     CLIPImageProcessor if is_vision_available() else None


       def  lowerCAmelCase (				self					) ->					Any:



            '''simple docstring'''




            __snake_case         =					CLIPImageProcessingTester(self      ,					num_channels=4					)
            __snake_case         =					3


       @property
       def  lowerCAmelCase (				self					) ->					str:



            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()


       def  lowerCAmelCase (				self					) ->					List[Any]:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_resize'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''size'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_center_crop'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''center_crop'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_normalize'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''image_mean'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''image_std'''					)					)
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE      ,					'''do_convert_rgb'''					)					)


       def  lowerCAmelCase (				self					) ->					Tuple:



            '''simple docstring'''




            pass




       def  lowerCAmelCase (				self					) ->					Optional[int]:



            '''simple docstring'''




            __snake_case         =					self.image_processing_class(**self.image_processor_dict					)
            # create random PIL images
            __snake_case         =					self.image_processor_tester.prepare_inputs(equal_resolution=__SCREAMING_SNAKE_CASE					)
            for image in image_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE      ,					Image.Image					)

            # Test not batched input
            __snake_case         =					image_processing(image_inputs[0]      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    1,
                    self.expected_encoded_image_num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)

            # Test batched
            __snake_case         =					image_processing(__SCREAMING_SNAKE_CASE      ,					return_tensors='''pt'''					).pixel_values
            self.assertEqual(
                encoded_images.shape      ,					(
                    self.image_processor_tester.batch_size,
                    self.expected_encoded_image_num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )      ,					)






