Ë
    éÓ^jÂ  ã                   óŠ  — d dl Z d dlmZ d dlmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZmZmZ g d¢Zdedeee   ef   fd„Zddededefd„Z	 	 	 	 	 	 	 	 ddededeeeeeef   ef      deeeef      deeeef      deeeef      dee   dee   dee   dedej>                  fd„Z y)é    N)ÚPath)ÚAnyÚDictÚOptionalÚTupleÚUnion)Úurlsplit)Únn)Úset_layer_configé   )Úload_checkpoint)Úload_model_config_from_hfÚload_model_config_from_path)ÚPretrainedCfg)Úis_modelÚmodel_entrypointÚsplit_model_name_tag)Úparse_model_nameÚsafe_model_nameÚcreate_modelÚ
model_nameÚreturnc                 óz  — | j                  d«      r| j                  dd«      } t        | «      }|j                  dv sJ ‚|j                  dk(  r|j                  |j                  fS |j                  dk(  r|j                  |j                  fS t
        j                  j                  |j                  «      d   } d| fS )z;Parse source and name from potentially prefixed model name.Úhf_hubúhf-hub)Ú r   ú	local-dirr   éÿÿÿÿN)Ú
startswithÚreplacer	   ÚschemeÚpathÚosÚsplit)r   Úparseds     ú_/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/models/_factory.pyr   r      s£   € à×Ñ˜XÔ&à×'Ñ'¨°(Ó;ˆ
Ü�jÓ!€FØ�=‰=Ð7Ñ7Ð7Ð7Ø‡}�}˜Ò à�}‰}˜fŸk™kÐ)Ð)Ø	�‰˜+Ò	%Ø�}‰}˜fŸk™kÐ)Ð)ä—W‘W—]‘] 6§;¡;Ó/°Ñ3ˆ
Ø�ZÐÐó    Úremove_sourcec                 óR   — dt         dt         fd„}|rt        | «      d   }  || «      S )z)Return a filename / path safe model name.Únamer   c                 óP   — dj                  d„ | D «       «      j                  d«      S )Nr   c              3   óD   K  — | ]  }|j                  «       r|nd –— Œ y­w)Ú_N)Úisalnum)Ú.0Úcs     r&   ú	<genexpr>z5safe_model_name.<locals>.make_safe.<locals>.<genexpr>&   s   è ø€ Ò?°Q˜AŸI™IœK‘q¨SÓ0Ñ?ùs   ‚ r-   )ÚjoinÚrstrip)r*   s    r&   Ú	make_safez"safe_model_name.<locals>.make_safe%   s"   € Ø�w‰wÑ?¸$Ô?Ó?×FÑFÀsÓKÐKr'   r   )Ústrr   )r   r(   r4   s      r&   r   r   #   s5   € ðLœð L¤ó LáÜ% jÓ1°"Ñ5ˆ
Ù�ZÓ Ð r'   Ú
pretrainedÚpretrained_cfgÚpretrained_cfg_overlayÚcheckpoint_pathÚ	cache_dirÚ
scriptableÚ
exportableÚno_jitÚkwargsc	           	      óB  — |	j                  «       D �
�ci c]  \  }
}|€Œ	|
|“Œ }	}
}t        | «      \  }}|rl|rJ d«       ‚|dk(  rt        ||¬«      \  }} }n|dk(  rt        |«      \  }} }n
J d|› �«       ‚|r?|j                  «       D ]  \  }
}|	j	                  |
|«       Œ nt        |«      \  } }|r|s|}t        | «      st        d| z  «      ‚t        | «      }t        |||¬«      5   |d
||||d	œ|	¤Ž}ddd«       |rt        |«       S c c}}
w # 1 sw Y   ŒxY w)a­  Create a model.

    Lookup model's entrypoint function and pass relevant args to create a new model.

    Tip:
        **kwargs will be passed through entrypoint fn to ``timm.models.build_model_with_cfg()``
        and then the model class __init__(). kwargs values set to None are pruned before passing.

    Args:
        model_name: Name of model to instantiate.
        pretrained: If set to `True`, load pretrained ImageNet-1k weights.
        pretrained_cfg: Pass in an external pretrained_cfg for model.
        pretrained_cfg_overlay: Replace key-values in base pretrained_cfg with these.
        checkpoint_path: Path of checkpoint to load _after_ the model is initialized.
        cache_dir: Override model cache dir for Hugging Face Hub and Torch checkpoints.
        scriptable: Set layer config so that model is jit scriptable (not working for all models yet).
        exportable: Set layer config so that model is traceable / ONNX exportable (not fully impl/obeyed yet).
        no_jit: Set layer config so that model doesn't utilize jit scripted layers (so far activations only).

    Keyword Args:
        drop_rate (float): Classifier dropout rate for training.
        drop_path_rate (float): Stochastic depth drop rate for training.
        global_pool (str): Classifier global pooling type.

    Example:

    ```py
    >>> from timm import create_model

    >>> # Create a MobileNetV3-Large model with no pretrained weights.
    >>> model = create_model('mobilenetv3_large_100')

    >>> # Create a MobileNetV3-Large model with pretrained weights.
    >>> model = create_model('mobilenetv3_large_100', pretrained=True)
    >>> model.num_classes
    1000

    >>> # Create a MobileNetV3-Large model with pretrained weights and a new head with 10 classes.
    >>> model = create_model('mobilenetv3_large_100', pretrained=True, num_classes=10)
    >>> model.num_classes
    10

    >>> # Create a Dinov2 small model with pretrained weights and save weights in a custom directory.
    >>> model = create_model('vit_small_patch14_dinov2.lvd142m', pretrained=True, cache_dir="/data/my-models")
    >>> # Data will be stored at `/data/my-models/models--timm--vit_small_patch14_dinov2.lvd142m/`
    ```
    NzKpretrained_cfg should not be set when sourcing model from Hugging Face Hub.r   )r:   r   zUnknown model_source zUnknown model (%s))r;   r<   r=   )r6   r7   r8   r:   © )Úitemsr   r   r   Ú
setdefaultr   r   ÚRuntimeErrorr   r   r   )r   r6   r7   r8   r9   r:   r;   r<   r=   r>   ÚkÚvÚmodel_sourceÚmodel_idÚ
model_argsÚpretrained_tagÚ	create_fnÚmodels                     r&   r   r   ,   sn  € ð|  &Ÿ|™|›~×?‘t�q˜!°±ˆa�‰dÐ?€FÑ?ä-¨jÓ9Ñ€L�(ÙÙ!ÐpÐ#pÓpÐ!Ø˜8Ò#ô 6OØØ#ô6Ñ2ˆN˜J©
ð ˜[Ò(Ü5PØó6Ñ2ˆN˜J©
ð AÐ1°,°Ð@Ó@�5ÙØ"×(Ñ(Ó*ò (‘��1Ø×!Ñ! ! QÕ'ñ(ô &:¸(Ó%CÑ"ˆ
�NÙ¡.à+ˆNä�JÔÜÐ/°*Ñ<Ó=Ð=ä  Ó,€IÜ	 Z¸JÈvÔ	Vñ 
Ùð 
Ø!Ø)Ø#9Øñ	
ð
 ñ
ˆ÷
ñ Ü˜˜Ô/à€LùóW @÷>
ð 
ús   ”
DŸDÃ)DÄD)T)FNNNNNNN)!r#   Úpathlibr   Útypingr   r   r   r   r   Úurllib.parser	   Útorchr
   Útimm.layersr   Ú_helpersr   Ú_hubr   r   Ú_pretrainedr   Ú	_registryr   r   r   Ú__all__r5   r   Úboolr   ÚModuler   r@   r'   r&   ú<module>rX      sS  ðÛ 	Ý ß 4Õ 4Ý !å å (Ý %ß HÝ &ß GÑ Gò B€ð  ð  ¨¨x¸©}¸cÐ/AÑ)Bó  ñ"! ð !°Dð !ÀCó !ð !ØNRØ;?Ø6:Ø04Ø%)Ø%)Ø!%ñiØðiàðið !  s¨D°°c°©N¸MÐ'IÑ!JÑKðið !)¨¨c°3¨h©Ñ 8ð	ið
 " %¨¨T¨	Ñ"2Ñ3ðið ˜E # t )Ñ,Ñ-ðið ˜T‘Nðið ˜T‘Nðið ˜‘ðið ðið ‡Y�Yôir'   