




'''simple docstring'''






import argparse
import json
from pathlib import Path

import requests
import timm
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import AutoImageProcessor, SwinvaConfig, SwinvaForImageClassification






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE		)    ->   List[str]:
      snake_case__       :   str	      =    SwinvaConfig()
      snake_case__       :   Any	      =    swinva_name.split('_'		)

      snake_case__       :   Dict	      =    name_split[1]
      if "to" in name_split[3]:
            snake_case__       :   Optional[int]	      =    int(name_split[3][-3:]		)
      else:
            snake_case__       :   List[str]	      =    int(name_split[3]		)
      if "to" in name_split[2]:
            snake_case__       :   Tuple	      =    int(name_split[2][-2:]		)
      else:
            snake_case__       :   str	      =    int(name_split[2][6:]		)

      if model_size == "tiny":
            snake_case__       :   List[Any]	      =    96
            snake_case__       :   str	      =    (2, 2, 6, 2)
            snake_case__       :   int	      =    (3, 6, 12, 24)
      elif model_size == "small":
            snake_case__       :   str	      =    96
            snake_case__       :   List[Any]	      =    (2, 2, 18, 2)
            snake_case__       :   Optional[Any]	      =    (3, 6, 12, 24)
      elif model_size == "base":
            snake_case__       :   List[Any]	      =    128
            snake_case__       :   Optional[Any]	      =    (2, 2, 18, 2)
            snake_case__       :   List[str]	      =    (4, 8, 16, 32)
      else:
            snake_case__       :   List[str]	      =    192
            snake_case__       :   str	      =    (2, 2, 18, 2)
            snake_case__       :   List[str]	      =    (6, 12, 24, 48)

      if "to" in swinva_name:
            snake_case__       :   Tuple	      =    (12, 12, 12, 6)

      if ("22k" in swinva_name) and ("to" not in swinva_name):
            snake_case__       :   str	      =    2_1841
            snake_case__       :   Dict	      =    'huggingface/label-files'
            snake_case__       :   Any	      =    'imagenet-22k-id2label.json'
            snake_case__       :   Union[str, Any]	      =    json.load(open(hf_hub_download(__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE				,      repo_type='dataset'		)				,      'r'		)		)
            snake_case__       :   str	      =    {int(__SCREAMING_SNAKE_CASE		): v for k, v in idalabel.items()}
            snake_case__       :   Optional[Any]	      =    idalabel
            snake_case__       :   Tuple	      =    {v: k for k, v in idalabel.items()}

      else:
            snake_case__       :   Tuple	      =    1000
            snake_case__       :   Any	      =    'huggingface/label-files'
            snake_case__       :   List[str]	      =    'imagenet-1k-id2label.json'
            snake_case__       :   Union[str, Any]	      =    json.load(open(hf_hub_download(__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE				,      repo_type='dataset'		)				,      'r'		)		)
            snake_case__       :   Optional[Any]	      =    {int(__SCREAMING_SNAKE_CASE		): v for k, v in idalabel.items()}
            snake_case__       :   Any	      =    idalabel
            snake_case__       :   Optional[int]	      =    {v: k for k, v in idalabel.items()}

      snake_case__       :   List[str]	      =    img_size
      snake_case__       :   List[Any]	      =    num_classes
      snake_case__       :   Optional[int]	      =    embed_dim
      snake_case__       :   int	      =    depths
      snake_case__       :   List[str]	      =    num_heads
      snake_case__       :   Tuple	      =    window_size

      return config






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE		)    ->   List[str]:
      if "patch_embed.proj" in name:
            snake_case__       :   List[Any]	      =    name.replace('patch_embed.proj'				,      'embeddings.patch_embeddings.projection'		)
      if "patch_embed.norm" in name:
            snake_case__       :   List[str]	      =    name.replace('patch_embed.norm'				,      'embeddings.norm'		)
      if "layers" in name:
            snake_case__       :   Any	      =    'encoder.' + name
      if "attn.proj" in name:
            snake_case__       :   List[str]	      =    name.replace('attn.proj'				,      'attention.output.dense'		)
      if "attn" in name:
            snake_case__       :   int	      =    name.replace('attn'				,      'attention.self'		)
      if "norm1" in name:
            snake_case__       :   Union[str, Any]	      =    name.replace('norm1'				,      'layernorm_before'		)
      if "norm2" in name:
            snake_case__       :   Dict	      =    name.replace('norm2'				,      'layernorm_after'		)
      if "mlp.fc1" in name:
            snake_case__       :   Optional[int]	      =    name.replace('mlp.fc1'				,      'intermediate.dense'		)
      if "mlp.fc2" in name:
            snake_case__       :   List[Any]	      =    name.replace('mlp.fc2'				,      'output.dense'		)
      if "q_bias" in name:
            snake_case__       :   Any	      =    name.replace('q_bias'				,      'query.bias'		)
      if "k_bias" in name:
            snake_case__       :   Optional[int]	      =    name.replace('k_bias'				,      'key.bias'		)
      if "v_bias" in name:
            snake_case__       :   List[Any]	      =    name.replace('v_bias'				,      'value.bias'		)
      if "cpb_mlp" in name:
            snake_case__       :   List[str]	      =    name.replace('cpb_mlp'				,      'continuous_position_bias_mlp'		)
      if name == "norm.weight":
            snake_case__       :   Tuple	      =    'layernorm.weight'
      if name == "norm.bias":
            snake_case__       :   Tuple	      =    'layernorm.bias'

      if "head" in name:
            snake_case__       :   Any	      =    name.replace('head'				,      'classifier'		)
      else:
            snake_case__       :   Any	      =    'swinv2.' + name

      return name






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE		)    ->   Optional[int]:
      for key in orig_state_dict.copy().keys():
            snake_case__       :   List[str]	      =    orig_state_dict.pop(__SCREAMING_SNAKE_CASE		)

            if "mask" in key:
                  continue
            elif "qkv" in key:
                  snake_case__       :   Optional[int]	      =    key.split('.'		)
                  snake_case__       :   List[Any]	      =    int(key_split[1]		)
                  snake_case__       :   Union[str, Any]	      =    int(key_split[3]		)
                  snake_case__       :   Optional[Any]	      =    model.swinva.encoder.layers[layer_num].blocks[block_num].attention.self.all_head_size

                  if "weight" in key:
                        snake_case__       :   Dict	      =    val[:dim, :]
                        snake_case__       :   Tuple	      =    val[dim : dim * 2, :]
                        snake_case__       :   Union[str, Any]	      =    val[-dim:, :]
                  else:
                        snake_case__       :   int	      =    val[:dim]
                        snake_case__       :   Any	      =    val[
                            dim : dim * 2
                        ]
                        snake_case__       :   str	      =    val[-dim:]
            else:
                  snake_case__       :   Tuple	      =    val

      return orig_state_dict






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE		)    ->   Optional[Any]:
      snake_case__       :   Union[str, Any]	      =    timm.create_model(__SCREAMING_SNAKE_CASE				,      pretrained=__SCREAMING_SNAKE_CASE		)
      timm_model.eval()

      snake_case__       :   str	      =    get_swinva_config(__SCREAMING_SNAKE_CASE		)
      snake_case__       :   Optional[int]	      =    SwinvaForImageClassification(__SCREAMING_SNAKE_CASE		)
      model.eval()

      snake_case__       :   Any	      =    convert_state_dict(timm_model.state_dict()				,      __SCREAMING_SNAKE_CASE		)
      model.load_state_dict(__SCREAMING_SNAKE_CASE		)

      snake_case__       :   Tuple	      =    'http://images.cocodataset.org/val2017/000000039769.jpg'

      snake_case__       :   Union[str, Any]	      =    AutoImageProcessor.from_pretrained('microsoft/{}'.format(swinva_name.replace('_'				,      '-'		)		)		)
      snake_case__       :   Tuple	      =    Image.open(requests.get(__SCREAMING_SNAKE_CASE				,      stream=__SCREAMING_SNAKE_CASE		).raw		)
      snake_case__       :   Optional[Any]	      =    image_processor(images=__SCREAMING_SNAKE_CASE				,      return_tensors='pt'		)

      snake_case__       :   List[str]	      =    timm_model(inputs['pixel_values']		)
      snake_case__       :   Optional[int]	      =    model(**__SCREAMING_SNAKE_CASE		).logits

      assert torch.allclose(__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE				,      atol=1E-3		)

      print(f"Saving model {swinva_name} to {pytorch_dump_folder_path}"		)
      model.save_pretrained(__SCREAMING_SNAKE_CASE		)

      print(f"Saving image processor to {pytorch_dump_folder_path}"		)
      image_processor.save_pretrained(__SCREAMING_SNAKE_CASE		)

      model.push_to_hub(
          repo_path_or_name=Path(__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE		)				,      organization='nandwalritik'				,      commit_message='Add model'				,      )


if __name__ == "__main__":
      A_			      =		argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          "--swinv2_name",
          default="swinv2_tiny_patch4_window8_256",
          type=str,
          help="Name of the Swinv2 timm model you'd like to convert.",
      )
      parser.add_argument(
          "--pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model directory."
      )

      A_			      =		parser.parse_args()
      convert_swinva_checkpoint(args.swinva_name, args.pytorch_dump_folder_path)






'''simple docstring'''






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE		)    ->   int:
      if n == 1 or not isinstance(__SCREAMING_SNAKE_CASE				,      __SCREAMING_SNAKE_CASE		):
            return 0
      elif n == 2:
            return 1
      else:
            snake_case__       :   int	      =    [0, 1]
            for i in range(2				,      n + 1		):
                  sequence.append(sequence[i - 1] + sequence[i - 2]		)

            return sequence[n]






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE		)    ->   int:
      snake_case__       :   Optional[int]	      =    0
      snake_case__       :   Dict	      =    2

      while digits < n:
            index += 1
            snake_case__       :   Optional[int]	      =    len(str(fibonacci(__SCREAMING_SNAKE_CASE		)		)		)

      return index






def 		UpperCamelCase__      (		__SCREAMING_SNAKE_CASE = 1000		)    ->   int:
      return fibonacci_digits_index(__SCREAMING_SNAKE_CASE		)


if __name__ == "__main__":
      print(solution(int(str(input()).strip())))
