'''simple docstring'''






import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import require_torch_gpu




class    a (       unittest.TestCase				):



  """simple docstring"""







  def    lowercase_  (							self					):

    '''simple docstring'''







    super().tearDown()
    gc.collect()
    torch.cuda.empty_cache()







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= 1
    __UpperCAmelCase:					Any		= 3
    __UpperCAmelCase:					Optional[int]		= (32, 32)

    __UpperCAmelCase:					Optional[int]		= floats_tensor((batch_size, num_channels) + sizes   ,    rng=random.Random(0					)					).to(snake_case_					)
    return image







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    torch.manual_seed(0					)
    __UpperCAmelCase:					Union[str, Any]		= UNetaDConditionModel(
        block_out_channels=(32, 64)   ,    layers_per_block=2   ,    sample_size=32   ,    in_channels=4   ,    out_channels=4   ,    down_block_types=("""DownBlock2D""", """CrossAttnDownBlock2D""")   ,    up_block_types=("""CrossAttnUpBlock2D""", """UpBlock2D""")   ,    cross_attention_dim=32   ,    )
    return model







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    torch.manual_seed(0					)
    __UpperCAmelCase:					Optional[int]		= AutoencoderKL(
        block_out_channels=[32, 64]   ,    in_channels=3   ,    out_channels=3   ,    down_block_types=["""DownEncoderBlock2D""", """DownEncoderBlock2D"""]   ,    up_block_types=["""UpDecoderBlock2D""", """UpDecoderBlock2D"""]   ,    latent_channels=4   ,    )
    return model







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    torch.manual_seed(0					)
    __UpperCAmelCase:					List[str]		= CLIPTextConfig(
        bos_token_id=0   ,    eos_token_id=2   ,    hidden_size=32   ,    intermediate_size=37   ,    layer_norm_eps=1e-0_5   ,    num_attention_heads=4   ,    num_hidden_layers=5   ,    pad_token_id=1   ,    vocab_size=1000   ,    )
    return CLIPTextModel(snake_case_					)







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    def extract(*snake_case_   ,    **snake_case_					):




      class    a :



        """simple docstring"""







        def __init__(							self					):

          '''simple docstring'''







          __UpperCAmelCase:					Optional[int]		= torch.ones([0]					)







        def    lowercase_  (							self   ,    snake_case_					):

          '''simple docstring'''







          self.pixel_values.to(snake_case_					)
          return self



      return Out()

    return extract







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= """cpu"""  # ensure determinism for the device-dependent torch.Generator
    __UpperCAmelCase:					Tuple		= self.dummy_cond_unet
    __UpperCAmelCase:					Union[str, Any]		= DDIMScheduler(
        beta_start=0.0_0_0_8_5   ,    beta_end=0.0_1_2   ,    beta_schedule="""scaled_linear"""   ,    clip_sample=snake_case_   ,    set_alpha_to_one=snake_case_   ,    )

    __UpperCAmelCase:					Dict		= self.dummy_vae
    __UpperCAmelCase:					List[Any]		= self.dummy_text_encoder
    __UpperCAmelCase:					List[Any]		= CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""					)

    # make sure here that pndm scheduler skips prk
    __UpperCAmelCase:					Tuple		= StableDiffusionPipeline(
        unet=snake_case_   ,    scheduler=snake_case_   ,    vae=snake_case_   ,    text_encoder=snake_case_   ,    tokenizer=snake_case_   ,    safety_checker=snake_case_   ,    feature_extractor=self.dummy_extractor   ,    )
    __UpperCAmelCase:					Tuple		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					Tuple		= """A painting of a squirrel eating a burger"""

    __UpperCAmelCase:					List[str]		= torch.Generator(device=snake_case_					).manual_seed(0					)
    __UpperCAmelCase:					Union[str, Any]		= sd_pipe([prompt]   ,    generator=snake_case_   ,    guidance_scale=6.0   ,    num_inference_steps=2   ,    output_type="""np"""					)
    __UpperCAmelCase:					List[Any]		= output.images

    __UpperCAmelCase:					Union[str, Any]		= torch.Generator(device=snake_case_					).manual_seed(0					)
    __UpperCAmelCase:					Union[str, Any]		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=6.0   ,    num_inference_steps=2   ,    output_type="""np"""   ,    return_dict=snake_case_   ,    )[0]

    __UpperCAmelCase:					Optional[int]		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					Optional[int]		= image_from_tuple[0, -3:, -3:, -1]

    assert image.shape == (1, 64, 64, 3)
    __UpperCAmelCase:					str		= np.array([0.5_7_5_6, 0.6_1_1_8, 0.5_0_0_5, 0.5_0_4_1, 0.5_4_7_1, 0.4_7_2_6, 0.4_9_7_6, 0.4_8_6_5, 0.4_8_6_4]					)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2
    assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 1e-2







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					str		= """cpu"""  # ensure determinism for the device-dependent torch.Generator
    __UpperCAmelCase:					Any		= self.dummy_cond_unet
    __UpperCAmelCase:					int		= PNDMScheduler(skip_prk_steps=snake_case_					)
    __UpperCAmelCase:					Tuple		= self.dummy_vae
    __UpperCAmelCase:					Optional[Any]		= self.dummy_text_encoder
    __UpperCAmelCase:					int		= CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""					)

    # make sure here that pndm scheduler skips prk
    __UpperCAmelCase:					int		= StableDiffusionPipeline(
        unet=snake_case_   ,    scheduler=snake_case_   ,    vae=snake_case_   ,    text_encoder=snake_case_   ,    tokenizer=snake_case_   ,    safety_checker=snake_case_   ,    feature_extractor=self.dummy_extractor   ,    )
    __UpperCAmelCase:					Any		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					Dict		= """A painting of a squirrel eating a burger"""
    __UpperCAmelCase:					Optional[Any]		= torch.Generator(device=snake_case_					).manual_seed(0					)
    __UpperCAmelCase:					int		= sd_pipe([prompt]   ,    generator=snake_case_   ,    guidance_scale=6.0   ,    num_inference_steps=2   ,    output_type="""np"""					)

    __UpperCAmelCase:					int		= output.images

    __UpperCAmelCase:					Union[str, Any]		= torch.Generator(device=snake_case_					).manual_seed(0					)
    __UpperCAmelCase:					Any		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=6.0   ,    num_inference_steps=2   ,    output_type="""np"""   ,    return_dict=snake_case_   ,    )[0]

    __UpperCAmelCase:					List[str]		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					List[Any]		= image_from_tuple[0, -3:, -3:, -1]

    assert image.shape == (1, 64, 64, 3)
    __UpperCAmelCase:					Optional[Any]		= np.array([0.5_1_2_5, 0.5_7_1_6, 0.4_8_2_8, 0.5_0_6_0, 0.5_6_5_0, 0.4_7_6_8, 0.5_1_8_5, 0.4_8_9_5, 0.4_9_9_3]					)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2
    assert np.abs(image_from_tuple_slice.flatten() - expected_slice					).max() < 1e-2







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Tuple		= StableDiffusionPipeline.from_pretrained(
        """hf-internal-testing/tiny-stable-diffusion-lms-pipe"""   ,    safety_checker=snake_case_					)
    assert isinstance(snake_case_   ,    snake_case_					)
    assert isinstance(pipe.scheduler   ,    snake_case_					)
    assert pipe.safety_checker is None

    __UpperCAmelCase:					Tuple		= pipe("""example prompt"""   ,    num_inference_steps=2					).images[0]
    assert image is not None

    # check that there's no error when saving a pipeline with one of the models being None
    with tempfile.TemporaryDirectory() as tmpdirname:
      pipe.save_pretrained(snake_case_					)
      __UpperCAmelCase:					Tuple		= StableDiffusionPipeline.from_pretrained(snake_case_					)

    # sanity check that the pipeline still works
    assert pipe.safety_checker is None
    __UpperCAmelCase:					Optional[Any]		= pipe("""example prompt"""   ,    num_inference_steps=2					).images[0]
    assert image is not None







  @unittest.skipIf(torch_device != """cuda"""   ,    """This test requires a GPU"""					)
  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Dict		= self.dummy_cond_unet
    __UpperCAmelCase:					List[Any]		= PNDMScheduler(skip_prk_steps=snake_case_					)
    __UpperCAmelCase:					Optional[Any]		= self.dummy_vae
    __UpperCAmelCase:					Any		= self.dummy_text_encoder
    __UpperCAmelCase:					Optional[int]		= CLIPTokenizer.from_pretrained("""hf-internal-testing/tiny-random-clip"""					)

    # put models in fp16
    __UpperCAmelCase:					List[str]		= unet.half()
    __UpperCAmelCase:					List[Any]		= vae.half()
    __UpperCAmelCase:					Optional[int]		= bert.half()

    # make sure here that pndm scheduler skips prk
    __UpperCAmelCase:					str		= StableDiffusionPipeline(
        unet=snake_case_   ,    scheduler=snake_case_   ,    vae=snake_case_   ,    text_encoder=snake_case_   ,    tokenizer=snake_case_   ,    safety_checker=snake_case_   ,    feature_extractor=self.dummy_extractor   ,    )
    __UpperCAmelCase:					Optional[Any]		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					Union[str, Any]		= """A painting of a squirrel eating a burger"""
    __UpperCAmelCase:					Dict		= sd_pipe([prompt]   ,    num_inference_steps=2   ,    output_type="""np"""					).images

    assert image.shape == (1, 64, 64, 3)




@nightly
@require_torch_gpu
class    a (       unittest.TestCase				):



  """simple docstring"""







  def    lowercase_  (							self					):

    '''simple docstring'''







    super().tearDown()
    gc.collect()
    torch.cuda.empty_cache()







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""   ,    safety_checker=snake_case_					)
    __UpperCAmelCase:					List[Any]		= LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config					)
    __UpperCAmelCase:					List[Any]		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					Union[str, Any]		= (
        """portrait of girl with smokey eyes makeup in abandoned hotel, grange clothes, redshift, wide high angle"""
        """ coloured polaroid photograph with flash, kodak film, hyper real, stunning moody cinematography, with"""
        """ anamorphic lenses, by maripol, fallen angels by wong kar - wai, style of suspiria and neon demon and"""
        """ children from bahnhof zoo, detailed """
    )
    __UpperCAmelCase:					Optional[int]		= 40_0366_0346
    __UpperCAmelCase:					Dict		= 7

    # without safety guidance (sld_guidance_scale = 0)
    __UpperCAmelCase:					Optional[Any]		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					Optional[Any]		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=0   ,    )

    __UpperCAmelCase:					Optional[int]		= output.images
    __UpperCAmelCase:					int		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					Any		= [0.2_2_7_8, 0.2_2_3_1, 0.2_2_4_9, 0.2_3_3_3, 0.2_3_0_3, 0.1_8_8_5, 0.2_2_7_3, 0.2_1_4_4, 0.2_1_7_6]

    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2

    # without safety guidance (strong configuration)
    __UpperCAmelCase:					Tuple		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					Optional[int]		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=2000   ,    sld_warmup_steps=7   ,    sld_threshold=0.0_2_5   ,    sld_momentum_scale=0.5   ,    sld_mom_beta=0.7   ,    )

    __UpperCAmelCase:					Union[str, Any]		= output.images
    __UpperCAmelCase:					Tuple		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					int		= [0.2_3_8_3, 0.2_2_7_6, 0.2_3_6, 0.2_1_9_2, 0.2_1_8_6, 0.2_0_5_3, 0.1_9_7_1, 0.1_9_0_1, 0.1_7_1_9]

    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""   ,    safety_checker=snake_case_					)
    __UpperCAmelCase:					int		= LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config					)
    __UpperCAmelCase:					Any		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					Any		= """padme amidala taking a bath artwork, safe for work, no nudity"""
    __UpperCAmelCase:					int		= 27_3497_1755
    __UpperCAmelCase:					int		= 7

    __UpperCAmelCase:					List[str]		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					str		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=0   ,    )

    __UpperCAmelCase:					List[Any]		= output.images
    __UpperCAmelCase:					int		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					Dict		= [0.3_5_0_2, 0.3_6_2_2, 0.3_3_9_6, 0.3_6_4_2, 0.3_4_7_8, 0.3_3_1_8, 0.3_5, 0.3_3_4_8, 0.3_2_9_7]

    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2

    __UpperCAmelCase:					List[str]		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					str		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=2000   ,    sld_warmup_steps=7   ,    sld_threshold=0.0_2_5   ,    sld_momentum_scale=0.5   ,    sld_mom_beta=0.7   ,    )

    __UpperCAmelCase:					Optional[int]		= output.images
    __UpperCAmelCase:					Optional[Any]		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					int		= [0.5_5_3_1, 0.5_2_0_6, 0.4_8_9_5, 0.5_1_5_6, 0.5_1_8_2, 0.4_7_5_1, 0.4_8_0_2, 0.4_8_0_3, 0.4_4_4_3]

    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= StableDiffusionPipeline.from_pretrained("""runwayml/stable-diffusion-v1-5"""					)
    __UpperCAmelCase:					List[str]		= sd_pipe.to(snake_case_					)
    sd_pipe.set_progress_bar_config(disable=snake_case_					)

    __UpperCAmelCase:					List[Any]		= (
        """the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c."""
        """ leyendecker"""
    )
    __UpperCAmelCase:					List[Any]		= 10_4435_5234
    __UpperCAmelCase:					Optional[Any]		= 12

    __UpperCAmelCase:					str		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					str		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=0   ,    )

    __UpperCAmelCase:					Tuple		= output.images
    __UpperCAmelCase:					List[Any]		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					str		= np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]					)

    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-7

    __UpperCAmelCase:					int		= torch.manual_seed(snake_case_					)
    __UpperCAmelCase:					str		= sd_pipe(
        [prompt]   ,    generator=snake_case_   ,    guidance_scale=snake_case_   ,    num_inference_steps=50   ,    output_type="""np"""   ,    width=512   ,    height=512   ,    sld_guidance_scale=2000   ,    sld_warmup_steps=7   ,    sld_threshold=0.0_2_5   ,    sld_momentum_scale=0.5   ,    sld_mom_beta=0.7   ,    )

    __UpperCAmelCase:					Dict		= output.images
    __UpperCAmelCase:					Tuple		= image[0, -3:, -3:, -1]
    __UpperCAmelCase:					Tuple		= np.array([0.5_8_1_8, 0.6_2_8_5, 0.6_8_3_5, 0.6_0_1_9, 0.6_2_5, 0.6_7_5_4, 0.6_0_9_6, 0.6_3_3_4, 0.6_5_6_1]					)
    assert image.shape == (1, 512, 512, 3)

    assert np.abs(image_slice.flatten() - expected_slice					).max() < 1e-2
'''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, prepare_image_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import PoolFormerImageProcessor




class    a (       unittest.TestCase				):



  """simple docstring"""







  def __init__(							self   ,    snake_case_   ,    snake_case_=7   ,    snake_case_=3   ,    snake_case_=30   ,    snake_case_=400   ,    snake_case_=True   ,    snake_case_=None   ,    snake_case_=0.9   ,    snake_case_=None   ,    snake_case_=True   ,    snake_case_=[0.5, 0.5, 0.5]   ,    snake_case_=[0.5, 0.5, 0.5]   ,    ):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= size if size is not None else {"""shortest_edge""": 30}
    __UpperCAmelCase:					str		= crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
    __UpperCAmelCase:					Dict		= parent
    __UpperCAmelCase:					Union[str, Any]		= batch_size
    __UpperCAmelCase:					List[Any]		= num_channels
    __UpperCAmelCase:					List[str]		= min_resolution
    __UpperCAmelCase:					List[str]		= max_resolution
    __UpperCAmelCase:					Tuple		= do_resize_and_center_crop
    __UpperCAmelCase:					Union[str, Any]		= size
    __UpperCAmelCase:					str		= crop_pct
    __UpperCAmelCase:					List[Any]		= crop_size
    __UpperCAmelCase:					str		= do_normalize
    __UpperCAmelCase:					Union[str, Any]		= image_mean
    __UpperCAmelCase:					List[str]		= image_std







  def    lowercase_  (							self					):

    '''simple docstring'''







    return {
        "size": self.size,
        "do_resize_and_center_crop": self.do_resize_and_center_crop,
        "crop_pct": self.crop_pct,
        "crop_size": self.crop_size,
        "do_normalize": self.do_normalize,
        "image_mean": self.image_mean,
        "image_std": self.image_std,
    }




@require_torch
@require_vision
class    a (       __lowerCAmelCase						,  unittest.TestCase				):



  """simple docstring"""
  __lowerCAmelCase				      =					PoolFormerImageProcessor if is_vision_available() else None







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= PoolFormerImageProcessingTester(self					)







  @property
  def    lowercase_  (							self					):

    '''simple docstring'''







    return self.image_processor_tester.prepare_image_processor_dict()







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= self.image_processing_class(**self.image_processor_dict					)
    self.assertTrue(hasattr(snake_case_   ,    """do_resize_and_center_crop"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """size"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """crop_pct"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """do_normalize"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """image_mean"""					)					)
    self.assertTrue(hasattr(snake_case_   ,    """image_std"""					)					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[str]		= self.image_processing_class.from_dict(self.image_processor_dict					)
    self.assertEqual(image_processor.size   ,    {"""shortest_edge""": 30}					)
    self.assertEqual(image_processor.crop_size   ,    {"""height""": 30, """width""": 30}					)

    __UpperCAmelCase:					Dict		= 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    lowercase_  (							self					):

    '''simple docstring'''







    pass







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= self.image_processing_class(**self.image_processor_dict					)
    # create random PIL images
    __UpperCAmelCase:					Optional[Any]		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    Image.Image					)

    # Test not batched input
    __UpperCAmelCase:					Optional[int]		= 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
    __UpperCAmelCase:					Any		= image_processing(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    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[Any]		= self.image_processing_class(**self.image_processor_dict					)
    # create random numpy tensors
    __UpperCAmelCase:					Union[str, Any]		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_   ,    numpify=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    np.ndarray					)

    # Test not batched input
    __UpperCAmelCase:					Union[str, Any]		= 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
    __UpperCAmelCase:					str		= image_processing(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    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= self.image_processing_class(**self.image_processor_dict					)
    # create random PyTorch tensors
    __UpperCAmelCase:					Dict		= prepare_image_inputs(self.image_processor_tester   ,    equal_resolution=snake_case_   ,    torchify=snake_case_					)
    for image in image_inputs:
      self.assertIsInstance(snake_case_   ,    torch.Tensor					)

    # Test not batched input
    __UpperCAmelCase:					Optional[int]		= 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
    __UpperCAmelCase:					Optional[int]		= image_processing(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"""],
        )   ,    )