interp = np.zeros_like(df_z_anim)
    idx_anim = df_z_anim.index.tolist()
    idx_pos = idx_anim[0::interp_steps]
    if idx_anim[-1] - idx_pos[-1] < interp_steps:
        idx_pos[-1] = idx_anim[-1]

    for i in range(len(idx_pos) - 1):
        interp[idx_pos[i]:idx_pos[i + 1], :] = interpolate(
            df_z_anim.iloc[idx_pos[i], :].values,
            df_z_anim.iloc[idx_pos[i + 1], :].values,
            idx_pos[i + 1] - idx_pos[i])

    interp[idx_pos[-1], :] = df_z_anim.iloc[idx_pos[-1], :].values

    gen_anim = decode(interp, model)
    output_df = pd.DataFrame(columns=joints_names, data=gen_anim)

    # Inverse normalization
    scaler = 'j_scaler_nao_lim_df13_50fps.pkl'
    output_df = inverse_norm(output_df, scaler)
    # Add the time vector
    output_df['time'] = np.linspace(time_lag, (output_df.shape[0] + 1) * fps,
                                    output_df.shape[0])
    # Label for the id
    output_df['id'] = 'GEN_' + anim_id
    # Label for the category
    output_df['category'] = category

    fig = z_anim2dec(df_z_mean, interp, output_df, anim_id)
Пример #2
0
for id_anim in id_list:

    df_single_anim = df_z_cat.loc[df_z_cat['id'] == id_anim, :]
    single_anim_mat = df_single_anim.iloc[:, 0:z_dim].values

    n_tile = max_step - single_anim_mat.shape[0]
    tiled_pad = np.tile(pad_z, (n_tile, 1))
    all_anims_z[i, :single_anim_mat.shape[0], :] = single_anim_mat
    all_anims_z[i, single_anim_mat.shape[0]:, :] = tiled_pad
    i += 1

# Average all the latent_means across the animations in the category
avg_z = np.mean(all_anims_z, axis=0)

# Decode the averaged latent means for this category
x_reconstruction = decode(avg_z, model)

output_df = pd.DataFrame(columns=joints_names, data=x_reconstruction)

# Inverse normalization
scaler = 'j_scaler_nao_lim_df23_50fps.pkl'
output_df = inverse_norm(output_df, scaler)
# Add the time vector
output_df['time'] = np.linspace(0.02, (output_df.shape[0] + 1) * 0.02,
                                output_df.shape[0])

# Label for the id
output_df['id'] = 'Gen_' + category + '_avg_z'

# GRAPH: Plot the encoded animations in the latent space (color-coded per category)
fig1 = plt.figure()
Пример #3
0
ax.set_title('Animations encoded in the latent space')
ax.axis('equal')
ax.axis('square')
ax.legend()
plt.show()

# Decode and normalize
if blend_mode == 'conv':
    blend = conv
elif blend_mode == 'pca':
    blend = pca
elif blend_mode == 'ica':
    blend = ica
elif blend_mode == 'fa':
    blend = fa
elif blend_mode == 'gmm':
    blend = gmm
else:
    print("Cannot understand the mode")

model = load_model(check_model, check_epoch)
dec = decode(blend, model)
df_dec = pd.DataFrame(columns=joints_names, data=dec)
scaler = 'j_scaler_nao_lim_df13_50fps.pkl'
df_dec_norm = inverse_norm(df_dec, scaler)

# Save df
df_dec_norm.to_csv(
    os.path.join(dest,
                 func_anim_id + '_' + emo_anim_id + '_' + blend_mode + '.csv'))
Пример #4
0
# Restore model to get the decoder
model = load_model(check_model, check_epoch)

# Load animation dataset and z_means
df_anim = pd.read_csv(os.path.join(ROOT_PATH, DATA_X_PATH, x_dataset),
                      index_col=0)

df_anim = df_anim[~df_anim.id.str.contains('_tr')]
x = df_anim.drop(columns=['time', 'id', 'category'], inplace=False)

# Encode the animation set x
latent_mean, latent_sigma = encode(x, model)

# Reconstruct animations from their trained latent_mean
x_reconstruction = decode(latent_mean, model)

output_df = pd.DataFrame(columns=joints_names, data=x_reconstruction)

# Inverse normalization
output_df = inverse_norm(output_df, scaler)

output_df['time'] = df_anim['time']
output_df['category'] = df_anim['category']
output_df['id'] = df_anim['id']

dest = os.path.join(ROOT_PATH, DATA_RECO, x_dataset.split('.')[0])

if not os.path.exists(dest):
    os.makedirs(dest)
Пример #5
0
    This is to explore if there is something interested learned by each latent dim (disentanglement).
"""

check_model = '42'
check_epoch = '-200'
fr = 0.06
scaler = 'j_scaler_nao_lim_df13_50fps.pkl'
z_dim = ['l1', 'l2', 'l3']
gen_vae_dir = 'frozen_z_basic'
dest = os.path.join(ROOT_PATH, DATA_SAMP, gen_vae_dir)
model = load_model(check_model, check_epoch)
r = 10
step = 0.1

latent_range = np.arange(-r, r, step)

for z in z_dim:
    # Creates the latent df with z dim equal to latent range and the rest dim equal to zero.
    data = np.zeros([int(2 * r / step), 3])
    df = pd.DataFrame(data, columns=z_dim)
    df[z] = latent_range

    # Decode
    a_dec = decode(df.values, model)
    df_dec = pd.DataFrame(columns=joints_names, data=a_dec)
    df_dec_norm = inverse_norm(df_dec, scaler)

    # Save
    df_dec_norm.to_csv(os.path.join(dest, z + '_var_dec.csv'))
    df.to_csv(os.path.join(dest, z + '_var_z.csv'))
Пример #6
0
df_l1_var = df.iloc[:, :-1]
df_l1_var['l2'] = df.loc[0, 'l2']
df_l1_var['l3'] = df.loc[0, 'l3']

df_l2_var = df.iloc[:, :-1]
df_l2_var['l1'] = df.loc[0, 'l1']
df_l2_var['l3'] = df.loc[0, 'l3']

df_l3_var = df.iloc[:, :-1]
df_l3_var['l1'] = df.loc[0, 'l1']
df_l3_var['l2'] = df.loc[0, 'l2']

# Decode
model = load_model(check_model, check_epoch)
l1_var_dec = decode(df_l1_var.values, model)
df_dec_l1_var = pd.DataFrame(columns=joints_names, data=l1_var_dec)
df_dec_l1_var_norm = inverse_norm(df_dec_l1_var, scaler)

l2_var_dec = decode(df_l2_var.values, model)
df_dec_l2_var = pd.DataFrame(columns=joints_names, data=l2_var_dec)
df_dec_l2_var_norm = inverse_norm(df_dec_l2_var, scaler)

l3_var_dec = decode(df_l3_var.values, model)
df_dec_l3_var = pd.DataFrame(columns=joints_names, data=l3_var_dec)
df_dec_l3_var_norm = inverse_norm(df_dec_l3_var, scaler)

# Save
df_dec_l1_var_norm.to_csv(
    os.path.join(ROOT_PATH, DATA_SAMP, gen_vae_dir,
                 data.split('.')[0] + '_l1_var.csv'))