Esempio n. 1
0
def test_model():
    features, labels = loadFromPickle()
    features, labels = shuffle(features, labels)
    features = features.reshape(features.shape[0], 64, 20, 1)
    labels = prepress_labels(labels)
    train_x, test_x, train_y, test_y = train_test_split(features,
                                                        labels,
                                                        random_state=0,
                                                        test_size=0.1)
    model, callbacks_list = keras_model((
        64,
        20,
        1,
    ), len(labels[0]))
    print_summary(model)
    model.fit(train_x,
              train_y,
              batch_size=128,
              epochs=5,
              verbose=1,
              validation_data=(test_x, test_y),
              callbacks=[TensorBoard(log_dir="TensorBoard")])

    # 开始评估模型效果 # verbose=0为不输出日志信息
    score = model.evaluate(test_x, test_y, verbose=0)
    print('Test loss:', score[0])
    print('Test accuracy:', score[1])  # 准确度

    model.save('asr_mfcc_conv2d_model.h5')  # 保存训练模型
Esempio n. 2
0
def test_model1():
    features, labels = loadFromPickle()
    labels_count = int(len(labels) / MAX_NUM)
    # features, labels = augmentData(features, labels)
    features, labels = shuffle(features, labels)
    labels = prepress_labels(labels)
    train_x, test_x, train_y, test_y = train_test_split(features,
                                                        labels,
                                                        random_state=0,
                                                        test_size=0.1)
    # train_x = train_x.reshape(train_x.shape[0], 28, 28, 1)
    # test_x = test_x.reshape(test_x.shape[0], 28, 28, 1)
    model, callbacks_list = keras_model1((28 * 28, ), labels_count)
    print_summary(model)
    model.fit(train_x,
              train_y,
              validation_data=(test_x, test_y),
              epochs=500,
              batch_size=256)
    # model.fit(train_x, train_y, validation_data=(test_x, test_y), epochs=500, batch_size=256,
    #          callbacks=[TensorBoard(log_dir="TensorBoard")])

    # 开始评估模型效果 # verbose=0为不输出日志信息
    score = model.evaluate(test_x, test_y, verbose=0)
    print('Test loss:', score[0])
    print('Test accuracy:', score[1])  # 准确度

    model.save('model1.h5')
Esempio n. 3
0
def test_model():
    features, labels = loadFromPickle()
    labels_count = len(load_label_name())
    # features, labels = augmentData(features, labels)
    features, labels = shuffle(features, labels)
    labels = prepress_labels(labels)
    train_x, test_x, train_y, test_y = train_test_split(features,
                                                        labels,
                                                        random_state=0,
                                                        test_size=0.2)
    train_x = train_x.reshape(train_x.shape[0], 28, 28, 1)
    test_x = test_x.reshape(test_x.shape[0], 28, 28, 1)
    model, callbacks_list = keras_model((
        28,
        28,
        1,
    ), labels_count)
    print_summary(model)
    model.fit(train_x,
              train_y,
              validation_data=(test_x, test_y),
              epochs=40,
              batch_size=128)
    # 开始评估模型效果 # verbose=0为不输出日志信息
    score = model.evaluate(test_x, test_y, verbose=0)
    print('Test loss:', score[0])
    print('Test accuracy:', score[1])  # 准确度
    model.save('model.h5')
Esempio n. 4
0
def test_model2(input_length):
    features, labels = loadFromPickle()
    features, labels = shuffle(features, labels)
    features=features.reshape(features.shape[0],input_length)
    labels=prepress_labels(labels)
    train_x, test_x, train_y, test_y = train_test_split(features, labels, random_state=0,
                                                        test_size=0.2)
    model, callbacks_list = keras_model2((input_length,),len(labels[0]))
    print_summary(model)
    model.fit(train_x, train_y, batch_size=128, epochs=20, verbose=1, validation_data=(test_x, test_y),
        callbacks=[TensorBoard(log_dir="TensorBoard")])

    score = model.evaluate(test_x, test_y, verbose=0)
    print('Test loss:', score[0])
    print('Test accuracy:', score[1]) # 准确度
    model.save('test_model2.h5') # 保存训练模型
Esempio n. 5
0
def validate():
    data_dir = ".\\data\\"
    label_names = get_labels(data_dir)
    model = load_model('asr_model.h5') # 加载训练模型

    features, labels = loadFromPickle()
    features, labels = shuffle(features, labels)
    features=features.reshape(features.shape[0],20,32,1)
    labels=prepress_labels(labels)
    train_x, test_x, train_y, test_y = train_test_split(features, labels, random_state=0,
                                                        test_size=0.3)
    print_summary(model)

    # 开始评估模型效果 # verbose=0为不输出日志信息
    score = model.evaluate(test_x, test_y, verbose=0)
    print('Test loss:', score[0])
    print('Test accuracy:', score[1]) # 准确度