a
    d                  
   @   s   d dl Z d dl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 dd	lmZmZmZ g d
ZedddZdeedddZdeeeeeeeef ef  eeeef  eee ee ee dddZdS )    N)AnyDictOptionalUnion)urlsplit)set_layer_config   )load_checkpoint)load_model_config_from_hf)PretrainedCfg)is_modelmodel_entrypointsplit_model_name_tag)parse_model_namesafe_model_namecreate_model)
model_namec                 C   s`   |  dr| dd} t| }|jdv s,J |jdkrB|j|jfS tj|jd } d| fS d S )NZhf_hubhf-hub) timmr   r   )
startswithreplacer   schemepathossplit)r   parsed r   ]/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/timm/models/_factory.pyr      s    

r   T)r   remove_sourcec                 C   s    dd }|rt | d } || S )Nc                 S   s   d dd | D dS )Nr   c                 s   s   | ]}|  r|nd V  qdS )_N)isalnum).0cr   r   r   	<genexpr>        z5safe_model_name.<locals>.make_safe.<locals>.<genexpr>r!   )joinrstrip)namer   r   r   	make_safe   s    z"safe_model_name.<locals>.make_safer   )r   )r   r    r*   r   r   r   r      s    r   Fr   )r   
pretrainedpretrained_cfgpretrained_cfg_overlaycheckpoint_path
scriptable
exportableno_jitc                 K   s   dd |  D }t| \}	} |	dkr@|r2J dt| \}} nt| \} }
|
rX|sX|
}t| sltd|  t| }t|||d& |f |||d|}W d   n1 s0    Y  |rt|| |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.
    </Tip>

    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.
        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
    ```
    c                 S   s   i | ]\}}|d ur||qS )Nr   )r#   kvr   r   r   
<dictcomp>_   r&   z create_model.<locals>.<dictcomp>r   zKpretrained_cfg should not be set when sourcing model from Hugging Face Hub.zUnknown model (%s))r/   r0   r1   )r+   r,   r-   N)	itemsr   r
   r   r   RuntimeErrorr   r   r	   )r   r+   r,   r-   r.   r/   r0   r1   kwargsZmodel_sourceZpretrained_tagZ	create_fnmodelr   r   r   r   &   s,    9$
r   )T)FNNr   NNN)r   typingr   r   r   r   urllib.parser   Ztimm.layersr   Z_helpersr	   Z_hubr
   Z_pretrainedr   	_registryr   r   r   __all__strr   boolr   r   r   r   r   r   <module>   s6          