예제 #1
0
파일: association.py 프로젝트: d-val/TFM
def lossfunction__old1(tr, sub):
    #@Borja(orginal)1

    # Where to create the loss using data from the subject class

    # First simple loss function---------------------------------------
    # Based in simple distance to subject base
    (xt, yt), radius = tr.pf.circle
    (xs, ys), radius = sub.circle

    distance = int(np.sqrt(np.power(xt - xs, 2) + np.power(yt - ys, 2)))

    # Second loss function---------------------------------------------
    # Based in normal probability density function of particles for
    # position and detection size

    (x, y), (h, w), a = sub.rot_box

    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    # optimizacion --> no calcular constantemente mean y std, sino hacerlo antes de entrar aqui
    # loss = -x -y -vx -vy
    loss  = - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0]))) \
        - np.log(normpdf(y, np.mean(p[:, 1]), np.std(p[:, 1]))) \
        - np.log(normpdf(x - p_star[0], np.mean(p[:, 4]), np.std(p[:, 4]))) \
        - np.log(normpdf(y - p_star[1], np.mean(p[:, 5]), np.std(p[:, 5]))) 
        #- np.log(normpdf(sub.h, np.mean(p[:, 4]), np.std(p[:, 4])))

    debug_flag=0
    if debug_flag:
        """
        print '###'
        print normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5]))
        print x
        print y
        """

        """
        print '----'
        print 'x, y, h: %s, %s, %s' % (x, y, sub.h)
        #print 'x: %s' % - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0])))
        print 'vx: %s' % - np.log(normpdf(p_star[0] - x, np.mean(p[:, 4]), np.std(p[:, 4])))
        print 'vy: %s' % - np.log(normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5])))
        print '----'
        """

    return loss, distance
예제 #2
0
def lossfunction__old1(tr, sub):
    #@Borja(orginal)1

    # Where to create the loss using data from the subject class

    # First simple loss function---------------------------------------
    # Based in simple distance to subject base
    (xt, yt), radius = tr.pf.circle
    (xs, ys), radius = sub.circle

    distance = int(np.sqrt(np.power(xt - xs, 2) + np.power(yt - ys, 2)))

    # Second loss function---------------------------------------------
    # Based in normal probability density function of particles for
    # position and detection size

    (x, y), (h, w), a = sub.rot_box

    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    # optimizacion --> no calcular constantemente mean y std, sino hacerlo antes de entrar aqui
    # loss = -x -y -vx -vy
    loss  = - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0]))) \
        - np.log(normpdf(y, np.mean(p[:, 1]), np.std(p[:, 1]))) \
        - np.log(normpdf(x - p_star[0], np.mean(p[:, 4]), np.std(p[:, 4]))) \
        - np.log(normpdf(y - p_star[1], np.mean(p[:, 5]), np.std(p[:, 5])))
    #- np.log(normpdf(sub.h, np.mean(p[:, 4]), np.std(p[:, 4])))

    debug_flag = 0
    if debug_flag:
        """
        print '###'
        print normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5]))
        print x
        print y
        """
        """
        print '----'
        print 'x, y, h: %s, %s, %s' % (x, y, sub.h)
        #print 'x: %s' % - np.log(normpdf(x, np.mean(p[:, 0]), np.std(p[:, 0])))
        print 'vx: %s' % - np.log(normpdf(p_star[0] - x, np.mean(p[:, 4]), np.std(p[:, 4])))
        print 'vy: %s' % - np.log(normpdf(p_star[1] - y, np.mean(p[:, 5]), np.std(p[:, 5])))
        print '----'
        """

    return loss, distance
예제 #3
0
파일: association.py 프로젝트: d-val/TFM
def lossfunction(tr, sub):
    #@CIA june-25-2015

    loss=0
    distance=0
    #----prepare variables
    (x, y), (h, b), a = sub.rot_box
    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    #----obtain loss(tr,sub)
    #--distance(tr,sub)
    sqDistance = np.power(x - p_mean[0], 2) + np.power(y - p_mean[1], 2)
    distance = np.sqrt(sqDistance)
    #--mix of gaussians
    w_star = 0.20
    w_mean = 0.80
    #sigma_mean = 1
    #sigma_star = 1

    """
    TODO
    ----
    cov --> anchura de las particulas en vez de 1
    """

    """
    COLOR_CUBES
    ---
    1 vector de 8 cubos por canal de color BGR
    ---
    SUBJECT (Deteccion)
    b, g, r = sub.rgb_cubes
    TRACKER
    b, g, r = tr.rgb_cubes
    """

    #.for X
    mu_starX = p_star[0] # x_star
    mu_meanX = p_mean[0] # x_mean
    sigma_starX = p_star[3]#/2
    sigma_meanX = p_mean[3]#/2
    lossX = w_star*norm.pdf(x,mu_starX,sigma_starX) + w_mean*norm.pdf(x,mu_meanX,sigma_meanX)
    #.for Y
    mu_starY = p_star[1] # x_star
    mu_meanY = p_mean[1] # x_mean
    sigma_starY = p_star[2]#/2
    sigma_meanY = p_mean[2]#/2
    lossY = w_star*norm.pdf(y,mu_starY,sigma_starY) + w_mean*norm.pdf(y,mu_meanY,sigma_meanY)    #.neglog of joint(X,Y) assuming independence

    # For appareance

    lossApp = cv2.compareHist(tr.rgb_cubes.ravel().astype('float32'),
                          sub.rgb_cubes.ravel().astype('float32'),
                          cv2.cv.CV_COMP_BHATTACHARYYA)
    #print cv2.normalize(sub.rgb_cubes.ravel().astype('float32'))
    #print cv2.normalize(tr.rgb_cubes.ravel().astype('float32'))
    
    loss = - np.log(lossX) - np.log(lossY) + np.log(lossApp)

    if loss == float('Inf') or loss == -float('Inf'):
        loss = 100
    return loss, distance
예제 #4
0
def lossfunction(tr, sub):
    #@CIA june-25-2015

    loss = 0
    distance = 0
    #----prepare variables
    (x, y), (h, b), a = sub.rot_box
    p = tr.pf.p
    p_star = tr.pf.p_star
    p_mean = tr.pf.p_mean

    #----obtain loss(tr,sub)
    #--distance(tr,sub)
    sqDistance = np.power(x - p_mean[0], 2) + np.power(y - p_mean[1], 2)
    distance = np.sqrt(sqDistance)
    #--mix of gaussians
    w_star = 0.20
    w_mean = 0.80
    #sigma_mean = 1
    #sigma_star = 1
    """
    TODO
    ----
    cov --> anchura de las particulas en vez de 1
    """
    """
    COLOR_CUBES
    ---
    1 vector de 8 cubos por canal de color BGR
    ---
    SUBJECT (Deteccion)
    b, g, r = sub.rgb_cubes
    TRACKER
    b, g, r = tr.rgb_cubes
    """

    #.for X
    mu_starX = p_star[0]  # x_star
    mu_meanX = p_mean[0]  # x_mean
    sigma_starX = p_star[3]  #/2
    sigma_meanX = p_mean[3]  #/2
    lossX = w_star * norm.pdf(x, mu_starX, sigma_starX) + w_mean * norm.pdf(
        x, mu_meanX, sigma_meanX)
    #.for Y
    mu_starY = p_star[1]  # x_star
    mu_meanY = p_mean[1]  # x_mean
    sigma_starY = p_star[2]  #/2
    sigma_meanY = p_mean[2]  #/2
    lossY = w_star * norm.pdf(y, mu_starY, sigma_starY) + w_mean * norm.pdf(
        y, mu_meanY, sigma_meanY)  #.neglog of joint(X,Y) assuming independence

    # For appareance

    lossApp = cv2.compareHist(tr.rgb_cubes.ravel().astype('float32'),
                              sub.rgb_cubes.ravel().astype('float32'),
                              cv2.cv.CV_COMP_BHATTACHARYYA)
    #print cv2.normalize(sub.rgb_cubes.ravel().astype('float32'))
    #print cv2.normalize(tr.rgb_cubes.ravel().astype('float32'))

    loss = -np.log(lossX) - np.log(lossY) + np.log(lossApp)

    if loss == float('Inf') or loss == -float('Inf'):
        loss = 100
    return loss, distance