

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


__lowercase				      =						logging.get_logger(__name__)

__lowercase				      =						{
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}

class    _lowercase				(					__lowerCamelCase,__lowerCamelCase			):
   _lowercase     :       Any  					=    'focalnet'

   def __init__(				self	:    List[str]			,						lowerCamelCase__	:    Any=2_2_4			,						lowerCamelCase__	:    Tuple=4			,						lowerCamelCase__	:    Any=3			,						lowerCamelCase__	:    Dict=9_6			,						lowerCamelCase__	:    Optional[int]=False			,						lowerCamelCase__	:    List[Any]=[1_9_2, 3_8_4, 7_6_8, 7_6_8]			,						lowerCamelCase__	:    int=[2, 2, 6, 2]			,						lowerCamelCase__	:    Dict=[2, 2, 2, 2]			,						lowerCamelCase__	:    Tuple=[3, 3, 3, 3]			,						lowerCamelCase__	:    Optional[Any]="gelu"			,						lowerCamelCase__	:    List[Any]=4.0			,						lowerCamelCase__	:    int=0.0			,						lowerCamelCase__	:    Optional[int]=0.1			,						lowerCamelCase__	:    List[Any]=False			,						lowerCamelCase__	:    Any=1e-4			,						lowerCamelCase__	:    Union[str, Any]=False			,						lowerCamelCase__	:    Tuple=False			,						lowerCamelCase__	:    int=False			,						lowerCamelCase__	:    Tuple=0.02			,						lowerCamelCase__	:    Optional[Any]=1e-5			,						lowerCamelCase__	:    Tuple=3_2			,						lowerCamelCase__	:    Optional[int]=None			,						lowerCamelCase__	:    str=None			,						**lowerCamelCase__	:    List[Any]			,						) ->			str:
         """simple docstring"""





         super().__init__(**_UpperCamelCase       )

         A_							       =		image_size
         A_							       =		patch_size
         A_							       =		num_channels
         A_							       =		embed_dim
         A_							       =		use_conv_embed
         A_							       =		hidden_sizes
         A_							       =		depths
         A_							       =		focal_levels
         A_							       =		focal_windows
         A_							       =		hidden_act
         A_							       =		mlp_ratio
         A_							       =		hidden_dropout_prob
         A_							       =		drop_path_rate
         A_							       =		use_layerscale
         A_							       =		layerscale_value
         A_							       =		use_post_layernorm
         A_							       =		use_post_layernorm_in_modulation
         A_							       =		normalize_modulator
         A_							       =		initializer_range
         A_							       =		layer_norm_eps
         A_							       =		encoder_stride
         A_							       =		['''stem'''] + [F"stage{idx}" for idx in range(1			,						len(self.depths       ) + 1       )]
         A_       ,A_							       =		get_aligned_output_features_output_indices(
             out_features=_UpperCamelCase			,						out_indices=_UpperCamelCase			,						stage_names=self.stage_names       )









'''simple docstring'''
import colorsys

from PIL import Image  # type: ignore

def 					lowerCamelCase_ ( __UpperCamelCase					:       float							,    __UpperCamelCase					:       float							,    __UpperCamelCase					:       int		)					->	float:







     """simple docstring"""
     _A				=							x
     _A				=							y
     for step in range(__UpperCamelCase		):  # noqa: B007
          _A				=							a * a - b * b + x
          _A				=							2 * a * b + y
          _A				=							a_new

          # divergence happens for all complex number with an absolute value
          # greater than 4
          if a * a + b * b > 4:
               break
     return step / (max_step - 1)

def 					lowerCamelCase_ ( __UpperCamelCase					:       float		)					->	tuple:







     """simple docstring"""
     if distance == 1:
          return (0, 0, 0)
     else:
          return (2_5_5, 2_5_5, 2_5_5)

def 					lowerCamelCase_ ( __UpperCamelCase					:       float		)					->	tuple:







     """simple docstring"""
     if distance == 1:
          return (0, 0, 0)
     else:
          return tuple(round(i * 2_5_5		) for i in colorsys.hsv_to_rgb(__UpperCamelCase							,    1							,    1		)		)

def 					lowerCamelCase_ ( __UpperCamelCase					:       int = 8_0_0							,    __UpperCamelCase					:       int = 6_0_0							,    __UpperCamelCase					:       float = -0.6							,    __UpperCamelCase					:       float = 0							,    __UpperCamelCase					:       float = 3.2							,    __UpperCamelCase					:       int = 5_0							,    __UpperCamelCase					:       bool = True							,    )					->	Image.Image:







     """simple docstring"""
     _A				=							Image.new('RGB'							,    (image_width, image_height)		)
     _A				=							img.load()

     # loop through the image-coordinates
     for image_x in range(__UpperCamelCase		):
          for image_y in range(__UpperCamelCase		):
               # determine the figure-coordinates based on the image-coordinates
               _A				=							figure_width / image_width * image_height
               _A				=							figure_center_x + (image_x / image_width - 0.5) * figure_width
               _A				=							figure_center_y + (image_y / image_height - 0.5) * figure_height

               _A				=							get_distance(__UpperCamelCase							,    __UpperCamelCase							,    __UpperCamelCase		)

               # color the corresponding pixel based on the selected coloring-function
               if use_distance_color_coding:
                    _A				=							get_color_coded_rgb(__UpperCamelCase		)
               else:
                    _A				=							get_black_and_white_rgb(__UpperCamelCase		)

     return img


if __name__ == "__main__":
    import doctest

    doctest.testmod()

    # colored version, full figure
    lowerCAmelCase						=					get_image()

    # uncomment for colored version, different section, zoomed in
    # img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
    # figure_width = 0.8)

    # uncomment for black and white version, full figure
    # img = get_image(use_distance_color_coding = False)

    # uncomment to save the image
    # img.save("mandelbrot.png")

    img.show()





