
    h&              
       4   d dl Z d dlZd dlZd dlZd dl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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jF                        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jF                  f   fdZ)ded edejF                  fd!Z*y)$    N)IterableMapping)	dataclass)Enum)partial)	signature)
ModuleType)AnyCallableget_argsOptionalTypeVarUnion)nn   )load_state_dict_from_url)WeightsEnumWeights	get_modelget_model_builderget_model_weights
get_weightlist_modelsc                   J    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
y)	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                 F   t        |t              st        S | j                  |j                  k7  ry| j                  |j                  k7  ryt        | j
                  t              rt        |j
                  t              r| j
                  j                  |j
                  j                  k(  xr\ | j
                  j                  |j
                  j                  k(  xr- | j
                  j                  |j
                  j                  k(  S | j
                  |j
                  k(  S )NF)

isinstancer   NotImplementedr   r   r   r   funcargskeywords)selfr   s     U/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/torchvision/models/_api.py__eq__zWeights.__eq__*   s     %)!!88uyy 99

"doow/Ju?O?OQX4Y$$(8(8(=(== JOO((E,<,<,A,AAJOO,,0@0@0I0II ??e&6&666    N)__name__
__module____qualname____doc__str__annotations__r   dictr
   boolr(    r)   r'   r   r      s5     
H
sCx.7C 7D 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y)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                     |qt        |      t        u r$| |j                  | j                  dz   d         }|S t	        ||       s0t        d| j                   d|j                  j                   d      |S )N. z(Invalid Weight class provided; expected z but received )typer.   replacer*   r!   	TypeError	__class__)clsr4   s     r'   verifyzWeightsEnum.verifyO   s}    ?CyC#++cllS&8"=>
 
	  S)>s||nN[^[h[h[q[qZrrst  
r)   r$   kwargsc                 4    t        | j                  g|i |S N)r   r   )r&   r$   r>   s      r'   get_state_dictzWeightsEnum.get_state_dictZ   s    'B4B6BBr)   c                 L    | j                   j                   d| j                   S )Nr6   )r;   r*   _name_r&   s    r'   __repr__zWeightsEnum.__repr__]   s"    ..))*!DKK=99r)   c                 .    | j                   j                  S r@   )valuer   rD   s    r'   r   zWeightsEnum.url`   s    zz~~r)   c                 .    | j                   j                  S r@   )rG   r   rD   s    r'   r   zWeightsEnum.transformsd   s    zz$$$r)   c                 .    | j                   j                  S r@   )rG   r   rD   s    r'   r   zWeightsEnum.metah   s    zzr)   N)r*   r+   r,   r-   classmethodr
   r=   r   r.   rA   rE   propertyr   r   r   r2   r)   r'   r   r   E   s        CC C3 C738;L C:# :   % %  r)   r   namer   c                 n   	 | j                  d      \  }}dj                  t        j                  t
           j
                  j                  d      dd       }t        j                  |      }|gt        j                  |t        j                        D cg c]%  }|d   j                  j                  d      r|d   ' c}z   }d}|D ]5  }|j                  j                  |d      }	|	"t        |	t               s3|	} n |t        d| d	      ||   S # t        $ r t        d|  d      w xY wc c}w )
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.
    r6   zInvalid weight name provided: ''.N   z__init__.pyzThe weight enum 'z0' for the specific method couldn't be retrieved.)split
ValueErrorjoinsysmodulesr*   	importlibimport_moduleinspect
getmembersismodule__file__endswith__dict__get
issubclassr   )
rL   	enum_name
value_namebase_module_namebase_modulexmodel_modulesweights_enummpotential_classs
             r'   r   r   m   sB   E $

3	: xxH 5 > > D DS I#2 NO))*:;K M##K1A1AB%Q4==!!-0 	
!% M L **..D9&:o{+S*L	 ,YK7ghii
##+  E:4&CDDE
%s   D *D2D/c                 R    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!   r.   r   _get_enum_from_fn)rL   models     r'   r   r      s%     (2$'<d#$EU##r)   fnc                 N   t        |       }d|j                  vrt        d      |j                  d   j                  }d}t	        |t
              rt        |t              r|}n5t        |      D ]'  }t	        |t
              st        |t              s%|} n |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   
parametersrR   
annotationr!   r8   r_   r   r   )rl   sigannrf   ts        r'   rj   rj      s     B-C&HII
..
#
.
.CL#tC!= # 	A!T"z!['A 	
 x
 	
 r)   M)bound.c                 P     dt         dt        f   dt         dt        f   f fd}|S )Nrl   .r   c                 h    n| j                   }|t        v rt        d| d      | t        |<   | S )Nz/An entry is already registered under the name 'rN   )r*   BUILTIN_MODELSrR   )rl   keyrL   s     r'   wrapperzregister_model.<locals>.wrapper   s@    &dBKK. NseSUVWW s	r)   )r   rt   )rL   rz   s   ` r'   register_modelr{      s/    HS!V$ #q&)9  Nr)   moduleincludeexcludec                    t         j                         D ch c]6  \  }}| -|j                  j                  dd      d   | j                  k(  s5|8 }}}|rGt               }t        |t              r|g}|D ]$  }|t        t        j                  ||            z  }& n|}|r<t        |t              r|g}|D ]$  }|t        t        j                  ||            z
  }& t        |      S c c}}w )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.
    r6   rP   r   )rx   itemsr+   rsplitr*   setr!   r.   fnmatchfiltersorted)	r|   r}   r~   kv
all_modelsmodelsinclude_filterexclude_filters	            r'   r   r      s    * %**,a!,,BUBUVY[\B]^_B`djdsdsBsJ  5gs#iG% 	NNc'..^"LMMF	N gs#iG% 	NNc'..^"LMMF	N&>#s   6C*C*c                 p    | j                         } 	 t        |    }|S # t        $ r t        d|        w xY w)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 )lowerrx   KeyErrorrR   )rL   rl   s     r'   r   r      sH     ::<D2D! I  2>$0112s   	 5configc                 (    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.
    r2   )r   )rL   r   rl   s      r'   r   r   	  s     
4	 B<<r)   r@   )NNN)+r   rV   rX   rT   collections.abcr   r   dataclassesr   enumr   	functoolsr   r   typesr	   typingr
   r   r   r   r   r   torchr   _internally_replaced_utilsr   __all__r   r   r.   r   r8   r   rj   Modulert   rx   r{   listr   r   r   r2   r)   r'   <module>r      s      
 - !     D D  A y ,7 ,7 ,7^%$ %P!$S !$[ !$H$E(C-0 $T+5F $( tK'8 @ Cryy!# (HS!V<L;MxX[]^X^O_;_2`  $(/3/3%Z %8C=#t+,% 8C=#t+,% 
#Y	%PC HS"))^$< $C 3 299 r)   