

'''simple docstring'''

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_       						=							logging.get_logger(__name__)

A_       						=							{
    """facebook/convnextv2-tiny-1k-224""": """https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json""",
}





class 							_snake_case (       lowercase_	,  lowercase_						):
   _A       :     str       =					'''convnextv2'''
   def __init__( self			:      Dict     ,SCREAMING_SNAKE_CASE__			:      Optional[int]=3     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=4     ,SCREAMING_SNAKE_CASE__			:      int=4     ,SCREAMING_SNAKE_CASE__			:      Dict=None     ,SCREAMING_SNAKE_CASE__			:      Any=None     ,SCREAMING_SNAKE_CASE__			:      Optional[int]="gelu"     ,SCREAMING_SNAKE_CASE__			:      Optional[Any]=0.02     ,SCREAMING_SNAKE_CASE__			:      Union[str, Any]=1e-12     ,SCREAMING_SNAKE_CASE__			:      List[Any]=0.0     ,SCREAMING_SNAKE_CASE__			:      str=224     ,SCREAMING_SNAKE_CASE__			:      Optional[int]=None     ,SCREAMING_SNAKE_CASE__			:      Any=None     ,**SCREAMING_SNAKE_CASE__			:      Tuple     ,):
     super().__init__(**SCREAMING_SNAKE_CASE__							)

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





'''simple docstring'''

import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("9.1.0"):
    A_       						=							{
        "linear": PIL.Image.Resampling.BILINEAR,
        "bilinear": PIL.Image.Resampling.BILINEAR,
        "bicubic": PIL.Image.Resampling.BICUBIC,
        "lanczos": PIL.Image.Resampling.LANCZOS,
        "nearest": PIL.Image.Resampling.NEAREST,
    }
else:
    A_       						=							{
        "linear": PIL.Image.LINEAR,
        "bilinear": PIL.Image.BILINEAR,
        "bicubic": PIL.Image.BICUBIC,
        "lanczos": PIL.Image.LANCZOS,
        "nearest": PIL.Image.NEAREST,
    }





def    A_  ( snake_case ):
  SCREAMING_SNAKE_CASE:Any						      =					(images / 2 + 0.5).clamp(0      ,       1 )
  SCREAMING_SNAKE_CASE:Optional[Any]						      =					images.cpu().permute(0      ,       2      ,       3      ,       1 ).float().numpy()
  SCREAMING_SNAKE_CASE:str						      =					numpy_to_pil(snake_case )
  return images





def    A_  ( snake_case ):
  if images.ndim == 3:
    SCREAMING_SNAKE_CASE:List[str]						      =					images[None, ...]
  SCREAMING_SNAKE_CASE:List[Any]						      =					(images * 255).round().astype("uint8" )
  if images.shape[-1] == 1:
    # special case for grayscale (single channel) images
    SCREAMING_SNAKE_CASE:Any						      =					[Image.fromarray(image.squeeze()      ,       mode="L" ) for image in images]
  else:
    SCREAMING_SNAKE_CASE:int						      =					[Image.fromarray(snake_case ) for image in images]

  return pil_images






