

from typing import TYPE_CHECKING

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


__UpperCAmelCase								=			{"""configuration_focalnet""": ["""FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP""", """FocalNetConfig"""]}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __UpperCAmelCase								=			[
       """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

   __UpperCAmelCase								=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





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 MobileViTImageProcessor



class SCREAMING_SNAKE_CASE     (  unittest.TestCase			):
  """simple docstring"""






  def __init__(      self			:   List[Any]	,							lowerCAmelCase			:   List[str]	,							lowerCAmelCase			:   Optional[Any]=7	,							lowerCAmelCase			:   List[str]=3	,							lowerCAmelCase			:   int=18	,							lowerCAmelCase			:   int=30	,							lowerCAmelCase			:   Optional[int]=4_00	,							lowerCAmelCase			:   Optional[Any]=True	,							lowerCAmelCase			:   Dict=None	,							lowerCAmelCase			:   List[str]=True	,							lowerCAmelCase			:   Tuple=None	,							lowerCAmelCase			:   Any=True	,							)							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[Any]    =						size if size is not None else {"""shortest_edge""": 20}
     __lowerCAmelCase  :      Any    =						crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
     __lowerCAmelCase  :      str    =						parent
     __lowerCAmelCase  :      List[str]    =						batch_size
     __lowerCAmelCase  :      int    =						num_channels
     __lowerCAmelCase  :      List[str]    =						image_size
     __lowerCAmelCase  :      Optional[int]    =						min_resolution
     __lowerCAmelCase  :      List[str]    =						max_resolution
     __lowerCAmelCase  :      List[Any]    =						do_resize
     __lowerCAmelCase  :      Optional[int]    =						size
     __lowerCAmelCase  :      List[Any]    =						do_center_crop
     __lowerCAmelCase  :      Optional[Any]    =						crop_size
     __lowerCAmelCase  :      int    =						do_flip_channel_order







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






     """simple docstring"""







     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_center_crop": self.do_center_crop,
         "crop_size": self.crop_size,
         "do_flip_channel_order": self.do_flip_channel_order,
     }






@require_torch
@require_vision
class SCREAMING_SNAKE_CASE     (  a_       ,							unittest.TestCase			):
  """simple docstring"""






  lowerCamelCase   :      List[str]										=MobileViTImageProcessor if is_vision_available() else None







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Tuple:






     """simple docstring"""







     __lowerCAmelCase  :      List[str]    =						MobileViTImageProcessingTester(self   )







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Dict:






     """simple docstring"""







     return self.image_processor_tester.prepare_image_processor_dict()







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[Any]    =						self.image_processing_class(**self.image_processor_dict   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_resize"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""size"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_center_crop"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""center_crop"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_flip_channel_order"""   )   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      List[str]    =						self.image_processing_class.from_dict(self.image_processor_dict   )
     self.assertEqual(image_processor.size	,							{"""shortest_edge""": 20}   )
     self.assertEqual(image_processor.crop_size	,							{"""height""": 18, """width""": 18}   )

     __lowerCAmelCase  :      Optional[Any]    =						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 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     int:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Tuple   )							->     List[str]:






     """simple docstring"""







     __lowerCAmelCase  :      Any    =						self.image_processing_class(**self.image_processor_dict   )
     # create random PIL images
     __lowerCAmelCase  :      Union[str, Any]    =						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  :      List[Any]    =						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  :      str    =						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.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)







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






     """simple docstring"""







     __lowerCAmelCase  :      List[Any]    =						self.image_processing_class(**self.image_processor_dict   )
     # create random numpy tensors
     __lowerCAmelCase  :      Any    =						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  :      Optional[Any]    =						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  :      Tuple    =						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.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Any:






     """simple docstring"""







     __lowerCAmelCase  :      Tuple    =						self.image_processing_class(**self.image_processor_dict   )
     # create random PyTorch tensors
     __lowerCAmelCase  :      str    =						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  :      Optional[int]    =						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  :      Tuple    =						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.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)


