Example #1
0
def testpredict():
    landmarks = predict(au)
    assert landmarks.shape == (2, 68)
    with pytest.raises(ValueError):
        predict(au, model=[0])
    with pytest.raises(ValueError):
        predict(au[:-1])
Example #2
0
def test_plot_face():
    # test plotting method
    fx = Fex(
        filename=join(get_test_data_path(), "iMotions_Test_v6.txt"),
        sampling_freq=30,
        detector="FACET",
    )
    fx = fx.read_file()
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    fx = Fex(
        filename=join(get_test_data_path(), "OpenFace_Test.csv"),
        sampling_freq=30,
        detector="OpenFace",
    )
    fx = fx.read_file()
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    fx = Fex(
        filename=join(get_test_data_path(),
                      "sample_affectiva-api-app_output.json"),
        sampling_freq=30,
        detector="Affectiva",
    )
    fx = fx.read_file(orig_cols=False)
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    # test plot in util
    plot_face()
    assert_plot_shape(plt.gca())
    plt.close()

    plot_face(au=au,
              vectorfield={"reference": predict(au2)},
              feature_range=(0, 1))
    assert_plot_shape(plt.gca())
    plt.close()

    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield={"reference": predict(au2)})
    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield=[])
    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield={"noreference": predict(au2)})
Example #3
0
def test_plot_face():
    # test plotting method
    fx = Fex(filename=join(get_test_data_path(), 'iMotions_Test_v6.txt'),
             sampling_freq=30,
             detector='FACET')
    fx = fx.read_file()
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    fx = Fex(filename=join(get_test_data_path(), 'OpenFace_Test.csv'),
             sampling_freq=30,
             detector='OpenFace')
    fx = fx.read_file()
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    fx = Fex(filename=join(get_test_data_path(),
                           'sample_affectiva-api-app_output.json'),
             sampling_freq=30,
             detector='Affectiva')
    fx = fx.read_file(orig_cols=False)
    ax = fx.plot_aus(row_n=0)
    assert_plot_shape(ax)
    plt.close()

    # test plot in util
    plot_face()
    assert_plot_shape(plt.gca())
    plt.close()

    plot_face(au=au, vectorfield={'reference': predict(au2)})
    assert_plot_shape(plt.gca())
    plt.close()

    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield={'reference': predict(au2)})
    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield=[])
    with pytest.raises(ValueError):
        plot_face(model=au, au=au, vectorfield={'noreference': predict(au2)})
Example #4
0
def test_draw_vectorfield():
    draw_vectorfield(reference=predict(au), target=predict(au=au2))
    assert_plot_shape(plt.gca())
    plt.close()
    with pytest.raises(ValueError):
        draw_vectorfield(reference=predict(au).reshape(4, 2 * feature_length),
                         target=predict(au=au2))
    with pytest.raises(ValueError):
        draw_vectorfield(reference=predict(au),
                         target=predict(au=au2).reshape(4, 2 * feature_length))
Example #5
0
def test_draw_lineface():
    landmarks = predict(au)
    draw_lineface(currx=landmarks[0, :], curry=landmarks[1, :])
    assert_plot_shape(plt.gca())
    plt.close()
Example #6
0
plot_face(model=None, ax = axes[0], au = np.zeros(20), color='k', linewidth=1, linestyle='-')
plot_face(model=None, ax = axes[1], au = np.array(au), color='k', linewidth=1, linestyle='-')

## Add a vectorfield with arrows from the changed face back to neutral and vice versa 

from feat.plotting import plot_face, predict
from feat.utils import load_h5
import numpy as np
import matplotlib.pyplot as plt

model = load_h5('pyfeat_aus_to_landmarks.h5')
# Add data activate AU1, and AU12
au = np.array([2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])

# Get neutral landmarks
neutral = predict(np.zeros(len(au)))

# Provide target landmarks and other vector specifications
vectors = {'target': predict(au),
           'reference':  neutral, 'color': 'blue'}

fig, axes = plt.subplots(1,2)
# Plot face where vectorfield goes from neutral to target, with target as final face
plot_face(model = model, ax = axes[0], au = np.array(au), 
            vectorfield = vectors, color='k', linewidth=1, linestyle='-')

# Plot face where vectorfield goes from neutral to target, with neutral as base face
plot_face(model = model, ax = axes[1], au = np.zeros(len(au)), 
            vectorfield = vectors, color='k', linewidth=1, linestyle='-')

## Add muscle heatmaps to the plot
Example #7
0
AUname = [
    1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 23, 24, 25, 26, 28, 43
]
AUdesc = [
    "inner brow raiser", "outer brow raiser", "brow lowerer",
    "upper lid raiser", "cheek raiser", "lid tightener", "nose wrinkler",
    "upper lip raiser", "lip corner puller", "dimpler", "lip corner depressor",
    "chin raiser", "lip puckerer", "lip stretcher", "lip tightener",
    "lip pressor", "lips part", "jaw drop", "lip suck", "eyes closed"
]
df = pd.DataFrame()
for intensity in np.arange(0, 3.1, .5):
    for au in range(20):
        aus = np.zeros(20)
        aus[au] = intensity
        xs, ys = predict(aus)
        AUtitle = f"{AUname[au]}\n" + AUdesc[au]
        _df = pd.DataFrame({
            "xs": xs,
            "ys": ys,
            "coord_id": range(68),
            "intensity": intensity,
            "AU": AUtitle,
            "AUidx": au,
            "color": "k"
        })

        idxs = [17, 23, 29, 39, 46, 53]
        for idx in idxs:
            df1 = _df.iloc[:idx].copy()
            df1.loc[-1] = [np.nan, np.nan, np.nan, intensity, AUtitle, au, "k"]
Example #8
0
Affectiva vectors should be divided by twenty for use with our 'blue' model. 

from feat.plotting import plot_face, predict
import numpy as np
import matplotlib.pyplot as plt



# Add data, AU is ordered as such: 
# AU1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 23, 24, 25, 26, 28, 43

# Activate AU1: Inner brow raiser 
au = np.array([5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

neutral = predict(np.zeros(len(au)))

vectors = {'target': predict(au),
           'reference':  neutral, 'color': 'blue'}

# Plot face
fig, axes = plt.subplots(1,2)
plot_face(model=None, vectorfield = vectors,
          ax = axes[0], au = np.zeros(20), color='k', linewidth=1, linestyle='-')
plot_face(model=None, vectorfield = vectors,
          ax = axes[1], au = np.array(au), color='k', linewidth=1, linestyle='-')

intensity=3
feature_range = (0, 2) 
au = np.array([0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Example #9
0
# Affectiva vectors should be divided by twenty for use with our 'blue' model.

# In[5]:

from feat.plotting import plot_face, predict
import numpy as np
import matplotlib.pyplot as plt

# Add data, AU is ordered as such:
# AU1, 2, 4, 5, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 23, 24, 25, 26, 28, 43

# Activate AU1: Inner brow raiser
au = np.array([5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

neutral = predict(np.zeros(len(au)))

vectors = {'target': predict(au), 'reference': neutral, 'color': 'blue'}

# Plot face
fig, axes = plt.subplots(1, 2)
plot_face(model=None,
          vectorfield=vectors,
          ax=axes[0],
          au=np.zeros(20),
          color='k',
          linewidth=1,
          linestyle='-')
plot_face(model=None,
          vectorfield=vectors,
          ax=axes[1],
Example #10
0
# ## Add a vectorfield with arrows from the changed face back to neutral and vice versa

# In[10]:

from feat.plotting import plot_face, predict
from feat.utils import load_h5
import numpy as np
import matplotlib.pyplot as plt

model = load_h5('pyfeat_aus_to_landmarks.h5')
# Add data activate AU1, and AU12
au = np.array([2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

# Get neutral landmarks
neutral = predict(np.zeros(len(au)))

# Provide target landmarks and other vector specifications
vectors = {'target': predict(au), 'reference': neutral, 'color': 'blue'}

fig, axes = plt.subplots(1, 2)
# Plot face where vectorfield goes from neutral to target, with target as final face
plot_face(model=model,
          ax=axes[0],
          au=np.array(au),
          vectorfield=vectors,
          color='k',
          linewidth=1,
          linestyle='-')

# Plot face where vectorfield goes from neutral to target, with neutral as base face