





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







  '''simple docstring'''


  def __init__(		self   :       Optional[int]					,   __a   :       Optional[int]					,   __a   :       List[str]=13					,   __a   :       Optional[Any]=3					,   __a   :       Optional[Any]=224					,   __a   :       str=30					,   __a   :       Optional[Any]=400					,   __a   :       List[Any]=True					,   __a   :       Any=None					,   __a   :       Union[str, Any]=True					,   __a   :       Dict=[0.5, 0.5, 0.5]					,   __a   :       str=[0.5, 0.5, 0.5]					,   )		->				Tuple:
        _UpperCamelCase      :	Any						=       size if size is not None else {"height": 18, "width": 18}
        _UpperCamelCase      :	Dict						=       parent
        _UpperCamelCase      :	Optional[Any]						=       batch_size
        _UpperCamelCase      :	List[Any]						=       num_channels
        _UpperCamelCase      :	Union[str, Any]						=       image_size
        _UpperCamelCase      :	Optional[int]						=       min_resolution
        _UpperCamelCase      :	int						=       max_resolution
        _UpperCamelCase      :	str						=       do_resize
        _UpperCamelCase      :	Tuple						=       size
        _UpperCamelCase      :	int						=       do_normalize
        _UpperCamelCase      :	int						=       image_mean
        _UpperCamelCase      :	Tuple						=       image_std


  def    __SCREAMING_SNAKE_CASE				(		self   :       str	)		->				str:
        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      __SCREAMING_SNAKE_CASE    (						_UpperCamelCase		,  unittest.TestCase   ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:str	     =					ViTImageProcessor if is_vision_available() else None

  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				Dict:
        _UpperCamelCase      :	str						=       EfficientFormerImageProcessorTester(self	)

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]	)		->				List[str]:
        return self.image_proc_tester.prepare_image_processor_dict()

  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				str:
        _UpperCamelCase      :	List[Any]						=       self.image_processing_class(**self.image_processor_dict	)
        self.assertTrue(hasattr(__a					,   "image_mean"	)	)
        self.assertTrue(hasattr(__a					,   "image_std"	)	)
        self.assertTrue(hasattr(__a					,   "do_normalize"	)	)
        self.assertTrue(hasattr(__a					,   "do_resize"	)	)
        self.assertTrue(hasattr(__a					,   "size"	)	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[Any]	)		->				Optional[Any]:
        pass

  def    __SCREAMING_SNAKE_CASE				(		self   :       str	)		->				Dict:
        # Initialize image_processor
        _UpperCamelCase      :	Tuple						=       self.image_processing_class(**self.image_processor_dict	)
        # create random PIL images
        _UpperCamelCase      :	List[str]						=       prepare_image_inputs(self.image_proc_tester					,   equal_resolution=__a	)
        for image in image_inputs:
              self.assertIsInstance(__a					,   Image.Image	)

        # Test not batched input
        _UpperCamelCase      :	Union[str, Any]						=       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
        _UpperCamelCase      :	Any						=       image_processor(__a					,   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    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				Dict:
        # Initialize image_processor
        _UpperCamelCase      :	Optional[Any]						=       self.image_processing_class(**self.image_processor_dict	)
        # create random numpy tensors
        _UpperCamelCase      :	Union[str, Any]						=       prepare_image_inputs(self.image_proc_tester					,   equal_resolution=__a					,   numpify=__a	)
        for image in image_inputs:
              self.assertIsInstance(__a					,   np.ndarray	)

        # Test not batched input
        _UpperCamelCase      :	Optional[Any]						=       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
        _UpperCamelCase      :	Optional[Any]						=       image_processor(__a					,   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    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				Any:
        # Initialize image_processor
        _UpperCamelCase      :	Optional[Any]						=       self.image_processing_class(**self.image_processor_dict	)
        # create random PyTorch tensors
        _UpperCamelCase      :	Optional[int]						=       prepare_image_inputs(self.image_proc_tester					,   equal_resolution=__a					,   torchify=__a	)
        for image in image_inputs:
              self.assertIsInstance(__a					,   torch.Tensor	)

        # Test not batched input
        _UpperCamelCase      :	List[Any]						=       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
        _UpperCamelCase      :	Tuple						=       image_processor(__a					,   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"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase__				  =   logging.get_logger(__name__)

lowerCamelCase__				  =   {
    "hustvl/yolos-small": "https://huggingface.co/hustvl/yolos-small/resolve/main/config.json",
    # See all YOLOS models at https://huggingface.co/models?filter=yolos
}



class      __SCREAMING_SNAKE_CASE    (						_UpperCamelCase   ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:Tuple	     =					"yolos"

  def __init__(		self   :       Dict					,   __a   :       Optional[Any]=768					,   __a   :       List[Any]=12					,   __a   :       Any=12					,   __a   :       List[Any]=3072					,   __a   :       Optional[int]="gelu"					,   __a   :       Dict=0.0					,   __a   :       Optional[Any]=0.0					,   __a   :       Any=0.02					,   __a   :       Optional[int]=1e-1_2					,   __a   :       List[Any]=[512, 864]					,   __a   :       List[str]=16					,   __a   :       str=3					,   __a   :       Optional[Any]=True					,   __a   :       Optional[Any]=100					,   __a   :       List[str]=True					,   __a   :       Any=False					,   __a   :       List[str]=1					,   __a   :       str=5					,   __a   :       Optional[Any]=2					,   __a   :       Tuple=5					,   __a   :       Any=2					,   __a   :       Union[str, Any]=0.1					,   **__a   :       List[str]					,   )		->				List[str]:
        super().__init__(**__a	)

        _UpperCamelCase      :	Dict						=       hidden_size
        _UpperCamelCase      :	Any						=       num_hidden_layers
        _UpperCamelCase      :	str						=       num_attention_heads
        _UpperCamelCase      :	Dict						=       intermediate_size
        _UpperCamelCase      :	List[str]						=       hidden_act
        _UpperCamelCase      :	List[str]						=       hidden_dropout_prob
        _UpperCamelCase      :	str						=       attention_probs_dropout_prob
        _UpperCamelCase      :	Tuple						=       initializer_range
        _UpperCamelCase      :	List[str]						=       layer_norm_eps
        _UpperCamelCase      :	Tuple						=       image_size
        _UpperCamelCase      :	Tuple						=       patch_size
        _UpperCamelCase      :	Dict						=       num_channels
        _UpperCamelCase      :	Any						=       qkv_bias
        _UpperCamelCase      :	str						=       num_detection_tokens
        _UpperCamelCase      :	str						=       use_mid_position_embeddings
        _UpperCamelCase      :	List[str]						=       auxiliary_loss
        # Hungarian matcher
        _UpperCamelCase      :	List[Any]						=       class_cost
        _UpperCamelCase      :	int						=       bbox_cost
        _UpperCamelCase      :	Optional[int]						=       giou_cost
        # Loss coefficients
        _UpperCamelCase      :	List[Any]						=       bbox_loss_coefficient
        _UpperCamelCase      :	str						=       giou_loss_coefficient
        _UpperCamelCase      :	Dict						=       eos_coefficient





class      __SCREAMING_SNAKE_CASE    (						_UpperCamelCase   ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:List[str]	     =					version.parse("1.11"   )

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       str	)		->				Mapping[str, Mapping[int, str]]:
        return OrderedDict(
            [
                ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
            ]	)

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]	)		->				float:
        return 1e-4


  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict	)		->				int:
        return 12
