コード例 #1
0
def lstm_example():
    to_flatten = False
    x_train, x_test, y_train, y_test, num_labels = extract_data(
        flatten=to_flatten)
    y_train = np_utils.to_categorical(y_train)
    y_test_train = np_utils.to_categorical(y_test)
    #train the model
    #    print('Starting LSTM')
    #    model = LSTM(input_shape=x_train[0].shape,
    #                 num_classes=num_labels)
    #    print('x shape', x_train[0].shape)
    #    print('num labels',num_labels)
    #
    #    model.train(x_train, y_train, x_test, y_test_train, n_epochs=50)
    #    model.evaluate(x_test, y_test)
    #    model.save_model()

    newmodel = LSTM(input_shape=x_train[0].shape, num_classes=num_labels)
    newmodel.load_model(to_load="./LSTM_best_model.h5")
    newmodel.train(x_train, y_train, x_test, y_test_train, n_epochs=0)

    audio_file = "../dataset/union-interview.wav"

    section_by_section_analysis(model=newmodel,
                                audio_file=audio_file,
                                to_flatten=to_flatten)
コード例 #2
0
ファイル: lstm_example.py プロジェクト: adityaa30/MoodX
def lstm_example():
    to_flatten = False
    x_train, x_test, y_train, y_test, num_labels = extract_data(
        flatten=to_flatten)
    y_train = np_utils.to_categorical(y_train)
    y_test_train = np_utils.to_categorical(y_test)
    print('Starting LSTM')
    model = LSTM(input_shape=x_train[0].shape, num_classes=num_labels)
    model.train(x_train, y_train, x_test, y_test_train, n_epochs=50)
    model.evaluate(x_test, y_test)
    filename = '../dataset/Sad/09b03Ta.wav'
    print(
        'prediction',
        model.predict_one(
            get_feature_vector_from_mfcc(filename, flatten=to_flatten)),
        'Actual 3')
コード例 #3
0
def dnn_example():
    x_train, x_test, y_train, y_test = get_data(dataset_path=dataset_path, flatten=False)
    y_train = np_utils.to_categorical(y_train)
    y_test = np_utils.to_categorical(y_test)
    print('Starting LSTM')
    model = LSTM(input_shape=x_train[0].shape, num_classes=len(class_labels))
    model.train(x_train, y_train, x_test, y_test)
    model.evaluate(x_test, y_test)
    print('LSTM Done\n Starting CNN')
    in_shape = x_train[0].shape
    x_train = x_train.reshape(x_train.shape[0], in_shape[0], in_shape[1], 1)
    x_test = x_test.reshape(x_test.shape[0], in_shape[0], in_shape[1], 1)
    model = CNN(input_shape=x_train[0].shape, num_classes=len(class_labels))
    model.train(x_train, y_train, x_test, y_test)
    model.evaluate(x_test, y_test)
    print('CNN Done')
コード例 #4
0
def lstm_example():
    to_flatten = False
    x_train, x_test, y_train, y_test, num_labels = extract_data(
        flatten=to_flatten)
    y_train = np_utils.to_categorical(y_train)
    y_test_train = np_utils.to_categorical(y_test)
    print('Starting LSTM')
    model = LSTM(input_shape=x_train[0].shape,
                 num_classes=num_labels, save_path="./lstm.h5")
    print("Training")
    model.train(x_train, y_train, x_test, y_test_train, n_epochs=10)
    print("Evaluating")
    model.evaluate(x_test, y_test)
    model.save_model()
    filename = '../dataset/Sad/09b03Ta.wav'
    # filename = './laugh.wav'
    print("\nPredicted: {}\nActual: {}".format(
        get_class_name(
            model.predict_one(
                get_feature_vector_from_mfcc(filename, flatten=to_flatten))),
        get_class_name(2)))
コード例 #5
0
        female_mfccs = female_mfccs[:common]
    data = male_mfccs + female_mfccs
    labels = [0 for _ in male_mfccs] + [1 for _ in female_mfccs]
    return np.array(data), np.array(labels)


if __name__ == '__main__':
    train_test_factor = 0.8

    # get training data
    data, labels = prepare_training_data(
        '/home/rfeldhans/programming/audio/esiaf_gender_rec/dataset/', 6000)

    # schuffle for train/test assignment
    x, y = _shuffle(data, labels)

    x_train = np.array(x[:int(len(x) * train_test_factor)])
    y_train = np.array(y[:int(len(y) * train_test_factor)])
    x_test = np.array(x[int(len(x) * train_test_factor):])
    y_test = np.array(y[int(len(y) * train_test_factor):])

    # prepare labels
    y_train = np_utils.to_categorical(y_train)
    y_train_test = np_utils.to_categorical(y_test)

    model = LSTM(input_shape=x_train[0].shape, num_classes=2)

    model.train(x_train, y_train, x_test, y_train_test, n_epochs=20)
    model.evaluate(x_test, y_test)
    model.save_model()