



'''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 EfficientNetImageProcessor







class 						UpperCAmelCase						(		unittest.TestCase):


 '''simple docstring'''




 def __init__( self				,	lowerCAmelCase_				,	lowerCAmelCase_=1_3				,	lowerCAmelCase_=3				,	lowerCAmelCase_=1_8				,	lowerCAmelCase_=3_0				,	lowerCAmelCase_=4_0_0				,	lowerCAmelCase_=True				,	lowerCAmelCase_=None				,	lowerCAmelCase_=True				,	lowerCAmelCase_=[0.5, 0.5, 0.5]				,	lowerCAmelCase_=[0.5, 0.5, 0.5]				,	)			->   List[Any]:



      """simple docstring"""







      a_									=size if size is not None else {"height": 1_8, "width": 1_8}
      a_									=parent
      a_									=batch_size
      a_									=num_channels
      a_									=image_size
      a_									=min_resolution
      a_									=max_resolution
      a_									=do_resize
      a_									=size
      a_									=do_normalize
      a_									=image_mean
      a_									=image_std




 def    lowercase_	( self)			->   Tuple:



      """simple docstring"""







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







@require_torch
@require_vision
class 						UpperCAmelCase						(		__a       ,						unittest.TestCase):


 '''simple docstring'''




 __magic_name__       :			List[Any]	=   EfficientNetImageProcessor if is_vision_available() else None




 def    lowercase_	( self)			->   Any:



      """simple docstring"""







      a_									=EfficientNetImageProcessorTester(self)




 @property
 def    lowercase_	( self)			->   str:



      """simple docstring"""







      return self.image_processor_tester.prepare_image_processor_dict()




 def    lowercase_	( self)			->   List[str]:



      """simple docstring"""







      a_									=self.image_processing_class(**self.image_processor_dict)
      self.assertTrue(hasattr(lowerCAmelCase_				,	"image_mean"))
      self.assertTrue(hasattr(lowerCAmelCase_				,	"image_std"))
      self.assertTrue(hasattr(lowerCAmelCase_				,	"do_normalize"))
      self.assertTrue(hasattr(lowerCAmelCase_				,	"do_resize"))
      self.assertTrue(hasattr(lowerCAmelCase_				,	"size"))




 def    lowercase_	( self)			->   str:



      """simple docstring"""







      a_									=self.image_processing_class.from_dict(self.image_processor_dict)
      self.assertEqual(image_processor.size				,	{"height": 1_8, "width": 1_8})

      a_									=self.image_processing_class.from_dict(self.image_processor_dict				,	size=4_2)
      self.assertEqual(image_processor.size				,	{"height": 4_2, "width": 4_2})




 def    lowercase_	( self)			->   Dict:



      """simple docstring"""







      a_									=self.image_processing_class(**self.image_processor_dict)
      # create random PIL images
      a_									=prepare_image_inputs(self.image_processor_tester				,	equal_resolution=lowerCAmelCase_)
      for image in image_inputs:
           self.assertIsInstance(lowerCAmelCase_				,	Image.Image)

      # Test not batched input
      a_									=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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)

      # Test batched
      a_									=image_processing(lowerCAmelCase_				,	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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)




 def    lowercase_	( self)			->   Dict:



      """simple docstring"""







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

      # Test not batched input
      a_									=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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)

      # Test batched
      a_									=image_processing(lowerCAmelCase_				,	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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)




 def    lowercase_	( self)			->   Any:



      """simple docstring"""







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

      # Test not batched input
      a_									=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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)

      # Test batched
      a_									=image_processing(lowerCAmelCase_				,	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.size["height"],
              self.image_processor_tester.size["width"],
          )				,	)







'''simple docstring'''


import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput







@dataclass
class 						UpperCAmelCase						(		__a):


 '''simple docstring'''




 __magic_name__       :			Union[List[PIL.Image.Image], np.ndarray]







class 						UpperCAmelCase						(		unittest.TestCase):


 '''simple docstring'''




 def    lowercase_	( self)			->   List[str]:



      """simple docstring"""







      a_									=CustomOutput(images=np.random.rand(1				,	3				,	4				,	4))

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	np.ndarray)
      assert outputs.images.shape == (1, 3, 4, 4)
      assert isinstance(outputs["images"]				,	np.ndarray)
      assert outputs["images"].shape == (1, 3, 4, 4)
      assert isinstance(outputs[0]				,	np.ndarray)
      assert outputs[0].shape == (1, 3, 4, 4)

      # test with a non-tensor attribute
      a_									=CustomOutput(images=[PIL.Image.new("RGB"				,	(4, 4))])

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	lowerCAmelCase_)
      assert isinstance(outputs.images[0]				,	PIL.Image.Image)
      assert isinstance(outputs["images"]				,	lowerCAmelCase_)
      assert isinstance(outputs["images"][0]				,	PIL.Image.Image)
      assert isinstance(outputs[0]				,	lowerCAmelCase_)
      assert isinstance(outputs[0][0]				,	PIL.Image.Image)




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



      """simple docstring"""







      a_									=CustomOutput({"images": np.random.rand(1				,	3				,	4				,	4)})

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	np.ndarray)
      assert outputs.images.shape == (1, 3, 4, 4)
      assert isinstance(outputs["images"]				,	np.ndarray)
      assert outputs["images"].shape == (1, 3, 4, 4)
      assert isinstance(outputs[0]				,	np.ndarray)
      assert outputs[0].shape == (1, 3, 4, 4)

      # test with a non-tensor attribute
      a_									=CustomOutput({"images": [PIL.Image.new("RGB"				,	(4, 4))]})

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	lowerCAmelCase_)
      assert isinstance(outputs.images[0]				,	PIL.Image.Image)
      assert isinstance(outputs["images"]				,	lowerCAmelCase_)
      assert isinstance(outputs["images"][0]				,	PIL.Image.Image)
      assert isinstance(outputs[0]				,	lowerCAmelCase_)
      assert isinstance(outputs[0][0]				,	PIL.Image.Image)


