Example #1
0
def test_ffnn():
    params = {
        'n_layers': 4,
        'hidden_nodes': [512, 512, 512, 512],
        'epochs': 10,
        'use_dynamic_features': True,
        'use_mspec': False,
        'as_mat': False,
        'speaker_norm': False,
        'context_length': 17
    }
    net = FFNN(params)
    model = net.train_model()
    net.set_model(model)
    y_true, yp = net.predict_on_test()
    print("FFNN RESULTS")
    print(get_f1_score(y_true, yp))
    print(get_accuracy(y_true, yp))
    print(classification_report(y_true, yp))
Example #2
0
def test_rnn():
    """Notice as_mat is true here!"""
    params = {
        'n_layers': 2,
        'hidden_nodes': [32, 32],
        'epochs': 100,
        'use_dynamic_features': True,
        'use_mspec': True,
        'as_mat': True,
        'speaker_norm': False,
        'context_length': 35
    }
    net = RNN(params)
    model = net.train_model(params['unroll'])
    net.set_model(model)
    y_true, yp = net.predict_on_test()
    print("RNN RESULTS")
    print(get_f1_score(y_true, yp))
    print(get_accuracy(y_true, yp))
    print(classification_report(y_true, yp))
    model.save('rnn-64-64-context-35.h5')
Example #3
0
def store_results(y_true, yp, net, model_path, model):
    phones = fixed_phones(net)
    with open(os.path.join(os.getcwd(), model_path + os.sep + 'results.txt'),
              'w') as f:
        f.write('acc: {}\n'.format(str(get_accuracy(y_true, yp))))
        f.write('edit: {}\n'.format(
            str(
                eval_edit_dist(y_true,
                               yp,
                               net.test,
                               feature_name=net.feature_name))))
        f.write('f1-score: {}\n'.format(str(get_f1_score(y_true, yp))))
        report = get_classification_report(y_true, yp, phones)
        f.write(str(report))
    cm = get_confusion_matrix(y_true, yp)
    net.plot_confusion_matrix(
        cm,
        phones,
        os.path.join(os.getcwd(),
                     model_path + os.sep + 'confusion_matrix.png'),
        normalize=True)
    model.save(os.path.join(os.getcwd(), model_path + os.sep + 'model.h5'))
 def get_f1_score(self):
     return metrics.get_f1_score(self.test_labels, self.pred_labels)
 def calculate_f1_score(self, samples, model_number):
     return get_f1_score(samples, model_number)