balancap / SSD-Tensorflow

Single Shot MultiBox Detector in TensorFlow
4.11k stars 1.89k forks source link

why feat_scores > -0.5? #317

Open ylqi007 opened 5 years ago

ylqi007 commented 5 years ago

According to the code:

jaccard = jaccard_with_anchors(bbox)
# Mask: check threshold + scores + no annotations + num_classes.
mask = tf.greater(jaccard, feat_scores)
# mask = tf.logical_and(mask, tf.greater(jaccard, matching_threshold))
mask = tf.logical_and(mask, feat_scores > -0.5)
mask = tf.logical_and(mask, label < num_classes)
  1. All the elements in feat_scores should be 0, therefore all the elements should be greater than -0.5.
  2. All the element in jaccard should be greater than or equal to 0.
    • when the element is greater than 0, which means the groundtruth box has overlap with this anchor;
    • when the element is 0, which means there is no overlap between groundtruth box and this anchor.
  3. mask=tf.greater(jaccard, feat_scores) will select out all the element greater than 0 in jaccard.
  4. mask=tf.logical_and(mask, feat_scores>-0.5), initially all the elements of feat_scores should be 0, and it is always greater than -0.5. I don't understant why feat_scores>-0.5.

@balancap @yjmade I am not sure that my understanding is correct or not. Could you please give me some explanation when you are convenient.

Fighting-JJ commented 5 years ago

up。 Dose it works the same way as "# mask = tf.logical_and(mask, tf.greater(jaccard, matching_threshold))" ?

Fighting-JJ commented 5 years ago

in the loss function: nmask = tf.logical_and(tf.logical_not(pmask), # nmask: negative mask gscores > -0.5) what "gscores > -0.5" means?

ChenhongyiYang commented 5 years ago

I think it's typo and should be 0.5, which is the ignore threshold.

ylqi007 commented 5 years ago

@Fighting-JJ For the first question, I don't think they work in the same way. Because matching_threshold should be a constant value of 0.5, while feat_scores=tf.zeros(shape, dtype=dtype) (https://github.com/balancap/SSD-Tensorflow/blob/master/nets/ssd_common.py#L57), the initial value of feat_scores should be 0, which is clearly different with matching_threshold.

For the second question, pmask is the mask matrix for all positive anchors, which are potentially to have objects, and tf.logical_not(pmask) is all the rest anchors. As for gscore > -0.5, I still don't understand. I don't know why the gscore has negative values. If you understand, could you please explain the reason?

This is my understanding. Sincerely

ylqi007 commented 5 years ago

@ChenhongyiYang I don't know and not sure about that.

Sincerely

Fighting-JJ commented 5 years ago

I think it's typo and should be 0.5, which is the ignore threshold.

There is no way that -0.5 is a typo. I don`t think -0.5 is a typo

YongshengDong commented 5 years ago

I think negative value means there are anchors without annotation...

stpraha commented 5 years ago

I change the -0.5 into 0.5 and it worked

YongshengDong commented 5 years ago

Can you tell me how it worked?The loss becomes lower? 2640062655 邮箱:2640062655@qq.com 签名由 网易邮箱大师 定制 On 03/16/2019 22:57, Stpraha wrote: I change the -0.5 into 0.5 and it worked — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

stpraha commented 5 years ago

Can you tell me how it worked?The loss becomes lower?

I'm trying to write a simple version SSD based on balancap's code. At first I copied this method and my model is not able to be trained. I reviewed this code and changed -0.5 to 0.5, then my model works. If you've reviewed his code, you would find that this line code doesn't work at all. Because feat_scores never less than 0. According to the comments in this code block, it should be 0.5

ylqi007 commented 5 years ago

@stpraha I can understand that the feat_scores new less than 0. What about the accuracy? Does accuracy improve?

Can you get the same result with the author's experiment like the following? image

Sincerely Yunlong

YongshengDong commented 5 years ago

Thanks, At frist, I only focus on the loss function of balancap's code. I don't think 'N' which in loss function should be 'batch size', so I changed it and remain '-5', I found it worked well, the loss and mAP was OK. Now, I may have an another idea. 2640062655 邮箱:2640062655@qq.com 签名由 网易邮箱大师 定制 On 03/16/2019 23:12, Stpraha wrote: Can you tell me how it worked?The loss becomes lower? I'm trying to write a simple version SSD based on balancap's code. At first I copied this method and my model is not able to be trained. I reviewed this code and changed -0.5 to 0.5, then my model works. If you've reviewed his code, you would find that this line code doesn't work at all. Because feat_scores never less than 0. According to the comments in this code block, it should be 0.5 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

stpraha commented 5 years ago

@ylqi007 I haven't test this change on balancap's model. I just tried on my on model (using copied method). The feat_scores is initialized to 0. Then, it will be compared with jaccard score (IoU), and it will be the bigger one. feat_scores = tf.where(mask, jaccard, feat_scores) Jaccard score will never be a negative value.

ylqi007 commented 5 years ago

@stpraha Yes. In my opinion, both the Jaccard score and feat_scores will never be a negative value.

Do you have SSD code which can work? Can you share your code?

Sincerely

lloydnguyen96 commented 5 years ago

Could you please share your code??? stpraha

Rayholle commented 5 years ago

hello, i change -0.5 to a positive value even small enough, but when train some steps the loss of cross_entropy_pos is 0, because there isn't pos anchor, someone can help me what's wrong with this code or repo? thanks all