


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 ViTImageProcessor







class  snake_case_     (unittest.TestCase   ):
					def __init__(   self     :Dict    ,__snake_case     :List[Any]    ,__snake_case     :Optional[Any]=13    ,__snake_case     :Optional[Any]=3    ,__snake_case     :Tuple=2_24    ,__snake_case     :str=30    ,__snake_case     :int=4_00    ,__snake_case     :Optional[Any]=True    ,__snake_case     :List[Any]=None    ,__snake_case     :List[str]=True    ,__snake_case     :List[str]=[0.5, 0.5, 0.5]    ,__snake_case     :Optional[Any]=[0.5, 0.5, 0.5]    ,)      ->					Dict:
												a__    =  size if size is not None else {'''height''': 18, '''width''': 18}
												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 				lowerCamelCase__(   self     :List[str]   )      ->					Optional[int]:
												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  snake_case_     (lowerCamelCase__			,		unittest.TestCase   ):
					UpperCAmelCase__      :					Union[str, Any]					   =    ViTImageProcessor if is_vision_available() else None
					def 				lowerCamelCase__(   self     :Union[str, Any]   )      ->					str:
												a__    =  EfficientFormerImageProcessorTester(self   )
					@property
					def 				lowerCamelCase__(   self     :str   )      ->					str:
												return self.image_proc_tester.prepare_image_processor_dict()
					def 				lowerCamelCase__(   self     :Optional[Any]   )      ->					Any:
												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 				lowerCamelCase__(   self     :Union[str, Any]   )      ->					List[Any]:
												pass
					def 				lowerCamelCase__(   self     :int   )      ->					List[str]:
												a__    =  self.image_processing_class(**self.image_processor_dict   )
												# create random PIL images
												a__    =  prepare_image_inputs(self.image_proc_tester    ,equal_resolution=__lowerCamelCase   )
												for image in image_inputs:
																			self.assertIsInstance(__lowerCamelCase    ,Image.Image   )

												# Test not batched input
												a__    =  image_processor(image_inputs[0]    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        1,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)

												# Test batched
												a__    =  image_processor(__lowerCamelCase    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        self.image_proc_tester.batch_size,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)
					def 				lowerCamelCase__(   self     :Any   )      ->					Optional[Any]:
												a__    =  self.image_processing_class(**self.image_processor_dict   )
												# create random numpy tensors
												a__    =  prepare_image_inputs(self.image_proc_tester    ,equal_resolution=__lowerCamelCase    ,numpify=__lowerCamelCase   )
												for image in image_inputs:
																			self.assertIsInstance(__lowerCamelCase    ,np.ndarray   )

												# Test not batched input
												a__    =  image_processor(image_inputs[0]    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        1,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)

												# Test batched
												a__    =  image_processor(__lowerCamelCase    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        self.image_proc_tester.batch_size,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)



					def 				lowerCamelCase__(   self     :List[Any]   )      ->					Any:
												a__    =  self.image_processing_class(**self.image_processor_dict   )
												# create random PyTorch tensors
												a__    =  prepare_image_inputs(self.image_proc_tester    ,equal_resolution=__lowerCamelCase    ,torchify=__lowerCamelCase   )
												for image in image_inputs:
																			self.assertIsInstance(__lowerCamelCase    ,torch.Tensor   )

												# Test not batched input
												a__    =  image_processor(image_inputs[0]    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        1,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)

												# Test batched
												a__    =  image_processor(__lowerCamelCase    ,return_tensors='pt'   ).pixel_values
												self.assertEqual(
												    encoded_images.shape    ,(
												        self.image_proc_tester.batch_size,
												        self.image_proc_tester.num_channels,
												        self.image_proc_tester.size['height'],
												        self.image_proc_tester.size['width'],
												    )    ,)




from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


snake_case							: Optional[Any]      =   {'''configuration_focalnet''': ['''FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FocalNetConfig''']}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						snake_case							: Optional[int]      =   [
						    '''FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''FocalNetForImageClassification''',
						    '''FocalNetForMaskedImageModeling''',
						    '''FocalNetBackbone''',
						    '''FocalNetModel''',
						    '''FocalNetPreTrainedModel''',
						]

if TYPE_CHECKING:
						from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_focalnet import (
												    FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
												    FocalNetBackbone,
												    FocalNetForImageClassification,
												    FocalNetForMaskedImageModeling,
												    FocalNetModel,
												    FocalNetPreTrainedModel,
												)

else:
						import sys

						snake_case							: Union[str, Any]      =   _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




