
    RЦi                        S SK r S SKJr  S SKJrJrJrJrJr  S SK	J
r
  S SKJr  S SKJr  SSKJr  SS	KJrJr  SS
KJr  SSKJrJrJr  / SQrS\S\\\   \4   4S jrSS\S\S\4S jjr        SS\S\S\\\\\\4   \4      S\\\\4      S\\\\4      S\\\\4      S\\   S\\   S\\   S\S\R>                  4S jjr g)    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                    U R                  S5      (       a  U R                  SS5      n [        U 5      nUR                  S;   d   eUR                  S:X  a  UR                  UR                  4$ UR                  S:X  a  UR                  UR                  4$ [
        R                  R                  UR                  5      S   n SU 4$ )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     S/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/models/_factory.pyr   r      s    X&&''(;
j!F==7777}} }}fkk))	+	%}}fkk))WW]]6;;/3
Z    remove_sourcec                 ^    S[         S[         4S jnU(       a  [        U 5      S   n U" U 5      $ )z)Return a filename / path safe model name.namer   c                 P    SR                  S U  5       5      R                  S5      $ )Nr   c              3   R   #    U  H  oR                  5       (       a  UOS v   M     g7f)_N)isalnum).0cs     r&   	<genexpr>5safe_model_name.<locals>.make_safe.<locals>.<genexpr>&   s     ?$QIIKKqS0$s   %'r-   )joinrstrip)r*   s    r&   	make_safe"safe_model_name.<locals>.make_safe%   s"    ww?$??FFsKKr'   r   )strr   )r   r(   r5   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	           	         U	R                  5        V
Vs0 s H  u  pUc  M
  X_M     n	n
n[        U 5      u  pU(       as  U(       a   S5       eUS:X  a  [        UUS9u  p nOUS:X  a  [        U5      u  p nO
 SU 35       eU(       a*  UR                  5        H  u  pU	R	                  X5        M     O[        U5      u  pU(       a	  U(       d  Un[        U 5      (       d  [        SU -  5      e[        U 5      n[        XgUS9   U" S
UUUUS	.U	D6nSSS5        U(       a  [        WU5        W$ s  snn
f ! , (       d  f       N)= f)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?   )r8   r9   r:   r<    )itemsr   r   r   
setdefaultr   r   RuntimeErrorr   r   r   )r   r8   r9   r:   r;   r<   r=   r>   r?   r@   kvmodel_sourcemodel_id
model_argspretrained_tag	create_fnmodels                     r&   r   r   ,   sW   |  &||~?~tqdad~F?-j9L!p#pp!8# 6O#62N
 [(5P62N
 A1,@@5"((*!!!' + &:(%C"
.+NJ/*<== ,I	Zv	V 
!)#9	

 
 
W /LW @> 
W	Vs   	D,D,D22
E )T)FNNNNNNN)!r#   pathlibr   typingr   r   r   r   r   urllib.parser	   torchr
   timm.layersr   _helpersr   _hubr   r   _pretrainedr   	_registryr   r   r   __all__r7   r   boolr   Moduler   rB   r'   r&   <module>rZ      sS   	  4 4 !  ( % H & G G B   x}c/A)B  "! !D !C ! !NR;?6:04%)%)!%iii !sDcNM'I!JKi !)c3h 8	i
 "%T	"23i E#t),-i TNi TNi i i YYir'   