



import os
import tempfile
import unittest

import numpy as np

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax, slow


if is_flax_available():
      import jax
      import jax.numpy as jnp
      from flax.jax_utils import replicate
      from flax.training.common_utils import shard

      from diffusers import FlaxDDIMScheduler, FlaxDiffusionPipeline, FlaxStableDiffusionPipeline

@require_flax
class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def 	__snake_case    (       self :							Optional[Any]				)->Optional[Any]:
      with tempfile.TemporaryDirectory() as tmpdirname:
       # pipeline has Flax weights
       __SCREAMING_SNAKE_CASE       :    List[str]       =	FlaxDiffusionPipeline.from_pretrained(
           "hf-internal-testing/tiny-stable-diffusion-pipe"     ,  safety_checker=__lowercase     ,  cache_dir=__lowercase				)

       __SCREAMING_SNAKE_CASE       :    List[Any]       =	[t[-1] for t in os.walk(os.path.join(__lowercase     ,  os.listdir(__lowercase				)[0]     ,  "snapshots"				)				)]
       __SCREAMING_SNAKE_CASE       :    Tuple       =	[item for sublist in all_root_files for item in sublist]

       # None of the downloaded files should be a PyTorch file even if we have some here:
       # https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-pipe/blob/main/unet/diffusion_pytorch_model.bin
       assert not any(f.endswith(".bin"				) for f in files				)






@slow
@require_flax
class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def 	__snake_case    (       self :							Any				)->int:
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "hf-internal-testing/tiny-stable-diffusion-pipe"     ,  safety_checker=__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	jax.random.PRNGKey(0				)
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	4

      __SCREAMING_SNAKE_CASE       :    str       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    Dict       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    Dict       =	pipeline.prepare_inputs(__lowercase				)

      # shard inputs and rng
      __SCREAMING_SNAKE_CASE       :    List[str]       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    int       =	jax.random.split(__lowercase     ,  __lowercase				)
      __SCREAMING_SNAKE_CASE       :    str       =	shard(__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Tuple       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images

      assert images.shape == (num_samples, 1, 6_4, 6_4, 3)
      if jax.device_count() == 8:
       assert np.abs(np.abs(images[0, 0, :2, :2, -2:]     ,  dtype=np.floataa				).sum() - 4.1_5_1_4_7_4_5				) < 1E-3
       assert np.abs(np.abs(__lowercase     ,  dtype=np.floataa				).sum() - 4_9_9_4_7.8_7_5				) < 5E-1

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:]				)				)				)
      assert len(__lowercase				) == num_samples





     def 	__snake_case    (       self :							Union[str, Any]				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="flax"     ,  safety_checker=__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	jax.random.PRNGKey(0				)
      __SCREAMING_SNAKE_CASE       :    str       =	5_0

      __SCREAMING_SNAKE_CASE       :    int       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    Any       =	pipeline.prepare_inputs(__lowercase				)

      # shard inputs and rng
      __SCREAMING_SNAKE_CASE       :    Dict       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	jax.random.split(__lowercase     ,  __lowercase				)
      __SCREAMING_SNAKE_CASE       :    int       =	shard(__lowercase				)

      __SCREAMING_SNAKE_CASE       :    str       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images

      assert images.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      if jax.device_count() == 8:
       assert np.abs((np.abs(images[0, 0, :2, :2, -2:]     ,  dtype=np.floataa				).sum() - 0.0_5_6_5_2_4_0_1)				) < 1E-3
       assert np.abs((np.abs(__lowercase     ,  dtype=np.floataa				).sum() - 2_3_8_3_8_0_8.2)				) < 5E-1





     def 	__snake_case    (       self :							int				)->List[Any]:
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="bf16"     ,  dtype=jnp.bfloataa     ,  safety_checker=__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Dict       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Dict       =	jax.random.PRNGKey(0				)
      __SCREAMING_SNAKE_CASE       :    Any       =	5_0

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    int       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	pipeline.prepare_inputs(__lowercase				)

      # shard inputs and rng
      __SCREAMING_SNAKE_CASE       :    Any       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    Dict       =	jax.random.split(__lowercase     ,  __lowercase				)
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	shard(__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Dict       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images

      assert images.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      if jax.device_count() == 8:
       assert np.abs((np.abs(images[0, 0, :2, :2, -2:]     ,  dtype=np.floataa				).sum() - 0.0_4_0_0_3_9_0_6)				) < 1E-3
       assert np.abs((np.abs(__lowercase     ,  dtype=np.floataa				).sum() - 2_3_7_3_5_1_6.7_5)				) < 5E-1





     def 	__snake_case    (       self :							Dict				)->int:
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="bf16"     ,  dtype=jnp.bfloataa				)

      __SCREAMING_SNAKE_CASE       :    Any       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Dict       =	jax.random.PRNGKey(0				)
      __SCREAMING_SNAKE_CASE       :    Dict       =	5_0

      __SCREAMING_SNAKE_CASE       :    List[str]       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    Dict       =	pipeline.prepare_inputs(__lowercase				)

      # shard inputs and rng
      __SCREAMING_SNAKE_CASE       :    Any       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	jax.random.split(__lowercase     ,  __lowercase				)
      __SCREAMING_SNAKE_CASE       :    int       =	shard(__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Any       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images

      assert images.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      if jax.device_count() == 8:
       assert np.abs((np.abs(images[0, 0, :2, :2, -2:]     ,  dtype=np.floataa				).sum() - 0.0_4_0_0_3_9_0_6)				) < 1E-3
       assert np.abs((np.abs(__lowercase     ,  dtype=np.floataa				).sum() - 2_3_7_3_5_1_6.7_5)				) < 5E-1





     def 	__snake_case    (       self :							Union[str, Any]				)->Optional[Any]:
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	FlaxDDIMScheduler(
          beta_start=0.0_0_0_8_5     ,  beta_end=0.0_1_2     ,  beta_schedule="scaled_linear"     ,  set_alpha_to_one=__lowercase     ,  steps_offset=1     ,  )

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    int       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="bf16"     ,  dtype=jnp.bfloataa     ,  scheduler=__lowercase     ,  safety_checker=__lowercase     ,  )
      __SCREAMING_SNAKE_CASE       :    int       =	scheduler.create_state()

      __SCREAMING_SNAKE_CASE       :    List[str]       =	scheduler_state

      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	jax.random.PRNGKey(0				)
      __SCREAMING_SNAKE_CASE       :    Any       =	5_0

      __SCREAMING_SNAKE_CASE       :    Tuple       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    Any       =	pipeline.prepare_inputs(__lowercase				)

      # shard inputs and rng
      __SCREAMING_SNAKE_CASE       :    int       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	jax.random.split(__lowercase     ,  __lowercase				)
      __SCREAMING_SNAKE_CASE       :    Any       =	shard(__lowercase				)

      __SCREAMING_SNAKE_CASE       :    Dict       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images

      assert images.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      if jax.device_count() == 8:
       assert np.abs((np.abs(images[0, 0, :2, :2, -2:]     ,  dtype=np.floataa				).sum() - 0.0_4_5_0_4_3_9_4_5)				) < 1E-3
       assert np.abs((np.abs(__lowercase     ,  dtype=np.floataa				).sum() - 2_3_4_7_6_9_3.5)				) < 5E-1






     def 	__snake_case    (       self :							Dict				)->Any:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	(
          "A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of"
          " field, close up, split lighting, cinematic"
      )

      __SCREAMING_SNAKE_CASE       :    Any       =	jax.device_count()
      __SCREAMING_SNAKE_CASE       :    str       =	num_samples * [prompt]
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	jax.random.split(jax.random.PRNGKey(0				)     ,  __lowercase				)

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="bf16"     ,  dtype=jnp.bfloataa     ,  safety_checker=__lowercase     ,  )

      __SCREAMING_SNAKE_CASE       :    Dict       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    Dict       =	pipeline.prepare_inputs(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    str       =	shard(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    int       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images
      assert images.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      __SCREAMING_SNAKE_CASE       :    str       =	images[2, 0, 2_5_6, 1_0:1_7, 1]

      # With memory efficient attention
      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	FlaxStableDiffusionPipeline.from_pretrained(
          "CompVis/stable-diffusion-v1-4"     ,  revision="bf16"     ,  dtype=jnp.bfloataa     ,  safety_checker=__lowercase     ,  use_memory_efficient_attention=__lowercase     ,  )

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	replicate(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    Any       =	pipeline.prepare_inputs(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    str       =	shard(__lowercase				)
      __SCREAMING_SNAKE_CASE       :    int       =	pipeline(__lowercase     ,  __lowercase     ,  __lowercase     ,  jit=__lowercase				).images
      assert images_eff.shape == (num_samples, 1, 5_1_2, 5_1_2, 3)
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	images[2, 0, 2_5_6, 1_0:1_7, 1]

      # I checked the results visually and they are very similar. However, I saw that the max diff is `1` and the `sum`
      # over the 8 images is exactly `256`, which is very suspicious. Testing a random slice for now.
      assert abs(slice_eff - slice				).max() < 1E-2











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       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     def __init__(       self :							Union[str, Any]     ,  UpperCamelCase :							List[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.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]     ,  UpperCamelCase :							Optional[Union[float, List[float]]] = [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]     ,  UpperCamelCase :							bool = True     ,  UpperCamelCase :							Dict=7     ,  UpperCamelCase :							Dict=3_0     ,  UpperCamelCase :							Tuple=4_0_0     ,  UpperCamelCase :							Union[str, Any]=3     ,  )->Optional[int]:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	parent
      __SCREAMING_SNAKE_CASE       :    str       =	do_resize
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	size if size is not None else {"shortest_edge": 2_8_8}
      __SCREAMING_SNAKE_CASE       :    List[str]       =	size_divisor
      __SCREAMING_SNAKE_CASE       :    str       =	do_rescale
      __SCREAMING_SNAKE_CASE       :    int       =	rescale_factor
      __SCREAMING_SNAKE_CASE       :    Tuple       =	do_normalize
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	do_center_crop
      __SCREAMING_SNAKE_CASE       :    List[str]       =	image_mean
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_std
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	do_pad
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	batch_size
      __SCREAMING_SNAKE_CASE       :    str       =	num_channels
      __SCREAMING_SNAKE_CASE       :    List[str]       =	min_resolution
      __SCREAMING_SNAKE_CASE       :    Tuple       =	max_resolution





     def 	__snake_case    (       self :							Optional[Any]				)->List[str]:
      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 	__snake_case    (       self :							Optional[Any]     ,  UpperCamelCase :							Optional[int]     ,  UpperCamelCase :							Dict=False				)->Optional[Any]:
      if not batched:
       __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.size["shortest_edge"]
       __SCREAMING_SNAKE_CASE       :    List[Any]       =	image_inputs[0]
       if isinstance(UpperCamelCase     ,  Image.Image				):
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	image.size
       else:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	image.shape[1], image.shape[2]
       __SCREAMING_SNAKE_CASE       :    Tuple       =	size / min(UpperCamelCase     ,  UpperCamelCase				)
       if h < w:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    int       =	size, scale * w
       else:
        __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[str]       =	scale * h, size

       __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	int((1_3_3_3 / 8_0_0) * size				)
       if max(UpperCamelCase     ,  UpperCamelCase				) > max_size:
        __SCREAMING_SNAKE_CASE       :    Any       =	max_size / max(UpperCamelCase     ,  UpperCamelCase				)
        __SCREAMING_SNAKE_CASE       :    List[Any]       =	newh * scale
        __SCREAMING_SNAKE_CASE       :    Optional[int]       =	neww * scale

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	int(newh + 0.5				), int(neww + 0.5				)
       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	(
           newh // self.size_divisor * self.size_divisor,
           neww // self.size_divisor * self.size_divisor,
       )

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

      return expected_height, expected_width






@require_torch
@require_vision
class       _SCREAMING_SNAKE_CASE	(UpperCamelCase			,    unittest.TestCase ):
     lowerCAmelCase					=			BridgeTowerImageProcessor if is_vision_available() else None





     def 	__snake_case    (       self :							str				)->int:
      __SCREAMING_SNAKE_CASE       :    str       =	BridgeTowerImageProcessingTester(self				)





     @property
     def 	__snake_case    (       self :							str				)->Any:
      return self.image_processor_tester.prepare_image_processor_dict()





     def 	__snake_case    (       self :							Optional[int]				)->Dict:
      __SCREAMING_SNAKE_CASE       :    Union[str, 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 	__snake_case    (       self :							Optional[int]				)->int:
      pass





     def 	__snake_case    (       self :							str				)->Union[str, Any]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    Any       =	self.image_processing_class(**self.image_processor_dict				)
      # create random PIL images
      __SCREAMING_SNAKE_CASE       :    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
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    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
      __SCREAMING_SNAKE_CASE       :    Any       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	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 	__snake_case    (       self :							List[str]				)->Optional[int]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.image_processing_class(**self.image_processor_dict				)
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE       :    Union[str, 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
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Optional[int]       =	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
      __SCREAMING_SNAKE_CASE       :    str       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    List[Any]       =	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 	__snake_case    (       self :							Optional[Any]				)->Union[str, Any]:
      # Initialize image processor
      __SCREAMING_SNAKE_CASE       :    Dict       =	self.image_processing_class(**self.image_processor_dict				)
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE       :    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
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	image_processing(image_inputs[0]     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Dict       =	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
      __SCREAMING_SNAKE_CASE       :    str       =	image_processing(UpperCamelCase     ,  return_tensors="pt"				).pixel_values

      __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE       :    Any       =	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,
          )     ,  )






