classification/loss/losses.py
def mmd_loss(student, teacher, args=None):
    """
    Maximum Mean Discrepancy Loss (NST Project)
    :param student: feature dictionary
    :param teacher: feature dictionary
    :param args:
    :return:
    """
    losses = []
    assert len(args.mimic_position) == len(args.mimic_lambda)
    for i, p in enumerate(args.mimic_position):
        s = student[p]
        t = teacher[p]
        s = F.normalize(s.view(s.shape[0], s.shape[1], -1), dim=1)              # N, C, H * W
        mmd_s = s.bmm(s.transpose(2, 1))                                        # N, C, C
        mmd_s_mean = mmd_s.pow(2).mean()
        t = F.normalize(t.view(t.shape[0], t.shape[1], -1), dim=1)
        mmd_st = s.bmm(t.transpose(2, 1))
        mmd_st_mean = mmd_st.pow(2).mean()
        loss = mmd_s_mean - 2 * mmd_st_mean
        losses.append(args.mimic_lambda[i] * loss)
    return losses

    Maximum Mean Discrepancy Loss (NST Project)
    :param student: feature dictionary
    :param teacher: feature dictionary
    :param args:
    :return:
    
Maximum Mean Discrepancy Loss (NST Project)
Maximum Mean Discrepancy Loss ( NST Project )
def mmd_loss(student, teacher, args=None):
    losses = []
    assert len(args.mimic_position) == len(args.mimic_lambda)
    for i, p in enumerate(args.mimic_position):
        s = student[p]
        t = teacher[p]
        s = F.normalize(s.view(s.shape[0], s.shape[1], -1), dim=1)              
        mmd_s = s.bmm(s.transpose(2, 1))                                        
        mmd_s_mean = mmd_s.pow(2).mean()
        t = F.normalize(t.view(t.shape[0], t.shape[1], -1), dim=1)
        mmd_st = s.bmm(t.transpose(2, 1))
        mmd_st_mean = mmd_st.pow(2).mean()
        loss = mmd_s_mean - 2 * mmd_st_mean
        losses.append(args.mimic_lambda[i] * loss)
    return losses
def mmd_loss ( student , teacher , args = None ) : losses = [ ] assert len ( args . mimic_position ) == len ( args . mimic_lambda ) for i , p in enumerate ( args . mimic_position ) : s = student [ p ] t = teacher [ p ] s = F . normalize ( s . view ( s . shape [ 0 ] , s . shape [ 1 ] , - 1 ) , dim = 1 ) mmd_s = s . bmm ( s . transpose ( 2 , 1 ) ) mmd_s_mean = mmd_s . pow ( 2 ) . mean ( ) t = F . normalize ( t . view ( t . shape [ 0 ] , t . shape [ 1 ] , - 1 ) , dim = 1 ) mmd_st = s . bmm ( t . transpose ( 2 , 1 ) ) mmd_st_mean = mmd_st . pow ( 2 ) . mean ( ) loss = mmd_s_mean - 2 * mmd_st_mean losses . append ( args . mimic_lambda [ i ] * loss ) return losses
Maximum Mean Discrepancy Loss (NST Project)
Maximum Mean Discrepancy Loss ( NST Project )
"""
    Maximum Mean Discrepancy Loss (NST Project)
    :param student: feature dictionary
    :param teacher: feature dictionary
    :param args:
    :return:
    """ # N, C, H * W # N, C, C
None
student
None
teacher
None
args
None