コード例 #1
0
def train_bbox_regressor(X, bbox, gt):
    config = Data()
    config.min_overlap = 0.6
    config.delta = 1000
    config.method = 'ridge_reg_chol'

    # get training groundtruth
    Y, O = get_examples(bbox, gt)
    X = X[O > config.min_overlap]
    Y = Y[O > config.min_overlap]

    # add bias
    X = np.c_[X, np.ones([X.shape[0], 1])]

    # center and decorrelate targets
    mu = np.mean(Y, axis=0).reshape(1, -1)
    Y = Y - mu
    S = dot(Y.T, Y) / Y.shape[0]
    D, V = eig(S)
    T = dot(dot(V, diag(1.0 / sqrt(D + 0.001))), V.T)
    T_inv = dot(dot(V, diag(sqrt(D + 0.001))), V.T)
    Y = dot(Y, T)

    model = Data()
    model.mu = mu
    model.T = T
    model.T_inv = T_inv
    model.Beta = np.c_[solve(X, Y[:, 0], config.delta, config.method),
                       solve(X, Y[:, 1], config.delta, config.method),
                       solve(X, Y[:, 2], config.delta, config.method),
                       solve(X, Y[:, 3], config.delta, config.method)]

    # pack
    bbox_reg = Data()
    bbox_reg.model = model
    bbox_reg.config = config
    return bbox_reg