




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 						SCREAMING_SNAKE_CASE__		(unittest.TestCase ):
     def __init__(	self  :		int					,	__lowerCamelCase  :		List[Any]					,	__lowerCamelCase  :		Any=13					,	__lowerCamelCase  :		int=3					,	__lowerCamelCase  :		str=18					,	__lowerCamelCase  :		List[Any]=30					,	__lowerCamelCase  :		Optional[Any]=4_00					,	__lowerCamelCase  :		Optional[Any]=True					,	__lowerCamelCase  :		Tuple=None					,	__lowerCamelCase  :		Dict=True					,	__lowerCamelCase  :		List[Any]=[0.5, 0.5, 0.5]					,	__lowerCamelCase  :		Optional[int]=[0.5, 0.5, 0.5]					,	):



       """simple docstring"""
       lowerCAmelCase__								=			size if size is not None else {'''height''': 18, '''width''': 18}
       lowerCAmelCase__								=			parent
       lowerCAmelCase__								=			batch_size
       lowerCAmelCase__								=			num_channels
       lowerCAmelCase__								=			image_size
       lowerCAmelCase__								=			min_resolution
       lowerCAmelCase__								=			max_resolution
       lowerCAmelCase__								=			do_resize
       lowerCAmelCase__								=			size
       lowerCAmelCase__								=			do_normalize
       lowerCAmelCase__								=			image_mean
       lowerCAmelCase__								=			image_std



     def 					A__			(	self  :		str	):



       """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 						SCREAMING_SNAKE_CASE__		(_a						,				unittest.TestCase ):
     lowercase_   :			List[str]   =   EfficientNetImageProcessor if is_vision_available() else None
     def 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			EfficientNetImageProcessorTester(self	)
     @property
     def 					A__			(	self  :		Tuple	):



       """simple docstring"""
       return self.image_processor_tester.prepare_image_processor_dict()
     def 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			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 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			self.image_processing_class.from_dict(self.image_processor_dict	)
       self.assertEqual(image_processor.size					,	{'''height''': 18, '''width''': 18}	)

       lowerCAmelCase__								=			self.image_processing_class.from_dict(self.image_processor_dict					,	size=42	)
       self.assertEqual(image_processor.size					,	{'''height''': 42, '''width''': 42}	)
     def 					A__			(	self  :		int	):



       """simple docstring"""
       lowerCAmelCase__								=			self.image_processing_class(**self.image_processor_dict	)
       # create random PIL images
       lowerCAmelCase__								=			prepare_image_inputs(self.image_processor_tester					,	equal_resolution=__lowerCamelCase	)
       for image in image_inputs:
         self.assertIsInstance(__lowerCamelCase					,	Image.Image	)

       # Test not batched input
       lowerCAmelCase__								=			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
       lowerCAmelCase__								=			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 					A__			(	self  :		Dict	):



       """simple docstring"""
       lowerCAmelCase__								=			self.image_processing_class(**self.image_processor_dict	)
       # create random numpy tensors
       lowerCAmelCase__								=			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
       lowerCAmelCase__								=			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
       lowerCAmelCase__								=			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 					A__			(	self  :		Optional[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.image_processing_class(**self.image_processor_dict	)
       # create random PyTorch tensors
       lowerCAmelCase__								=			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
       lowerCAmelCase__								=			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
       lowerCAmelCase__								=			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 		a_       (   __lowerCAmelCase      ,   __lowerCAmelCase							):
  lowerCAmelCase__								=			0
  for ele in arr:
    total_sum += product_sum(__lowerCAmelCase      ,   depth + 1							) if isinstance(__lowerCAmelCase      ,   __lowerCAmelCase							) else ele
  return total_sum * depth
def 		a_       (   __lowerCAmelCase							):
  return product_sum(__lowerCAmelCase      ,   1							)


if __name__ == "__main__":
      import doctest

      doctest.testmod()

