

'''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 ViTImageProcessor







class 						lowerCAmelCase__   (      unittest.TestCase					):



 """simple docstring"""



 def __init__(		self					:       List[Any]					,							__SCREAMING_SNAKE_CASE					:       int					,							__SCREAMING_SNAKE_CASE					:       Optional[Any]=13					,							__SCREAMING_SNAKE_CASE					:       Dict=3					,							__SCREAMING_SNAKE_CASE					:       List[Any]=224					,							__SCREAMING_SNAKE_CASE					:       List[str]=30					,							__SCREAMING_SNAKE_CASE					:       Tuple=400					,							__SCREAMING_SNAKE_CASE					:       List[str]=True					,							__SCREAMING_SNAKE_CASE					:       Dict=None					,							__SCREAMING_SNAKE_CASE					:       List[str]=True					,							__SCREAMING_SNAKE_CASE					:       List[Any]=[0.5, 0.5, 0.5]					,							__SCREAMING_SNAKE_CASE					:       Dict=[0.5, 0.5, 0.5]					,							)  -> Tuple:


      """simple docstring"""




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


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


      """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__   (      a ,					unittest.TestCase					):



 """simple docstring"""



 lowerCAmelCase__  					=      ViTImageProcessor if is_vision_available() else None
 def       UpperCAmelCase__		(		self					:       Optional[int]			)  -> str:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      EfficientFormerImageProcessorTester(self			)
 @property
 def       UpperCAmelCase__		(		self					:       Optional[int]			)  -> List[str]:


      """simple docstring"""




      return self.image_proc_tester.prepare_image_processor_dict()
 def       UpperCAmelCase__		(		self					:       List[str]			)  -> Tuple:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.image_processing_class(**self.image_processor_dict			)
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,							"""image_mean"""			)			)
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,							"""image_std"""			)			)
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,							"""do_normalize"""			)			)
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,							"""do_resize"""			)			)
      self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE					,							"""size"""			)			)
 def       UpperCAmelCase__		(		self					:       Dict			)  -> str:


      """simple docstring"""




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


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.image_processing_class(**self.image_processor_dict			)
      # create random PIL images
      __SCREAMING_SNAKE_CASE     =      prepare_image_inputs(self.image_proc_tester					,							equal_resolution=__SCREAMING_SNAKE_CASE			)
      for image in image_inputs:
           self.assertIsInstance(__SCREAMING_SNAKE_CASE					,							Image.Image			)

      # Test not batched input
      __SCREAMING_SNAKE_CASE     =      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
      __SCREAMING_SNAKE_CASE     =      image_processor(__SCREAMING_SNAKE_CASE					,							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       UpperCAmelCase__		(		self					:       int			)  -> Union[str, Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.image_processing_class(**self.image_processor_dict			)
      # create random numpy tensors
      __SCREAMING_SNAKE_CASE     =      prepare_image_inputs(self.image_proc_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
      __SCREAMING_SNAKE_CASE     =      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
      __SCREAMING_SNAKE_CASE     =      image_processor(__SCREAMING_SNAKE_CASE					,							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       UpperCAmelCase__		(		self					:       Optional[Any]			)  -> Optional[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      self.image_processing_class(**self.image_processor_dict			)
      # create random PyTorch tensors
      __SCREAMING_SNAKE_CASE     =      prepare_image_inputs(self.image_proc_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
      __SCREAMING_SNAKE_CASE     =      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
      __SCREAMING_SNAKE_CASE     =      image_processor(__SCREAMING_SNAKE_CASE					,							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"""],
          )					,							)









'''simple docstring'''



# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


UpperCAmelCase :       Any			   =     [
    'EAGER',
    'AOT_EAGER',
    'INDUCTOR',
    'NVFUSER',
    'AOT_NVFUSER',
    'AOT_CUDAGRAPHS',
    'OFI',
    'FX2TRT',
    'ONNXRT',
    'IPEX',
]







def    a__       (  a__      ,    a__=None      ,    a__=None      ,    a__=None						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      True
     while ask_again:
          __SCREAMING_SNAKE_CASE     =      input(a__						)
          try:
               if default is not None and len(a__						) == 0:
                    return default
               return convert_value(a__						) if convert_value is not None else result
          except Exception:
               if error_message is not None:
                    print(a__						)







def    a__       (  a__      ,    a__=[]      ,    a__=None      ,    a__=0						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      BulletMenu(a__      ,    a__						)
     __SCREAMING_SNAKE_CASE     =      menu.run(default_choice=a__						)
     return convert_value(a__						) if convert_value is not None else result







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return DynamoBackend(DYNAMO_BACKENDS[value]						).value







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE     =      int(a__						)
     return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]						)







def    a__       (  a__						):




     """simple docstring"""


     return {"yes": True, "no": False}[value.lower()]







class 						lowerCAmelCase__   (      argparse.RawDescriptionHelpFormatter					):



 """simple docstring"""



 def       UpperCAmelCase__		(		self					:       str					,							__SCREAMING_SNAKE_CASE					:       Optional[Any]					,							__SCREAMING_SNAKE_CASE					:       Dict					,							__SCREAMING_SNAKE_CASE					:       Optional[int]					,							__SCREAMING_SNAKE_CASE					:       List[Any]			)  -> Dict:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE     =      super()._format_usage(__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE			)
      __SCREAMING_SNAKE_CASE     =      usage.replace("""<command> [<args>] """					,							""""""			)
      return usage






