yule-li / CosFace

Tensorflow implementation for paper CosFace: Large Margin Cosine Loss for Deep Face Recognition
285 stars 99 forks source link

what is the difference between calculate cosloss using py_func and tf api in utils.py line 104-109? #19

Open xiaowenhe opened 4 years ago

xiaowenhe commented 4 years ago

Hi,I have a question, what is the difference as follows:

implemented by py_func

#value = tf.identity(xw)
#substract the marigin and scale it
value = coco_func(xw_norm,y,alpha) * scale

#implemented by tf api
#margin_xw_norm = xw_norm - alpha
#label_onehot = tf.one_hot(y,num_cls)
#value = scale*tf.where(tf.equal(label_onehot,1), margin_xw_norm, xw_norm)

Implemented by py_func is more complex,you should calculate grad by youself ,and implemented by tf api is simple,only 3 lines. And have any difference between the two?