




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


       def __init__(      self			,     __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE=13			,     __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=[0.5, 0.5, 0.5]			,     __SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]			,     )					->     Any:



            '''simple docstring'''




            __snake_case			    =     size if 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_normalize
            __snake_case			    =     image_mean
            __snake_case			    =     image_std




       def 					lowerCAmelCase					(      self     )					->     List[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 			lowerCAmelCase      (       _snake_case ,      unittest.TestCase):
       __lowercase     :					List[str]       				=	EfficientNetImageProcessor if is_vision_available() else None


       def 					lowerCAmelCase					(      self     )					->     int:



            '''simple docstring'''




            __snake_case			    =     EfficientNetImageProcessorTester(self     )


       @property
       def 					lowerCAmelCase					(      self     )					->     Dict:



            '''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(_lowercase			,     '''image_mean'''     )     )
            self.assertTrue(hasattr(_lowercase			,     '''image_std'''     )     )
            self.assertTrue(hasattr(_lowercase			,     '''do_normalize'''     )     )
            self.assertTrue(hasattr(_lowercase			,     '''do_resize'''     )     )
            self.assertTrue(hasattr(_lowercase			,     '''size'''     )     )


       def 					lowerCAmelCase					(      self     )					->     Union[str, Any]:



            '''simple docstring'''




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

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


       def 					lowerCAmelCase					(      self     )					->     Dict:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random PIL images
            __snake_case			    =     prepare_image_inputs(self.image_processor_tester			,     equal_resolution=_lowercase     )
            for image in image_inputs:
                 self.assertIsInstance(_lowercase			,     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.size['''height'''],
                    self.image_processor_tester.size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(_lowercase			,     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 					lowerCAmelCase					(      self     )					->     List[Any]:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random numpy tensors
            __snake_case			    =     prepare_image_inputs(self.image_processor_tester			,     equal_resolution=_lowercase			,     numpify=_lowercase     )
            for image in image_inputs:
                 self.assertIsInstance(_lowercase			,     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.size['''height'''],
                    self.image_processor_tester.size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(_lowercase			,     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 					lowerCAmelCase					(      self     )					->     Dict:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random PyTorch tensors
            __snake_case			    =     prepare_image_inputs(self.image_processor_tester			,     equal_resolution=_lowercase			,     torchify=_lowercase     )
            for image in image_inputs:
                 self.assertIsInstance(_lowercase			,     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.size['''height'''],
                    self.image_processor_tester.size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(_lowercase			,     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'''],
                )			,     )











from dataclasses import dataclass
from typing import Callable, Optional

import datasets







@dataclass
class 							a_  (		datasets.BuilderConfig				):
						UpperCamelCase__      :						Optional[Callable]				       =None
						UpperCamelCase__      :						Optional[dict]				       =None
						UpperCamelCase__      :						Optional[datasets.Features]				       =None

						def 	__a       (    self	:List[str])		->					List[str]:
												assert self.generator is not None, "generator must be specified"

												if self.gen_kwargs is None:
																		UpperCAmelCase_     							=     {}







class 							a_  (		datasets.GeneratorBasedBuilder				):
						UpperCamelCase__      :						List[str]				       =GeneratorConfig

						def 	__a       (    self	:List[str])		->					List[Any]:
												return datasets.DatasetInfo(features=self.config.features)

						def 	__a       (    self	:Optional[Any]   ,						_lowercase	:List[str])		->					Optional[Any]:
												return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,						gen_kwargs=self.config.gen_kwargs)]




						def 	__a       (    self	:Optional[int]   ,						**_lowercase	:str)		->					Union[str, Any]:
												for idx, ex in enumerate(self.config.generator(**_lowercase)):
																		yield idx, ex





