HYPJUDY / Decouple-SSAD

Decoupling Localization and Classification in Single Shot Temporal Action Detection
https://arxiv.org/abs/1904.07442
MIT License
96 stars 19 forks source link

Inconsistency: about reg loss #7

Closed Rheelt closed 5 years ago

Rheelt commented 5 years ago

Thank you for your contribution! In SSAD, Loss_reg=SL(pred_center-match_center)+SL(pred_width-match_width) But, in your code, loc_loss = abs_smooth(anchors_xmin - match_xmin) + abs_smooth(anchors_xmax - match_xmax). Why do you use it like that? By the way, can you send me the source code of SSAD? Email: rheecoder@gmail.com Thank you very much!

HYPJUDY commented 5 years ago

Hi~ loc_loss = abs_smooth(anchors_xmin - match_xmin) + abs_smooth(anchors_xmax - match_xmax) is directly taken from original SSAD source code without modification. I think this line of code is consistent with the L_loc (the Smooth L1 loss for location offsets) in SSAD paper. Following is the relevant loss code from original SSAD.

def SSAD_loss(anchors_class,anchors_conf,anchors_xmin,anchors_xmax,match_x,match_w,match_labels,match_scores,Train_label,config):

    match_xmin=match_x-match_w/2
    match_xmax=match_x+match_w/2

    pmask=tf.cast(match_scores>0.5,dtype=tf.float32)
    num_positive=tf.reduce_sum(pmask)
    num_entries=tf.cast(tf.shape(match_scores)[0],dtype=tf.float32)

    hmask=match_scores<0.5
    hmask=tf.logical_and(hmask,anchors_conf>0.5)
    hmask=tf.cast(hmask,dtype=tf.float32)
    num_hard=tf.reduce_sum(hmask)

    r_negative=(config.negative_ratio-num_hard/num_positive) * num_positive/(num_entries-num_positive-num_hard)
    r_negative=tf.minimum(r_negative,1)
    nmask=tf.random_uniform([tf.shape(pmask)[0]],dtype=tf.float32)
    nmask = nmask * (1. - pmask)
    nmask = nmask * (1. - hmask)
    nmask = tf.cast(nmask > (1. - r_negative), dtype=tf.float32)

    #class_loss
    weights=pmask+nmask+hmask
    class_loss=tf.nn.softmax_cross_entropy_with_logits(logits=anchors_class,labels=match_labels)   
    class_loss=tf.losses.compute_weighted_loss(class_loss,weights)

    correct_pred = tf.equal(tf.argmax(anchors_class, 1), tf.argmax(match_labels, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_pred, dtype=tf.float32))
    #loc_loss
    weights=pmask
    loc_loss=abs_smooth(anchors_xmin-match_xmin)+abs_smooth(anchors_xmax-match_xmax)
    loc_loss=tf.losses.compute_weighted_loss(loc_loss,weights)

    #conf loss
    weights=pmask+nmask+hmask
    conf_loss=abs_smooth(match_scores-anchors_conf)
    conf_loss=tf.losses.compute_weighted_loss(conf_loss,weights)

    num_p=tf.reduce_sum(nmask)    

    return class_loss,loc_loss,conf_loss,num_p,accuracy

As for the full source code of SSAD, I suggest you to contact the SSAD author. Thanks!

Rheelt commented 5 years ago

Thank you for your prompt reply!