def center_loss(features, label, alfa, nrof_classes):
 nrof_features = features.get_shape()[1]
 centers = tf.get_variable('centers', [nrof_classes, nrof_features], dtype=tf.float32, initializer=tf.constant_initializer(0), trainable=False)
 label = tf.reshape(label, [(-1)])
 centers_batch = tf.gather(centers, label)
 diff = ((1 - alfa) * (centers_batch - features))
 centers = tf.scatter_sub(centers, label, diff)
 loss = tf.nn.l2_loss((features - centers_batch))
 return (loss, centers)

def center_loss ( features , label , alfa , nrof_classes ) : nrof_features = features . get_shape ( ) [ 1 ] centers = tf . get_variable ( 'centers' , [ nrof_classes , nrof_features ] , dtype = tf . float32 , initializer = tf . constant_initializer ( 0 ) , trainable = False ) label = tf . reshape ( label , [ ( - 1 ) ] ) centers_batch = tf . gather ( centers , label ) diff = ( ( 1 - alfa ) * ( centers_batch - features ) ) centers = tf . scatter_sub ( centers , label , diff ) loss = tf . nn . l2_loss ( ( features - centers_batch ) ) return ( loss , centers )
center loss based on the paper "a discriminative feature learning approach for deep face recognition" .