File size: 1,696 Bytes
d1d6816 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import tensorflow as tf
from keras.layers import Input, Dense, Dropout
from keras.models import Model
from keras.losses import binary_crossentropy
from load_data import read_data
import joblib
import numpy as np
KL = tf.keras.layers
def perceptual_label_predictor():
"""Assemble and return the perceptual_label_predictor."""
mini_input = Input((20,))
p = Dense(20, activation='relu')(mini_input)
p = Dropout(0.2)(p)
p = Dense(16, activation='relu')(p)
p = Dropout(0.2)(p)
p = Dense(5, activation='sigmoid')(p)
style_predictor = Model(mini_input, p)
style_predictor.summary()
return style_predictor
def train_perceptual_label_predictor(perceptual_label_predictor, encoder):
"""Train the perceptual_label_predictor. (Including data loading.)"""
Input_synthetic = read_data("./data/labeled_dataset/synthetic_data")
Input_AU = read_data("./data/external_data/ARTURIA_data")[:100]
AU_labels = joblib.load("./data/labeled_dataset/ARTURIA_labels")
synth_labels = joblib.load("./data/labeled_dataset/synthetic_data_labels")
AU_encode = encoder.predict(Input_AU)[0]
Synth_encode = encoder.predict(Input_synthetic)[0]
perceptual_label_predictor.compile(optimizer='adam', loss=binary_crossentropy)
perceptual_label_predictor.fit(np.vstack([AU_encode, Synth_encode]), np.vstack([AU_labels, synth_labels]), epochs=140, validation_split=0.05, batch_size=16)
perceptual_label_predictor.save(f"./models/new_trained_models/perceptual_label_predictor.h5")
|