
    ڧgF'              
          d dl Z d dlZd dlZd dl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mZmZmZmZmZmZmZmZ d dlmZ d	d
lmZ g dZe G d d                      Z G d de          Zde defdZ!deee f         dee         fdZ"dedee         fdZ# edej$                  Z%i Z&d!dee          deede%f         gede%f         f         fdZ'	 	 	 d"dee         deee          e df         deee          e df         dee          fdZ(de dedej$        f         fdZ)de dedej$        fd Z*dS )#    N)	dataclass)Enum)partial)	signature)
ModuleType)AnyCallableDictIterableListMappingOptionalSetTypeTypeVarUnion)nn   )load_state_dict_from_url)WeightsEnumWeights	get_modelget_model_builderget_model_weights
get_weightlist_modelsc                   R    e Zd ZU dZeed<   eed<   eeef         ed<   dede	fdZ
dS )	r   a  
    This class is used to group important attributes associated with the pre-trained weights.

    Args:
        url (str): The location where we find the weights.
        transforms (Callable): A callable that constructs the preprocessing method (or validation preset transforms)
            needed to use the model. The reason we attach a constructor method rather than an already constructed
            object is because the specific object might have memory and thus we want to delay initialization until
            needed.
        meta (Dict[str, Any]): Stores meta-data related to the weights of the model and its configuration. These can be
            informative attributes (for example the number of parameters/flops, recipe link/methods used in training
            etc), configuration parameters (for example the `num_classes`) needed to construct the model or important
            meta-data (for example the `classes` of a classification model) needed to use the model.
    url
transformsmetaotherreturnc                    t          |t                    st          S | j        |j        k    rdS | j        |j        k    rdS t          | j        t                    rht          |j        t                    rN| j        j        |j        j        k    o3| j        j        |j        j        k    o| j        j	        |j        j	        k    S | j        |j        k    S )NF)

isinstancer   NotImplementedr   r    r   r   funcargskeywords)selfr!   s     S/var/www/html/ai-engine/env/lib/python3.11/site-packages/torchvision/models/_api.py__eq__zWeights.__eq__)   s     %)) 	"!!8uy  59
""5dow// 	7Ju?OQX4Y4Y 	7$(8(== JO(E,<,AAJO,0@0II ?e&666    N)__name__
__module____qualname____doc__str__annotations__r	   r
   r   boolr+    r,   r*   r   r      sm           
HHH
sCx.7C 7D 7 7 7 7 7 7r,   r   c                       e Zd ZdZededefd            Zdededeeef         fdZ	defdZ
ed	             Zed
             Zed             ZdS )r   aM  
    This class is the parent class of all model weights. Each model building method receives an optional `weights`
    parameter with its associated pre-trained weights. It inherits from `Enum` and its values should be of type
    `Weights`.

    Args:
        value (Weights): The data class entry with the weight information.
    objr"   c                     |pt          |          t          u r%| |                    | j        dz   d                   }n5t	          ||           s%t          d| j         d|j        j         d          |S )N. z(Invalid Weight class provided; expected z but received )typer1   replacer-   r$   	TypeError	__class__)clsr6   s     r*   verifyzWeightsEnum.verifyN   s    ?CyyC#++clS&8"==>S)) ts|tt[^[h[qttt   
r,   r'   kwargsc                 ,    t          | j        g|R i |S N)r   r   )r)   r'   r@   s      r*   get_state_dictzWeightsEnum.get_state_dictY   s"    'B4BBB6BBBr,   c                 .    | j         j         d| j         S )Nr8   )r=   r-   _name_r)   s    r*   __repr__zWeightsEnum.__repr__\   s    .)99DK999r,   c                     | j         j        S rB   )valuer   rF   s    r*   r   zWeightsEnum.url_   s    z~r,   c                     | j         j        S rB   )rI   r   rF   s    r*   r   zWeightsEnum.transformsc   s    z$$r,   c                     | j         j        S rB   )rI   r    rF   s    r*   r    zWeightsEnum.metag   s    zr,   N)r-   r.   r/   r0   classmethodr   r?   r   r1   rC   rG   propertyr   r   r    r4   r,   r*   r   r   D   s               [CC C3 C738;L C C C C:# : : : :   X % % X%   X  r,   r   namer"   c                 B   	 |                      d          \  }}n!# t          $ r t          d|  d          w xY wd                    t          j        t
                   j                             d          dd                   }t          j        |          }|gd t          j	        |t          j
                  D             z   }d}|D ]8}|j                            |d          }|t          |t                    r|} n9|t          d| d          ||         S )	z
    Gets the weights enum value by its full name. Example: "ResNet50_Weights.IMAGENET1K_V1"

    Args:
        name (str): The name of the weight enum entry.

    Returns:
        WeightsEnum: The requested weight enum.
    r8   zInvalid weight name provided: ''.Nc                 ^    g | ]*}|d          j                             d          "|d          +S )   z__init__.py)__file__endswith).0xs     r*   
<listcomp>zget_weight.<locals>.<listcomp>}   sF     % % %Q4=!!-00%	!% % %r,   zThe weight enum 'z0' for the specific method couldn't be retrieved.)split
ValueErrorjoinsysmodulesr-   	importlibimport_moduleinspect
getmembersismodule__dict__get
issubclassr   )	rN   	enum_name
value_namebase_module_namebase_modulemodel_modulesweights_enummpotential_classs	            r*   r   r   l   sK   E $

3	:: E E EC4CCCDDDE xxH 5 > D DS I I#2# NOO)*:;;K M % %#K1ABB% % % M L  *..D99&:o{+S+S&*LEhYhhhiii
##s    9c                 l    t          | t                    rt          |           n| }t          |          S )a  
    Returns the weights enum class associated to the given model.

    Args:
        name (callable or str): The model builder function or the name under which it is registered.

    Returns:
        weights_enum (WeightsEnum): The weights enum class associated with the model.
    )r$   r1   r   _get_enum_from_fn)rN   models     r*   r   r      s4     (2$'<'<Fd###$EU###r,   fnc                    t          |           }d|j        vrt          d          t          |           j        d         j        }d}t	          |t
                    rt          |t                    r|}n8|j        D ]0}t	          |t
                    rt          |t                    r|} n1|t          d          |S )z
    Internal method that gets the weight enum of a specific model builder method.

    Args:
        fn (Callable): The builder method used to create the model.
    Returns:
        WeightsEnum: The requested weight enum.
    weightsz-The method is missing the 'weights' argument.NzjThe WeightsEnum class for the specific method couldn't be retrieved. Make sure the typing info is correct.)	r   
parametersrZ   
annotationr$   r:   re   r   __args__)rq   sigannrk   ts        r*   ro   ro      s     B--C&&HIII
B--
"9
-
8CL#t C!=!=   	 	A!T"" z!['A'A  x
 
 	
 r,   M)bound.c                 d     dt           dt          f         dt           dt          f         f fd}|S )Nrq   .r"   c                 j    n| j         }|t          v rt          d| d          | t          |<   | S )Nz/An entry is already registered under the name 'rP   )r-   BUILTIN_MODELSrZ   )rq   keyrN   s     r*   wrapperzregister_model.<locals>.wrapper   sG    &ddBK.  VsVVVWWW s	r,   )r	   rz   )rN   r   s   ` r*   register_modelr      sH    HS!V$ #q&)9       Nr,   moduleincludeexcludec                      fdt                                           D             }|rQt                      }t          |t                    r|g}|D ]'}|t          t          j        ||                    z  }(n|}|rBt          |t                    r|g}|D ]'}|t          t          j        ||                    z
  }(t          |          S )a  
    Returns a list with the names of registered models.

    Args:
        module (ModuleType, optional): The module from which we want to extract the available models.
        include (str or Iterable[str], optional): Filter(s) for including the models from the set of all models.
            Filters are passed to `fnmatch <https://docs.python.org/3/library/fnmatch.html>`__ to match Unix shell-style
            wildcards. In case of many filters, the results is the union of individual filters.
        exclude (str or Iterable[str], optional): Filter(s) applied after include_filters to remove models.
            Filter are passed to `fnmatch <https://docs.python.org/3/library/fnmatch.html>`__ to match Unix shell-style
            wildcards. In case of many filters, the results is removal of all the models that match any individual filter.

    Returns:
        models (list): A list with the names of available models.
    c                 r    h | ]3\  }}*|j                             dd          d         j        k    1|4S )Nr8   rS   r   )r.   rsplitr-   )rV   kvr   s      r*   	<setcomp>zlist_models.<locals>.<setcomp>   sP       a!,BUBUVY[\B]B]^_B`djdsBsBsBsBsBsr,   )r~   itemssetr$   r1   fnmatchfiltersorted)r   r   r   
all_modelsmodelsinclude_filterexclude_filters   `      r*   r   r      s    (   $**,,  J  55gs## 	 iG% 	N 	NNc'.^"L"LMMMFF	N  Ngs## 	 iG% 	N 	NNc'.^"L"LMMMFF&>>r,   c                     |                                  } 	 t          |          }n # t          $ r t          d|            w xY w|S )z
    Gets the model name and returns the model builder method.

    Args:
        name (str): The name under which the model is registered.

    Returns:
        fn (Callable): The model builder method.
    zUnknown model )lowerr~   KeyErrorrZ   )rN   rq   s     r*   r   r      sY     ::<<D2D! 2 2 20$001112Is	   $ Aconfigc                 0    t          |           } |di |S )a&  
    Gets the model name and configuration and returns an instantiated model.

    Args:
        name (str): The name under which the model is registered.
        **config (Any): parameters passed to the model builder method.

    Returns:
        model (nn.Module): The initialized model.
    r4   )r   )rN   r   rq   s      r*   r   r   	  s#     
4	 	 B2<<<<r,   rB   )NNN)+r   r^   r`   r\   dataclassesr   enumr   	functoolsr   r   typesr   typingr   r	   r
   r   r   r   r   r   r   r   r   torchr   _internally_replaced_utilsr   __all__r   r   r1   r   r   ro   Modulerz   r~   r   r   r   r   r4   r,   r*   <module>r      s         



 ! ! ! ! ! !                         d d d d d d d d d d d d d d d d d d d d d d d d d d       A A A A A A y
x
x ,7 ,7 ,7 ,7 ,7 ,7 ,7 ,7^% % % % %$ % % %P!$S !$[ !$ !$ !$ !$H$E(C-0 $T+5F $ $ $ $( tK'8    B GCry!!! # (HS!V<L;MxX[]^X^O_;_2`     $(/3/3% %Z %8C=#t+,% 8C=#t+,% 
#Y	% % % %PC HS")^$<    $C 3 29      r,   