
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      _UpperCAmelCase				(					unittest.TestCase):
    def __init__(    self						,    snake_case_						,    snake_case_=13						,    snake_case_=3						,    snake_case_=2_24						,    snake_case_=30						,    snake_case_=4_00						,    snake_case_=True						,    snake_case_=None						,    snake_case_=True						,    snake_case_=[0.5, 0.5, 0.5]						,    snake_case_=[0.5, 0.5, 0.5]						,    ):
      _snake_case     :						List[str]						=   size if size is not None else {"height": 18, "width": 18}
      _snake_case     :						str						=   parent
      _snake_case     :						str						=   batch_size
      _snake_case     :						Dict						=   num_channels
      _snake_case     :						Optional[int]						=   image_size
      _snake_case     :						List[Any]						=   min_resolution
      _snake_case     :						int						=   max_resolution
      _snake_case     :						Any						=   do_resize
      _snake_case     :						Dict						=   size
      _snake_case     :						Dict						=   do_normalize
      _snake_case     :						List[str]						=   image_mean
      _snake_case     :						Optional[int]						=   image_std


    def 					lowerCamelCase__	(    self     ):
      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      _UpperCAmelCase				(					_snake_case		,					unittest.TestCase):
    __lowercase							: Tuple  =					ViTImageProcessor if is_vision_available() else None
    def 					lowerCamelCase__	(    self     ):
      _snake_case     :						List[Any]						=   EfficientFormerImageProcessorTester(self     )
    @property
    def 					lowerCamelCase__	(    self     ):
      return self.image_proc_tester.prepare_image_processor_dict()
    def 					lowerCamelCase__	(    self     ):
      _snake_case     :						List[str]						=   self.image_processing_class(**self.image_processor_dict     )
      self.assertTrue(hasattr(snake_case_						,    "image_mean"     )     )
      self.assertTrue(hasattr(snake_case_						,    "image_std"     )     )
      self.assertTrue(hasattr(snake_case_						,    "do_normalize"     )     )
      self.assertTrue(hasattr(snake_case_						,    "do_resize"     )     )
      self.assertTrue(hasattr(snake_case_						,    "size"     )     )
    def 					lowerCamelCase__	(    self     ):
      pass
    def 					lowerCamelCase__	(    self     ):
      # Initialize image_processor
      _snake_case     :						Any						=   self.image_processing_class(**self.image_processor_dict     )
      # create random PIL images
      _snake_case     :						Tuple						=   prepare_image_inputs(self.image_proc_tester						,    equal_resolution=snake_case_     )
      for image in image_inputs:
        self.assertIsInstance(snake_case_						,    Image.Image     )

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

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

      # Test not batched input
      _snake_case     :						Optional[int]						=   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
      _snake_case     :						Dict						=   image_processor(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"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_a      :			Optional[int]					=							logging.get_logger(__name__)

_a      :			List[str]					=							{
    """facebook/convnextv2-tiny-1k-224""": """https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json""",
}






class      _UpperCAmelCase				(					_snake_case		,					_snake_case):
    __lowercase							: List[Any]  =					"""convnextv2"""
    def __init__(    self						,    snake_case_=3						,    snake_case_=4						,    snake_case_=4						,    snake_case_=None						,    snake_case_=None						,    snake_case_="gelu"						,    snake_case_=0.02						,    snake_case_=1E-12						,    snake_case_=0.0						,    snake_case_=2_24						,    snake_case_=None						,    snake_case_=None						,    **snake_case_						,    ):
      super().__init__(**snake_case_     )

      _snake_case     :						Tuple						=   num_channels
      _snake_case     :						Optional[int]						=   patch_size
      _snake_case     :						Tuple						=   num_stages
      _snake_case     :						int						=   [96, 1_92, 3_84, 7_68] if hidden_sizes is None else hidden_sizes
      _snake_case     :						str						=   [3, 3, 9, 3] if depths is None else depths
      _snake_case     :						int						=   hidden_act
      _snake_case     :						Tuple						=   initializer_range
      _snake_case     :						Union[str, Any]						=   layer_norm_eps
      _snake_case     :						Optional[int]						=   drop_path_rate
      _snake_case     :						Union[str, Any]						=   image_size
      _snake_case     :						List[Any]						=   ["stem"] + [F'stage{idx}' for idx in range(1						,    len(self.depths     ) + 1     )]
      _snake_case			,					_snake_case     :						Dict						=   get_aligned_output_features_output_indices(
          out_features=snake_case_						,    out_indices=snake_case_						,    stage_names=self.stage_names     )

