Ë
    éÓ^jÏ  ã                   óØ   — d Z ddlmZmZmZmZmZmZmZ ddl	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 ddlmZmZ g d¢Z G d	„ d
e
j2                  «      Z G d„ de
j2                  «      Zy)zm PyTorch FX Based Feature Extraction Helpers
Using https://pytorch.org/vision/stable/feature_extraction.html
é    )ÚCallableÚDictÚListÚOptionalÚUnionÚTupleÚTypeN)Únn)	Úcreate_feature_extractorÚget_graph_node_namesÚregister_notrace_moduleÚregister_notrace_functionÚis_notrace_moduleÚis_notrace_functionÚget_notrace_functionsÚget_notrace_modulesÚFormaté   )Ú_get_feature_infoÚ_get_return_layers)
r   r   r   r   r   r   r   r   ÚFeatureGraphNetÚGraphExtractNetc                   ó¤   ‡ — e Zd ZU dZej
                  j                  e   ed<   	 	 	 d
de	j                  deedf   dee   dedef
ˆ fd„Zd	„ Zˆ xZS )r   zX A FX Graph based feature extractor that works with the model feature_info metadata
    Úreturn_dictÚmodelÚout_indices.Úout_mapÚ
output_fmtc                 óö   •— t         ‰| �  «        t        ||«      | _        |�t	        |«      t	        |«      k(  sJ ‚t        |«      | _        t        | j                  |«      }t        ||«      | _	        || _
        y ©N)ÚsuperÚ__init__r   Úfeature_infoÚlenr   r   r   r   Úgraph_moduler   )Úselfr   r   r   r   r   Úreturn_nodesÚ	__class__s          €úc/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/timm/models/_features_fx.pyr"   zFeatureGraphNet.__init__+   sq   ø€ ô 	‰ÑÔÜ-¨e°[ÓAˆÔØÐÜ�w“<¤3 {Ó#3Ò3Ð3Ð3Ü  Ó,ˆŒÜ)¨$×*;Ñ*;¸WÓEˆÜ4°U¸LÓIˆÔØ&ˆÕó    c                 ór   — | j                  |«      }| j                  r|S t        |j                  «       «      S r    )r%   r   ÚlistÚvalues©r&   ÚxÚouts      r)   ÚforwardzFeatureGraphNet.forward<   s1   € Ø×Ñ Ó"ˆØ×ÒØˆJÜ�C—J‘J“LÓ!Ð!r*   )NÚNCHWF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtorchÚjitÚFinalÚboolÚ__annotations__r
   ÚModuler   Úintr   r   Ústrr"   r1   Ú__classcell__©r(   s   @r)   r   r   &   sp   ø… ñà—‘—‘ Ñ&Ó&ð '+Ø$Ø %ñ'à—9‘9ð'ð ˜s C˜x™ð'ð ˜d‘^ð	'ð
 ð'ð õ'ö""r*   r   c            	       óæ   ‡ — e Zd ZU dZej
                  j                  e   ed<   	 	 d	de	j                  deeeef   ee   f   dedefˆ fd„Zdeeej                      ej                   f   fd„Zˆ xZS )
r   aé   A standalone feature extraction wrapper that maps dict -> list or single tensor
    NOTE:
      * one can use feature_extractor directly if dictionary output is desired
      * unlike FeatureGraphNet, this is intended to be used standalone and not with model feature_info
      metadata for builtin feature extraction mode
      * create_feature_extractor can be used directly if dictionary output is acceptable

    Args:
        model: model to extract features from
        return_nodes: node names to return features from (dict or list)
        squeeze_out: if only one output, and output in list format, flatten to single tensor
        return_dict: return as dictionary from extractor with node names as keys, ignores squeeze_out arg
    r   r   r'   Úsqueeze_outc                 ó`   •— t         ‰| �  «        || _        t        ||«      | _        || _        y r    )r!   r"   rB   r   r%   r   )r&   r   r'   rB   r   r(   s        €r)   r"   zGraphExtractNet.__init__S   s/   ø€ ô 	‰ÑÔØ&ˆÔÜ4°U¸LÓIˆÔØ&ˆÕr*   Úreturnc                 ó´   — | j                  |«      }| j                  r|S t        |j                  «       «      }| j                  rt        |«      dk(  r|d   S |S )Nr   r   )r%   r   r,   r-   rB   r$   r.   s      r)   r1   zGraphExtractNet.forward_   sQ   € Ø×Ñ Ó"ˆØ×ÒØˆJÜ�3—:‘:“<Ó ˆØ×)Ò)¬c°#«h¸!ªmˆs�1‰vÐDÀÐDr*   )TF)r3   r4   r5   r6   r7   r8   r9   r:   r;   r
   r<   r   r   r>   r   r"   ÚTensorr1   r?   r@   s   @r)   r   r   C   s�   ø… ñð —‘—‘ Ñ&Ó&ð !%Ø %ñ
'à—9‘9ð
'ð    S¨# X¡°°S±	Ð 9Ñ:ð
'ð ð	
'ð
 õ
'ðE˜E $ u§|¡|Ñ"4°e·l±lÐ"BÑC÷ Er*   r   )r6   Útypingr   r   r   r   r   r   r	   r7   r
   Útimm.layersr   r   r   r   r   r   r   r   r   Ú	_featuresr   r   Ú__all__r<   r   r   © r*   r)   ú<module>rL      sY   ðñ÷ F× EÑ Eã Ý ÷
÷ 
õ 
÷ =ò€ô"�b—i‘iô "ô:!E�b—i‘iõ !Er*   