§
    ·¯¸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mZ dd	lmZ dd
lmZmZmZ g d¢ZdZddiZ e j        d¦  «        Z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#dS )$é    N)ÚPath)ÚAnyÚDictÚOptionalÚTupleÚUnion)Ú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)úhf-hubú	local-dirÚhf_hubr   z[a-zA-Z][a-zA-Z0-9+.\-_]+)ú/ú\ú:Ú
model_nameÚreturnc           
      óò  ‡ — ‰                       d¦  «        \  }}}|rt                               |¦  «        s=t          ˆ fd„t          D ¦   «         ¦  «        rt          d‰ › d‰ › d‰ › d�¦  «        ‚d‰ fS |                     ¦   «         }t                               ||¦  «        }|t          vr1t          d|› d	‰ › d
d 
                    t          ¦  «        › d�¦  «        ‚|st          d‰ › d|› d�¦  «        ‚||fS )a½  Parse source and name from potentially prefixed model name.

    Everything after a recognized source prefix is treated as an opaque identifier (a Hugging Face
    Hub repo id or a local filesystem path). It is deliberately not URL parsed, so Windows drive
    letters, UNC paths, and paths containing characters such as '#', '?' or '@' pass through as-is.

    Args:
        model_name: Model name, optionally prefixed with a source, e.g. ``hf-hub:timm/resnet18.a1_in1k``
            or ``local-dir:/path/to/model_folder``.

    Returns:
        Tuple of (source, model_id). Source is None for plain (timm registry) model names.

    Raises:
        ValueError: If a source prefix is present but unknown, or has an empty model id. Also if no prefix
            is present but the name looks like a path or Hub repo id, as falling back to a registry model
            of the same basename would silently load different weights (or drop the repo owner).
    r   c              3   ó    •K  — | ]}|‰v V — Œ	d S ©N© )Ú.0Úcr   s     €úd/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/timm/models/_factory.pyú	<genexpr>z#parse_model_name.<locals>.<genexpr>0   s'   øè è € Ð4Ð4 1ˆq�JˆÐ4Ð4Ð4Ð4Ð4Ð4ó    zModel name 'z^' has no source prefix but looks like a Hugging Face Hub repo id or a local path. Use 'hf-hub:z%' to load from the Hub or 'local-dir:z' to load from a local folder.NzUnknown model source 'z' in model name 'z', valid sources: z, ú.z$' has no model id / path after the 'z
:' prefix.)Ú	partitionÚ_SOURCE_PREFIX_PATTERNÚ	fullmatchÚanyÚ_PATH_CHARSÚ
ValueErrorÚlowerÚ_MODEL_SOURCE_ALIASESÚgetÚ_MODEL_SOURCESÚjoin)r   ÚsourceÚsepÚmodel_ids   `   r$   r   r      sn  ø€ ð& '×0Ò0°Ñ5Ô5Ñ€FˆC�Øð 	 Õ,×6Ò6°vÑ>Ô>ð 	 åÐ4Ð4Ð4Ð4­Ð4Ñ4Ô4Ñ4Ô4ð 	åðM˜zð Mð MØ1;ðMð Mà",ðMð Mð Mñô ð ð
 �ZÐÐà�\Š\‰^Œ^€Få"×&Ò& v¨vÑ6Ô6€FØ•^Ð#Ð#Ýð< Vð <ð <¸jð <ð <Ø#Ÿyšy­Ñ8Ô8ð<ð <ð <ñ
ô 
ð 	
ð ð lÝÐj¨
ÐjÐjÐX^ÐjÐjÐjÑkÔkÐkð �8ÐÐr&   TÚremove_sourcec                 ój   — dt           dt           fd„}|rt          | ¦  «        d         }  || ¦  «        S )z)Return a filename / path safe model name.Únamer   c                 óf   — d                      d„ | D ¦   «         ¦  «                             d¦  «        S )NÚ c              3   óF   K  — | ]}|                      ¦   «         r|nd V — ŒdS )Ú_N)Úisalnum)r"   r#   s     r$   r%   z5safe_model_name.<locals>.make_safe.<locals>.<genexpr>K   s3   è è € Ð?Ð?°Q˜AŸIšI™KœKÐ0�q�q¨SÐ?Ð?Ð?Ð?Ð?Ð?r&   r<   )r2   Úrstrip)r8   s    r$   Ú	make_safez"safe_model_name.<locals>.make_safeJ   s1   € Ø�wŠwÐ?Ð?¸$Ð?Ñ?Ô?Ñ?Ô?×FÒFÀsÑKÔKÐKr&   éÿÿÿÿ)Ústrr   )r   r6   r?   s      r$   r   r   H   sT   € ðL�ð L¥ð Lð Lð Lð Làð 6Ý% jÑ1Ô1°"Ô5ˆ
Øˆ9�ZÑ Ô Ð r&   FÚ
pretrainedÚpretrained_cfgÚpretrained_cfg_overlayÚcheckpoint_pathÚ	cache_dirÚ
scriptableÚ
exportableÚno_jitÚkwargsc	           	      ó�  — d„ |	                      ¦   «         D ¦   «         }	t          | ¦  «        \  }
}|
r‚|r
J d¦   «         ‚|
dk    rt          ||¬¦  «        \  }} }n'|
dk    rt          |¦  «        \  }} }nJ d|
› �¦   «         ‚|r0|                      ¦   «         D ]\  }}|	                     ||¦  «         Œnt          |¦  «        \  } }|r|s|}t          | ¦  «        st          d| z  ¦  «        ‚t          | ¦  «        }t          |||¬	¦  «        5   |d||||d
œ|	¤Ž}ddd¦  «         n# 1 swxY w Y   |rt          ||¦  «         |S )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/`
    ```
    c                 ó   — i | ]
\  }}|®||“ŒS r    r!   )r"   ÚkÚvs      r$   ú
<dictcomp>z create_model.<locals>.<dictcomp>�   s   € Ð?Ð?Ð?‘t�q˜!°°ˆa�°°°r&   zKpretrained_cfg should not be set when sourcing model from Hugging Face Hub.r   )rF   r   FzUnknown model_source zUnknown model (%s))rG   rH   rI   )rB   rC   rD   rF   Nr!   )Úitemsr   r   r   Ú
setdefaultr   r   ÚRuntimeErrorr   r
   r   )r   rB   rC   rD   rE   rF   rG   rH   rI   rJ   Úmodel_sourcer5   Ú
model_argsrM   rN   Úpretrained_tagÚ	create_fnÚmodels                     r$   r   r   Q   s  € ð| @Ð?˜vŸ|š|™~œ~Ð?Ñ?Ô?€Få-¨jÑ9Ô9Ñ€L�(Øð ,Ø!ÐpÐpÐ#pÑpÔpÐ!Ø˜8Ò#Ð#õ 6OØØ#ð6ñ 6ô 6Ñ2ˆN˜J¨
¨
ð ˜[Ò(Ð(Ý5PØñ6ô 6Ñ2ˆN˜J¨
¨
ð AÐ@°,Ð@Ð@Ñ@Ô@�5Øð 	(Ø"×(Ò(Ñ*Ô*ð (ð (‘��1Ø×!Ò! ! QÑ'Ô'Ð'Ð'øå%9¸(Ñ%CÔ%CÑ"ˆ
�NØð 	, .ð 	,à+ˆNå�JÑÔð >ÝÐ/°*Ñ<Ñ=Ô=Ð=å  Ñ,Ô,€IÝ	 Z¸JÈvÐ	VÑ	VÔ	Vð 
ð 
Ø�	ð 
Ø!Ø)Ø#9Øð	
ð 
ð
 ð
ð 
ˆð
ð 
ð 
ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
øøøð 
ð 
ð 
ð 
ð ð 0Ý˜˜Ñ/Ô/Ð/à€Ls   ÄD)Ä)D-Ä0D-)T)FNNNNNNN)$ÚreÚpathlibr   Útypingr   r   r   r   r   Útorchr	   Útimm.layersr
   Ú_helpersr   Ú_hubr   r   Ú_pretrainedr   Ú	_registryr   r   r   Ú__all__r1   r/   Úcompiler)   r,   rA   r   Úboolr   ÚModuler   r!   r&   r$   ú<module>re      sh  ðØ 	€	€	€	Ø Ð Ð Ð Ð Ð Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (Ø %Ð %Ð %Ð %Ð %Ð %Ø HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ &Ð &Ð &Ð &Ð &Ð &Ø GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ Gð BÐ
AÐ
A€ð )€à! 8Ð,Ð à#˜œÐ$@ÑAÔAÐ à€ð+ ð +¨¨x¸¬}¸cÐ/AÔ)Bð +ð +ð +ð +ð\!ð ! ð !°Dð !ÀCð !ð !ð !ð !ð !ØNRØ;?Ø6:Ø04Ø%)Ø%)Ø!%ðið 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ðið ið ið ið ið ir&   