Exemple #1
0
def build_and_train_conv1_model(inputs, labels, num_of_labels, do_train=True, validation_data=None):
    inputs_transpose, labels_many_to_one, input_len, num_of_features = Utils.convert_to_cnn_inputs_and_labels(inputs,
                                                                                                              labels)
    model = MyModel(input_len=input_len, num_features=num_of_features, num_labels=num_of_labels)
    weights_path = None
    if model_config.continue_train_existing_model:
        weights_path = model_config.model_file_name
    model.build_model("CONV1", [], [], weights_path=weights_path)
    if do_train:
        if validation_data is not None:
            val_inputs_transpose, val_labels_many_to_one, input_len, num_of_features = Utils.convert_to_cnn_inputs_and_labels(
                validation_data[0],
                validation_data[1])
            model.fit(inputs_transpose, labels_many_to_one, model_path=model_config.model_file_name,val_percentage=validation_perc,
                      early_stopping_patience=10, validation_data=(val_inputs_transpose,val_labels_many_to_one), batch_size=batch_size, num_epochs=num_epochs)
        else:
            model.fit(inputs_transpose, labels_many_to_one, model_path=model_config.model_file_name, early_stopping_patience=10,
                  val_percentage=validation_perc, batch_size=batch_size, num_epochs=num_epochs)
    return model
Exemple #2
0
def build_and_train_gru_model(inputs, labels, num_of_labels, do_train=True):
    num_of_features = len(inputs[0][0])
    model = MyModel(input_len=model_config.input_vec_size, num_features=num_of_features, num_labels=num_of_labels)
    if model_config.continue_train_existing_model:
        weights_path = model_config.model_file_name
    if model_config.many_to_many:
        model.build_model("GRU", [350, 300, 250], [0.05, 0.05, 0.05], weights_path)
        if do_train:
            model.fit(inputs, labels, model_path="model", early_stopping_patience=40, val_percentage=validation_perc,
                      batch_size=batch_size, num_epochs=num_epochs)

    else:
        # NOTE: train - many inputs to one label
        labels_many_to_one = Utils.get_many_to_one_labels(labels, num_of_labels)
        model.build_model("GRU_1", [350, 300, 250], [0.05, 0.05, 0.05], weights_path)
        if do_train:
            model.fit(inputs, labels_many_to_one, model_path="model", early_stopping_patience=40, val_percentage=validation_perc,
                  batch_size=batch_size, num_epochs=num_epochs)
    return model
Exemple #3
0
def main():
    audio_path = 'wav_files\\long_dr1_7.wav'
    # NOTE: no overlap in the input vectors frames
    inputs = Utils.audio_to_model_inputs(audio_path,
                                         model_config.input_vec_size)
    inputs_transposed = Utils.convert_to_cnn_inputs(inputs)
    input_len = len(inputs_transposed[0])
    num_of_features = len(inputs_transposed[0][0])
    num_of_labels = PhonesSet.get_num_labels()

    model = MyModel(input_len=input_len,
                    num_features=num_of_features,
                    num_labels=num_of_labels)
    model_file = model_config.model_file_name
    model.build_model("CONV1", [], [], weights_path=model_file)

    thread = threading.Thread(target=send_visemes_to_smartbody,
                              args=(model, inputs_transposed))
    thread.daemon = True  # Daemon thread
    thread.start()

    loader_audio_path = 'wav_files\\long_dr1_7_loader.wav'
    play_wav(loader_audio_path)