Files
Track-Anything/model/__pycache__/network.cpython-39.pyc

71 lines
5.9 KiB
Plaintext
Raw Normal View History

2023-04-12 08:24:08 +08:00
a
_{3dp<00>@sJdZddlZddlmZddlmZddlTddlTGdd<06>dej<08>Z dS)z<>
This file defines XMem, the highest level nn.Module interface
During training, it is used by trainer.py
During evaluation, it is used by inference_core.py
It further depends on modules.py which gives more detailed implementations of sub-modules
<EFBFBD>N)<01> aggregate)<01>*cs`eZdZd<14>fdd<03> Zddd<06>Zddd<08>Zd d
<EFBFBD>Zdd d <0C>Zd d<0E>Zddd<10>Z ddd<13>Z
<EFBFBD>Z S)<1A>XMemNcs<>t<00><00><01>|<00>|||<03>}|<01>dd<02>|_td|j<04><00><02>t<06>|_t|j |j
|j<04>|_ t d|j <0A>|_t|j |j
<EFBFBD>|_|dur<>|j|dd<07>dS)z<>
model_path/map_location are used in evaluation only
map_location is for converting models saved in cuda to cpu
<20> single_objectFzSingle object mode: iNT)<01>init_as_zero_if_needed)<12>super<65>__init__<5F>init_hyperparameters<72>getr<00>printZ
KeyEncoder<EFBFBD> key_encoderZ ValueEncoder<65> value_dim<69>
hidden_dim<EFBFBD> value_encoderZ KeyProjection<6F>key_dim<69>key_proj<6F>Decoder<65>decoder<65> load_weights<74><05>self<6C>config<69>
model_path<EFBFBD> map_locationZ model_weights<74><01> __class__<5F><00>-/home/gaomingqi/SAM/xmem-sam/model/network.pyrs
z XMem.__init__Tc Cspt|j<01>dkr4d}|jdd<03>\}}|jddd<06>}nt|j<01>dkrHd}nt<03>|<00>|<01>\}}} |<00>|||<03>\}
} } |<04>r`|
j||g|
jd d<00><00>R<00><00>dd<03><02><08>}
| dur<>| j||g| jd d<00><00>R<00><00>dd<03><02><08>} | du<01>r| j||g| jd d<00><00>R<00><00>dd<03><02><08>} |j||g|jd d<00><00>R<00>}|j||g|jd d<00><00>R<00>}| j||g| jd d<00><00>R<00>} |
| | ||| fS)
N<EFBFBD>T<>r<00><00><02> start_dim<69>end_dim<69>F<><46><EFBFBD><EFBFBD><EFBFBD>) <09>len<65>shape<70>flatten<65>NotImplementedErrorr r<00>view<65> transpose<73>
contiguous) r<00>frameZneed_skZneed_ekZ need_reshape<70>b<>t<>f16<31>f8<66>f4<66>key<65> shrinkage<67> selectionrrr<00>
encode_key(s&**
*zXMem.encode_keycs^<00>jd<00><01>dkr4t<01><02><00>fdd<03>t<03><01>D<00>d<01>}n
t<01><04><00>}|<00>|||<03>||<05>\}}||fS)Nr cs:g|]2<>tj<01>dd<00><02>fdd<02>t<02><02>D<00>fddd<05><03>qS)Ncsg|]}<01>|kr|<01>qSrr)<02>.0<EFBFBD>j<><01>irr<00>
<listcomp>M<00>z0XMem.encode_value.<locals>.<listcomp>.<listcomp>r T)<02>dim<69>keepdim)<03>torch<63>sum<75>range)r7<00><02>masks<6B> num_objectsr9rr;Ks
<02> <04>z%XMem.encode_value.<locals>.<listcomp>)r'r?<00>catrA<00>
zeros_liker)rr-Zimage_feat_f16Zh16rC<00>is_deep_update<74>othersZg16rrBr<00> encode_valueHs
<06><02>
zXMem.encode_valuec
Cs^|jdd<02>\}}|jddd<04>}t||||<02>}t||<05>} | j|||jg| jdd<01><00>R<00>} | S)z<>
query_key : B * CK * H * W
query_selection : B * CK * H * W
memory_key : B * CK * T * H * W
memory_shrinkage: B * 1 * T * H * W
memory_value : B * num_objects * CV * T * H * W
Nrr r!<00><><EFBFBD><EFBFBD><EFBFBD>)r'r(Z get_affinityZreadoutr*r )
rZ query_keyZquery_selectionZ
memory_keyZmemory_shrinkageZ memory_value<75>
batch_sizerDZaffinity<74>memoryrrr<00> read_memoryYs 
"zXMem.read_memoryc Csp|jg|<01>|<03>|<02>Rd|i<01>\}}t<01>|<07>}|dur<||}t|ddd<04>\}}|rf|dd<00>dd<00>f}|||fS)N<>h_outr T)r=Z return_logits)rr?<00>sigmoidr) rZmulti_scale_features<65>memory_readoutZ hidden_state<74>selectorrNZstrip_bg<62>logits<74>probrrr<00>segmentks"
z XMem.segmentcOsh|dkr|j|i|<03><01>S|dkr0|j|i|<03><01>S|dkrH|j|i|<03><01>S|dkr`|j|i|<03><01>St<04>dS)Nr6rIrMrT)r6rIrMrTr))r<00>mode<64>args<67>kwargsrrr<00>forwardzsz XMem.forwardcCs4|dur<>tj||d<02>}|djd|_|djd|_d|v|_|jrNd|_n|djdd|_td|j<03>d |j<04>d
|j<06><00><06>n<>d}d |vr<>d |_td |j<03><00><02>n
|d |_d|vr<>d|_td|j<04><00><02>n
|d|_d|vr<>d |_td|j<06><00><02>n
|d|_|jdk|_|j|d <|j|d<|j|d<|S)a
Init three hyperparameters: key_dim, value_dim, and hidden_dim
If model_path is provided, we load these from the model weights
The actual parameters are then updated to the config in-place
Otherwise we load it either from the config or default
N)rzkey_proj.key_proj.weightrz'value_encoder.fuser.block2.conv2.weightz&decoder.hidden_update.transform.weight<68>z1Hyperparameters read from the model weights: C^k=z, C^v=z, C^h=r<00>@z,key_dim not found in config. Set to default r iz.value_dim not found in config. Set to default rz/hidden_dim not found in config. Set to default )r?<00>loadr'rr Zdisable_hiddenrr rrrrr <00>sB
<04><04><04>



 


zXMem.init_hyperparametersFcCs<>t|<01><01><00>D]t}|dkr ||jddkr td<04>tjd||jd<06>}|s`td<07>tj<08> |<04>ntd<08>t<04>
|||gd<02>||<q |<00> |<01>dS) Nzvalue_encoder.conv1.weightr r$z:Converting weights from single object to multiple objects.)rZr <00>r\)<01>devicezRandomly initialized padding.zZero-initialized padding.) <0C>list<73>keysr'r r?<00>zerosr]<00>nn<6E>init<69> orthogonal_rE<00>load_state_dict)r<00>src_dictr<00>kZpadsrrrr<00>szXMem.load_weights)NN)TT)T)NTT)NN)F) <0C>__name__<5F>
__module__<EFBFBD> __qualname__rr6rIrMrTrXr r<00> __classcell__rrrrrs
<00>

2r)
<EFBFBD>__doc__r?<00>torch.nnraZmodel.aggregaterZ model.modulesZmodel.memory_util<69>Modulerrrrr<00><module>s