Scheaven
2021-09-18 291deeb1fcf45dbf39a24aa72a213ff3fd6b3405
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
U
t—_¾ã@sddZddlmmZddlmZddlTddlmZm    Z    ddl
m Z e   ¡Gdd    „d    ej ƒƒZdS)
z9
@author:  liaoxingyu
@contact: sherlockliao01@gmail.com
éN)Únn)Ú*)Úweights_init_kaimingÚweights_init_classifieré)ÚREID_HEADS_REGISTRYcs&eZdZ‡fdd„Zddd„Z‡ZS)Ú EmbeddingHeadc     stƒ ¡|jjj}|jjj}|jjj}|jjj}|jjj    }|jjj
}|jjj }|jjj }    |dkrlt ƒ|_nª|dkr‚t d¡|_n”|dkr˜t d¡|_n~|dkrªtƒ|_nl|dkr¼tƒ|_nZ|dkrÎtƒ|_nH|dkràtƒ|_n6|d    krôt ¡|_n"|d
krtƒ|_nt|›d ƒ‚||_g}
|d krH|
 tj||ddd d¡|}|rb|
 t|    |dd¡tj|
Ž|_|dkrŒtj||d d|_ n\|dkr¦t!|||ƒ|_ nB|dkrÀt"|||ƒ|_ n(|dkrÚt#|||ƒ|_ nt|›d ƒ‚|j $t%¡|j  $t&¡dS)NZ fastavgpoolÚavgpoolrÚmaxpoolZgempoolPZgempoolZ
avgmaxpoolZ clipavgpoolÚidentityÚflattenz is not supported!rF)ÚbiasT)Ú bias_freezeÚlinearZ
arcSoftmaxZ circleSoftmaxZ    amSoftmax)'ÚsuperÚ__init__ÚMODELÚBACKBONEZFEAT_DIMÚHEADSZ EMBEDDING_DIMZ NUM_CLASSESZ    NECK_FEATZ
POOL_LAYERZ    CLS_LAYERZ WITH_BNNECKÚNORMÚFastGlobalAvgPool2dÚ
pool_layerrÚAdaptiveAvgPool2dÚAdaptiveMaxPool2dÚGeneralizedMeanPoolingPÚGeneralizedMeanPoolingÚAdaptiveAvgMaxPool2dZClipGlobalAvgPool2dÚIdentityÚFlattenÚKeyErrorÚ    neck_featÚappendÚConv2dÚget_normÚ
SequentialÚ
bottleneckÚLinearÚ
classifierZ
ArcSoftmaxZ CircleSoftmaxZ    AMSoftmaxÚapplyrr) ÚselfÚcfgZfeat_dimÚ embedding_dimÚ num_classesr Z    pool_typeZcls_typeZ with_bnneckÚ    norm_typer%©Ú    __class__©ú"./modeling/heads/embedding_head.pyrs^
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 zEmbeddingHead.__init__NcCsÀ| |¡}| |¡}|d}|js&|S|jjjdkrP| |¡}t ||jj¡}n0| ||¡}|jj    t t 
|¡t 
|jj¡¡}|j dkr”|d}n |j dkr¤|}nt |j ›dƒ‚|||dœS)z1
        See :class:`ReIDHeads.forward`.
        ).rrr&ÚbeforeZafterz% is invalid for MODEL.HEADS.NECK_FEAT)Ú cls_outputsÚpred_class_logitsÚfeatures) rr%Útrainingr'r/Ú__name__ÚFrÚweightÚsÚ    normalizer r)r)r5ÚtargetsZ global_featZbn_featr3r4Zfeatr0r0r1ÚforwardAs*
 
 
  ÿ
 
 
ýzEmbeddingHead.forward)N)r7Ú
__module__Ú __qualname__rr=Ú __classcell__r0r0r.r1rs 0r)Ú__doc__Útorch.nn.functionalrÚ
functionalr8ÚtorchÚlayersZutils.weight_initrrÚbuildrÚregisterÚModulerr0r0r0r1Ú<module>s