
    RЦi                         S r SSKJrJrJrJrJrJrJr  SSK	r	SSK	J
r
  SSKJrJrJrJrJrJrJrJrJr  SSKJrJr  / SQr " S	 S
\
R2                  5      r " S S\
R2                  5      rg)zlPyTorch 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                      ^  \ rS rSr% Sr\R                  R                  \   \	S'      SS\
R                  S\\S4   S\\   S\S\4
U 4S	 jjjrS
 rSrU =r$ )r   &   zWA FX Graph based feature extractor that works with the model feature_info metadata
    return_dictmodelout_indices.out_map
output_fmtc                    > [         TU ]  5         [        X5      U l        Ub  [	        U5      [	        U5      :X  d   e[        U5      U l        [        U R                  U5      n[        X5      U l	        XPl
        g N)super__init__r   feature_infolenr   r   r   r   graph_moduler   )selfr   r   r   r   r   return_nodes	__class__s          W/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/timm/models/_features_fx.pyr#   FeatureGraphNet.__init__+   sk     	-eAw<3{#3333 ,)$*;*;WE4UI&    c                 |    U R                  U5      nU R                  (       a  U$ [        UR                  5       5      $ r!   )r&   r   listvaluesr'   xouts      r*   forwardFeatureGraphNet.forward<   s1    "JCJJL!!r,   )r$   r&   r   r   )NNCHWF)__name__
__module____qualname____firstlineno____doc__torchjitFinalbool__annotations__r
   Moduler   intr   r   strr#   r3   __static_attributes____classcell__r)   s   @r*   r   r   &   sz    && '+$ %'99' sCx' d^	'
 ' ' '"" "r,   r   c            	          ^  \ rS rSr% Sr\R                  R                  \   \	S'     SS\
R                  S\\\\4   \\   4   S\S\4U 4S jjjrS\\\R"                     \R"                  4   4S	 jrS
rU =r$ )r   C   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                 Z   > [         TU ]  5         X0l        [        X5      U l        X@l        g r!   )r"   r#   rH   r   r&   r   )r'   r   r(   rH   r   r)   s        r*   r#   GraphExtractNet.__init__S   s)     	&4UI&r,   returnc                     U R                  U5      nU R                  (       a  U$ [        UR                  5       5      nU R                  (       a  [        U5      S:X  a  US   $ U$ )Nr   r   )r&   r   r.   r/   rH   r%   r0   s      r*   r3   GraphExtractNet.forward_   sQ    "J3::< ))c#h!ms1vDDr,   )r&   r   rH   )TF)r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r
   r@   r   r   rB   r   r#   Tensorr3   rC   rD   rE   s   @r*   r   r   C   s     && !% %
'99
'  S#XS	 9:
' 	
'
 
' 
'EE$u||"4ell"BC E Er,   r   )r:   typingr   r   r   r   r   r   r	   r;   r
   timm.layersr   r   r   r   r   r   r   r   r   	_featuresr   r   __all__r@   r   r    r,   r*   <module>rT      sY    F E E  
 
 
 ="bii ":!Ebii !Er,   