コード例 #1
0
def Train(save_model_name: str):
    Config.save_model_name = save_model_name
    x_train, x_test, y_train, y_test = Opensmile_Feature.get_data(Config.DATA_PATH, Config.TRAIN_FEATURE_PATH_OPENSMILE, train=True)
    model = SVM_Model()
    model.train(x_train, y_train)
    model.evaluate(x_test, y_test)
    model.save_model(save_model_name)

    return model
コード例 #2
0
def Train(save_model_name: str):
    Config.save_model_name = save_model_name
    x_train, x_test, y_train, y_test = Librosa_Feature.get_data(
        Config.DATA_PATH, Config.TRAIN_FEATURE_PATH_LIBROSA, train=True)
    model = SVM_Model()
    model.train(x_train, y_train)
    model.evaluate(x_test, y_test)
    model.save_model(save_model_name)

    return model
コード例 #3
0
ファイル: SER.py プロジェクト: Anakinliu/PythonProjects
def Train(model_name: str,
          save_model_name: str,
          if_load: bool = True,
          feature_method: str = 'opensmile'):
    # 提取特征
    print(f'if_load: {if_load}')
    if (feature_method == 'o'):
        # 使用openSmile提取特征

        if (if_load == True):
            x_train, x_test, y_train, y_test = of.load_feature(
                feature_path=Config.TRAIN_FEATURE_PATH_OPENSMILE, train=True)
        else:
            x_train, x_test, y_train, y_test = of.get_data(
                Config.DATA_PATH,
                Config.TRAIN_FEATURE_PATH_OPENSMILE,
                train=True)

    elif (feature_method == 'l'):
        if (if_load == True):
            x_train, x_test, y_train, y_test = lf.load_feature(
                feature_path=Config.TRAIN_FEATURE_PATH_LIBROSA, train=True)
        else:
            print('here-------------------------')
            x_train, x_test, y_train, y_test = lf.get_data(
                Config.DATA_PATH,
                Config.TRAIN_FEATURE_PATH_LIBROSA,
                train=True)

    # 创建模型
    if (model_name == 'svm'):
        model = SVM_Model()
    elif (model_name == 'mlp'):
        model = MLP_Model()
    else:
        y_train = np_utils.to_categorical(y_train)
        y_val = np_utils.to_categorical(y_test)

        model = LSTM_Model(input_shape=x_train.shape[1],
                           num_classes=len(Config.CLASS_LABELS))

        # 二维数组转三维(samples, time_steps, input_dim)
        x_train = np.reshape(x_train, (x_train.shape[0], 1, x_train.shape[1]))
        x_test = np.reshape(x_test, (x_test.shape[0], 1, x_test.shape[1]))

    # 训练模型
    print(
        '-------------------------------- Start --------------------------------'
    )
    if (model_name == 'svm' or model_name == 'mlp'):
        model.train(x_train, y_train)
    else:
        print(x_train.shape)
        print(y_train.shape)

        print(x_test.shape)
        print(y_val.shape)
        model.train(x_train, y_train, x_test, y_val, n_epochs=Config.epochs)

    model.evaluate(x_test, y_test)
    model.save_model(save_model_name)
    print(
        '---------------------------------- End ----------------------------------'
    )

    return model
コード例 #4
0
ファイル: audio.py プロジェクト: cem-ergin/yapayzeka
# When using SVM, _svm = True, or _svm = False
#asdf = get_feature_svm("/Users/cemergin/PycharmProjects/Speech-Emotion-Recognition/Models/DataSet/RAVDESSson/angry/03-01-05-01-01-01-01.wav", 39)
#numpy.savetxt("asdf.txt",asdf)
#print("yazdım")
#print(asdf)
x_train, x_test, y_train, y_test = get_data(DATA_PATH, _svm=True)
#print(len(x_train))
#print(len(x_test))
#print(x_train.shape)
#print(x_test.shape)
#print(x_train)
#print(x_test)

numpy.savetxt("x_train.txt", x_train)
numpy.savetxt("x_test.txt", x_test)
numpy.savetxt("y_train.txt", y_train)
numpy.savetxt("y_test.txt", y_test)
model_svm = SVM_Model()
model_svm.save_model("svmmodeli")
model_svm.train(x_train, y_train)
model_svm.evaluate(x_test, y_test)
#model.recognize_one(get_feature("/Users/cemergin/PycharmProjects/Speech-Emotion-Recognition/Models/DataSet/RAVDESS/angry/03-01-05-01-01-01-01.wav"))

#a = get_feature("/Users/cemergin/PycharmProjects/audio-classification/data/03a01Nc.wav",39,flatten=1)
#print(a)
#print(type(a))
#print(len(a))
#numpy.savetxt("feature.txt",a)
#-36.04365339 03a01nc
#1134 -5.689264606224537779e-01 fa