def decov_loss(xs):
 x = tf.reshape(xs, [int(xs.get_shape()[0]), (-1)])
 m = tf.reduce_mean(x, 0, True)
 z = tf.expand_dims((x - m), 2)
 corr = tf.reduce_mean(tf.batch_matmul(z, tf.transpose(z, perm=[0, 2, 1])), 0)
 corr_frob_sqr = tf.reduce_sum(tf.square(corr))
 corr_diag_sqr = tf.reduce_sum(tf.square(tf.diag_part(corr)))
 loss = (0.5 * (corr_frob_sqr - corr_diag_sqr))
 return loss

def decov_loss ( xs ) : x = tf . reshape ( xs , [ int ( xs . get_shape ( ) [ 0 ] ) , ( - 1 ) ] ) m = tf . reduce_mean ( x , 0 , True ) z = tf . expand_dims ( ( x - m ) , 2 ) corr = tf . reduce_mean ( tf . batch_matmul ( z , tf . transpose ( z , perm = [ 0 , 2 , 1 ] ) ) , 0 ) corr_frob_sqr = tf . reduce_sum ( tf . square ( corr ) ) corr_diag_sqr = tf . reduce_sum ( tf . square ( tf . diag_part ( corr ) ) ) loss = ( 0.5 * ( corr_frob_sqr - corr_diag_sqr ) ) return loss
decov loss as described in URL reducing overfitting in deep networks by decorrelating representation .