Beispiel #1
0
def test():
    # TODO : Test Later
    print('==> Testing network..')
    # Make predictions on full X_test mels
    y_predicted = accuracy.predict_class_all(create_segmented_mels(X_test), a_net)

    # Print statistics
    print(np.sum(accuracy.confusion_matrix(y_predicted, y_test),axis=1))
    print(accuracy.confusion_matrix(y_predicted, y_test))
    print(accuracy.get_accuracy(y_predicted,y_test))
Beispiel #2
0
    X_test = pool.map(get_wav, X_test)

    # Convert to MFCC
    if DEBUG:
        print('converting to mfcc')
    X_train = pool.map(to_mfcc, X_train)
    X_test = pool.map(to_mfcc, X_test)

    # Create segments from MFCCs
    X_train, y_train = make_segments(X_train, y_train)
    X_validation, y_validation = make_segments(X_test, y_test)

    # Randomize training segments
    X_train, _, y_train, _ = train_test_split(X_train, y_train, test_size=0)

    # Train model
    model = train_model(np.array(X_train), np.array(y_train), np.array(X_validation),np.array(y_validation))

    # Make predictions on full X_test MFCCs
    y_predicted = accuracy.predict_class_all(create_segmented_mfccs(X_test), model)

    # Print statistics
    print train_count
    print test_count
    print acc_to_beat
    print np.sum(accuracy.confusion_matrix(y_predicted, y_test),axis=1)
    print accuracy.confusion_matrix(y_predicted, y_test)
    print accuracy.get_accuracy(y_predicted,y_test)

    # Save model
    save_model(model, model_filename)
    
# # Get statistics
train_count = Counter(y_train)
test_count =  Counter(y_test)


# print('==> Creatting segments..')
# # Create segments
# X_train, y_train = make_segments(X_train, y_train)

# # Randomize training segments
# X_train, _, y_train, _ = train_test_split(X_train, y_train, test_size=0)
    
# print(X_train.shape)
#Training
for epoch in range(start_epoch, start_epoch + args.epochs):
    train(epoch, X_train, y_train)


print('==> Testing network..')
# Make predictions on full X_test mels
y_predicted = accuracy.predict_class_all(create_segmented_mels(X_test, args.colsize), net)

# Print statistics
print(train_count)
print(test_count)
print(np.sum(accuracy.confusion_matrix(y_predicted, y_test),axis=1))
print(accuracy.confusion_matrix(y_predicted, y_test))
print(accuracy.get_accuracy(y_predicted,y_test))

    # Create segments from MFCCs
    X_train, y_train = make_segments(X_train, y_train)
    # X_validation, y_validation = make_segments(X_test, y_test)
    X_train, X_validation, y_train, y_validation = train_test_split(
        X_train, y_train, test_size=0.15)
    # print "Validation shape: {}".format(X_validation)
    # Randomize training segments
    X_train, _, y_train, _ = train_test_split(X_train, y_train, test_size=0)

    if network == 'cnn':
        # Train model
        model = train_model(np.array(X_train), np.array(y_train),
                            np.array(X_validation), np.array(y_validation),
                            EPOCHS)
        # Make predictions on full X_test MFCCs
        y_predicted = accuracy.predict_class_all(
            create_segmented_mfccs(X_test), model, 'cnn')
        class_sum = np.sum(accuracy.confusion_matrix(y_predicted, y_test),
                           axis=1)
        confusion_matrix = accuracy.confusion_matrix(y_predicted, y_test)
        print confusion_matrix
        print accuracy.get_accuracy(y_predicted, y_test)
        show_confusion_matrix(confusion_matrix, plt,
                              ['mandarin', 'arabic', 'english'], 'cnn')

    if network == 'lstm':
        # Train Lstm Model
        lstm = train_lstm_model(np.array(X_train), np.array(y_train),
                                np.array(X_validation), np.array(y_validation),
                                EPOCHS)
        y_predicted_lstm = accuracy.predict_class_all(
            create_segmented_mfccs(X_test), lstm, 'lstm')