Tencent / tencent-ml-images

Largest multi-label image database; ResNet-101 model; 80.73% top-1 acc on ImageNet
Other
3.05k stars 514 forks source link

About the loss function? #22

Open idealboy opened 5 years ago

idealboy commented 5 years ago

Thank you for your explanation for the loss function, do you have any supplement material about the loss?

I am curious about some code in the loss function, and I found some variables were not changed at all after computation, eg.

non_neg_mask = tf.fill(tf.shape(labels), -1.0, name='non_neg') non_neg_mask = tf.cast(tf.not_equal(labels, non_neg_mask), tf.float32)

because all the value in labels is '0' or '1', and then , the non_neg_mask will be assigned with '1' all ?

And the same case with the variable pos_count, neg_count,

because the pos_count and neg_count were initialized with '0' all, and the pos_curr_count and neg_curr_count were complementary at the same position, then, is pos_count equal to pos_curr_count , and neg_count equal to neg_curr_count * neg_select, after follow computation?

133 pos_count = tf.assign_sub( 134 tf.assign_add(pos_count, pos_curr_count), 135 tf.multiply(pos_count, neg_curr_count)) 136 neg_count = tf.assign_sub( 137 tf.assign_add(neg_count, tf.multiply(neg_curr_count, neg_select)), 138 tf.multiply(neg_count, pos_curr_count))

thank you!

wubaoyuan commented 5 years ago

@idealboy During the training, we down-sample negative samples to ensure that the number of negative samples is not more than 5 times of the number of positive samples, for each class in one mini-batch. Soon, we will release an Arxiv paper to explain the loss function and training process.

dlnlpchenliyu commented 5 years ago

我也有同样的问题。 看论文里面,并没有提到non_neg_mask。看tfrecord.py和tfrecord.sh,labels里的数值都是大于等于0的, non_neg_mask = tf.fill(tf.shape(labels), -1.0, name='non_neg') non_neg_mask = tf.cast(tf.not_equal(labels, non_neg_mask), tf.float32) train.py里这两行代码执行后non_neg_mask里的指应该都是1.0。那么non_neg_mask的作用是啥?