






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




							def __init__(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   List[str]=7 ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=3 ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=30 ,							SCREAMING_SNAKE_CASE_     :   List[str]=400 ,							SCREAMING_SNAKE_CASE_     :   Any=True ,							SCREAMING_SNAKE_CASE_     :   Union[str, Any]=None ,							SCREAMING_SNAKE_CASE_     :   List[Any]=0.9 ,							SCREAMING_SNAKE_CASE_     :   Tuple=None ,							SCREAMING_SNAKE_CASE_     :   str=True ,							SCREAMING_SNAKE_CASE_     :   List[str]=[0.5, 0.5, 0.5] ,							SCREAMING_SNAKE_CASE_     :   Optional[Any]=[0.5, 0.5, 0.5] ,							):
											lowerCAmelCase__      			=						size if size is not None else {'''shortest_edge''': 30}
											lowerCAmelCase__      			=						crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
											lowerCAmelCase__      			=						parent
											lowerCAmelCase__      			=						batch_size
											lowerCAmelCase__      			=						num_channels
											lowerCAmelCase__      			=						min_resolution
											lowerCAmelCase__      			=						max_resolution
											lowerCAmelCase__      			=						do_resize_and_center_crop
											lowerCAmelCase__      			=						size
											lowerCAmelCase__      			=						crop_pct
											lowerCAmelCase__      			=						crop_size
											lowerCAmelCase__      			=						do_normalize
											lowerCAmelCase__      			=						image_mean
											lowerCAmelCase__      			=						image_std




							def 						__snake_case					(   self     :   str	):
											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  lowerCAmelCase_       (				snake_case__     ,    unittest.TestCase					):
							UpperCamelCase_		:int		      =    PoolFormerImageProcessor if is_vision_available() else None




							def 						__snake_case					(   self     :   int	):
											lowerCAmelCase__      			=						PoolFormerImageProcessingTester(self	)




							@property
							def 						__snake_case					(   self     :   List[str]	):
											return self.image_processor_tester.prepare_image_processor_dict()




							def 						__snake_case					(   self     :   Union[str, Any]	):
											lowerCAmelCase__      			=						self.image_processing_class(**self.image_processor_dict	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''do_resize_and_center_crop'''	)	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''size'''	)	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''crop_pct'''	)	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''do_normalize'''	)	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''image_mean'''	)	)
											self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,							'''image_std'''	)	)




							def 						__snake_case					(   self     :   List[Any]	):
											lowerCAmelCase__      			=						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}	)

											lowerCAmelCase__      			=						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 						__snake_case					(   self     :   List[str]	):
											pass




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

											# Test batched
											lowerCAmelCase__      			=						image_processing(_SCREAMING_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 						__snake_case					(   self     :   Optional[Any]	):
											lowerCAmelCase__      			=						self.image_processing_class(**self.image_processor_dict	)
											# create random numpy tensors
											lowerCAmelCase__      			=						prepare_image_inputs(self.image_processor_tester ,							equal_resolution=_SCREAMING_SNAKE_CASE ,							numpify=_SCREAMING_SNAKE_CASE	)
											for image in image_inputs:
															self.assertIsInstance(_SCREAMING_SNAKE_CASE ,							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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    ) ,							)

											# Test batched
											lowerCAmelCase__      			=						image_processing(_SCREAMING_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 						__snake_case					(   self     :   List[Any]	):
											lowerCAmelCase__      			=						self.image_processing_class(**self.image_processor_dict	)
											# create random PyTorch tensors
											lowerCAmelCase__      			=						prepare_image_inputs(self.image_processor_tester ,							equal_resolution=_SCREAMING_SNAKE_CASE ,							torchify=_SCREAMING_SNAKE_CASE	)
											for image in image_inputs:
															self.assertIsInstance(_SCREAMING_SNAKE_CASE ,							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.crop_size['''height'''],
											        self.image_processor_tester.crop_size['''width'''],
											    ) ,							)

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













from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader
class  lowerCAmelCase_       (				snake_case__					):




							def __init__(   self     :   str ,							SCREAMING_SNAKE_CASE_     :   pyspark.sql.DataFrame ,							SCREAMING_SNAKE_CASE_     :   Optional[NamedSplit] = None ,							SCREAMING_SNAKE_CASE_     :   Optional[Features] = None ,							SCREAMING_SNAKE_CASE_     :   bool = True ,							SCREAMING_SNAKE_CASE_     :   str = None ,							SCREAMING_SNAKE_CASE_     :   bool = False ,							SCREAMING_SNAKE_CASE_     :   str = None ,							SCREAMING_SNAKE_CASE_     :   bool = True ,							SCREAMING_SNAKE_CASE_     :   str = "arrow" ,							**SCREAMING_SNAKE_CASE_     :   Optional[Any] ,							):
											super().__init__(
											    split=SCREAMING_SNAKE_CASE_ ,							features=SCREAMING_SNAKE_CASE_ ,							cache_dir=SCREAMING_SNAKE_CASE_ ,							keep_in_memory=SCREAMING_SNAKE_CASE_ ,							streaming=SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_ ,							)
											lowerCAmelCase__      			=						load_from_cache_file
											lowerCAmelCase__      			=						file_format
											lowerCAmelCase__      			=						Spark(
											    df=SCREAMING_SNAKE_CASE_ ,							features=SCREAMING_SNAKE_CASE_ ,							cache_dir=SCREAMING_SNAKE_CASE_ ,							working_dir=SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_ ,							)




							def 						__snake_case					(   self     :   List[str]	):
											if self.streaming:
															return self.builder.as_streaming_dataset(split=self.split	)
											lowerCAmelCase__      			=						None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
											self.builder.download_and_prepare(
											    download_mode=SCREAMING_SNAKE_CASE_ ,							file_format=self._file_format ,							)
											return self.builder.as_dataset(split=self.split	)





