Esempio n. 1
0
print('Pseudo balancing samples')
balY = pd.DataFrame()
balX = pd.DataFrame()
for AU in labels[au_cols].columns:
    if np.sum(labels[AU] == 1) > min_pos_sample:
        replace = False
    else:
        replace = True
    newSample = labels[labels[AU] > .5].sample(min_pos_sample,
                                               replace=replace,
                                               random_state=0)
    balX = pd.concat([balX, newSample])
    balY = pd.concat([balY, landmarks.loc[newSample.index]])
X = balX[au_cols].values
y = registration(balY.values, neutral)

# Model Accuracy in KFold CV
print("Evaluating model with KFold CV")
n_components = len(au_cols)
kf = KFold(n_splits=3)
scores = []
for train_index, test_index in kf.split(X):
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
    clf = PLSRegression(n_components=n_components, max_iter=2000)
    clf.fit(X_train, y_train)
    scores.append(clf.score(X_test, y_test))
print('3-fold accuracy mean', np.round(np.mean(scores), 2))

# Train real model
Esempio n. 2
0
def test_utils():
    sample = read_openface(join(get_test_data_path(), "OpenFace_Test.csv"))
    lm_cols = ["x_" + str(i) for i in range(0, 68)] + [
        "y_" + str(i) for i in range(0, 68)
    ]
    sample_face = np.array([sample[lm_cols].values[0]])
    registered_lm = registration(sample_face)
    assert registered_lm.shape == (1, 136)

    with pytest.raises(ValueError):
        registration(sample_face, method="badmethod")
    with pytest.raises(TypeError):
        registration(sample_face, method=np.array([1, 2, 3, 4]))
    with pytest.raises(AssertionError):
        registration([sample_face[0]])
    with pytest.raises(AssertionError):
        registration(sample_face[0])
    with pytest.raises(AssertionError):
        registration(sample_face[:, :-1])

    # Test softmax
    assert softmax(0) == 0.5
    # Test badfile.
    with pytest.raises(Exception):
        load_h5("badfile.h5")

    # Test loading of pickled model
    out = load_pickled_model()
    with pytest.raises(Exception):
        load_pickled_model("badfile.pkl")
Esempio n. 3
0
def test_utils():
    sample = read_openface(join(get_test_data_path(), 'OpenFace_Test.csv'))
    lm_cols = ['x_'+str(i) for i in range(0,68)]+['y_'+str(i) for i in range(0,68)]
    sample_face = np.array([sample[lm_cols].as_matrix()[0]])
    registered_lm = registration(sample_face)
    assert(registered_lm.shape==(1,136))

    with pytest.raises(ValueError):
        registration(sample_face, method='badmethod')
    with pytest.raises(TypeError):
        registration(sample_face, method = np.array([1,2,3,4]))
    with pytest.raises(AssertionError):
        registration([sample_face[0]])
    with pytest.raises(AssertionError):
        registration(sample_face[0])
    with pytest.raises(AssertionError):
        registration(sample_face[:,:-1])

    # Test softmax
    assert(softmax(0) == .5)