def gen_regression(): base_path = g_base_data_path + '{}emodb_regression_train'.format( g_base_dir_delimiter) aT.featureAndTrainRegression(base_path, 1, 1, aT.shortTermWindow, aT.shortTermStep, "svm", g_regression_model_path, False)
def trainRegressionWrapper(method, beat_feats, dirName, model_name): aT.featureAndTrainRegression(dirName, 1, 1, aT.shortTermWindow, aT.shortTermStep, method.lower(), model_name, compute_beat=beat_feats)
def training_regression(request): try: print('--- Start handling ...') aT.featureAndTrainRegression( "/home/dinhkhoi1/data/songs/train/", 1, 1, aT.shortTermWindow, aT.shortTermStep, "svm", "/home/dinhkhoi1/data/songs/train/svm_model", False) return Response(status=status.HTTP_201_CREATED) except Exception as ex: sys.stderr(ex) return Response(ex.__cause__, status=status.HTTP_400_BAD_REQUEST)
def train(self, audio_files_path, output_path, model_name): afp = Path(audio_files_path) op = Path(output_path) model = str(op / model_name) if not os.path.exists(afp): print('The audio files path does not exist') return if not os.path.exists(op): os.mkdir(op) return return aT.featureAndTrainRegression(audio_files_path, 1.0, 1.0, aT.shortTermWindow, aT.shortTermStep, "svm", model, True)
Regression ''' ''' Train Regression Models for Audio Segments featureAndTrainRegression(). It calls functions dirsWavFeatureExtraction() to extract the audio features and then repetivelly calls evaluateRegression() to extract one optimized regression model for each learned parameter. ''' import subprocess from pyAudioAnalysis import audioTrainTest as aT aT.featureAndTrainRegression("pyAudioAnalysis/data/speechEmotion/", 1, 1, aT.shortTermWindow, aT.shortTermStep, "svm", "output/svmSpeechEmotion", False) ''' Regression task valence Param MSE T-MSE R-MSE 0.0010 0.37 0.45 0.42 0.0050 0.30 0.32 0.43 0.0100 0.29 0.28 0.43 best 0.0500 0.30 0.20 0.44 0.1000 0.33 0.18 0.44 0.2500 0.46 0.16 0.42 0.5000 0.62 0.15 0.44 1.0000 0.86 0.14 0.41 5.0000 1.70 0.13 0.44 10.0000 2.41 0.12 0.42 Selected params: 0.01000
from pyAudioAnalysis import audioTrainTest as att att.featureAndTrainRegression('wav', 1.0, 1.0, att.shortTermWindow, att.shortTermStep, 'svm', 'mesto', True)
root_data_path + 'radioFinal/train/bbc4A.segments', 'hmmTemp1', 1.0, 1.0) aS.trainHMM_fromDir(root_data_path + 'radioFinal/small', 'hmmTemp2', 1.0, 1.0) aS.hmmSegmentation(root_data_path + 'pyAudioAnalysis/data//scottish.wav', 'hmmTemp1', True, root_data_path + 'pyAudioAnalysis/data//scottish.segments') # test 1 aS.hmmSegmentation(root_data_path + 'pyAudioAnalysis/data//scottish.wav', 'hmmTemp2', True, root_data_path + 'pyAudioAnalysis/data//scottish.segments') # test 2 print("\n\n\n * * * TEST 7 * * * \n\n\n") aT.featureAndTrainRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion", 1, 1, 0.050, 0.050, "svm_rbf", "temp.mod", compute_beat=False) print( aT.fileRegression( root_data_path + "pyAudioAnalysis/data/speechEmotion/01.wav", "temp.mod", "svm_rbf")) print("\n\n\n * * * TEST 8 * * * \n\n\n") aT.featureAndTrainRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion", 1, 1, 0.050,
print("\n\n\n * * * TEST 3 * * * \n\n\n") [Fs, x] = audioBasicIO.readAudioFile(root_data_path + "pyAudioAnalysis/data/doremi.wav") x = audioBasicIO.stereo2mono(x) specgram, TimeAxis, FreqAxis = audioFeatureExtraction.stChromagram(x, Fs, round(Fs * 0.040), round(Fs * 0.040), True) print("\n\n\n * * * TEST 4 * * * \n\n\n") aT.featureAndTrain([root_data_path +"SM/speech",root_data_path + "SM/music"], 1.0, 1.0, 0.2, 0.2, "svm", "temp", True) print("\n\n\n * * * TEST 5 * * * \n\n\n") [flagsInd, classesAll, acc, CM] = aS.mtFileClassification(root_data_path + "pyAudioAnalysis/data//scottish.wav", root_data_path + "pyAudioAnalysis/data/svmSM", "svm", True, root_data_path + 'pyAudioAnalysis/data/scottish.segments') print("\n\n\n * * * TEST 6 * * * \n\n\n") aS.trainHMM_fromFile(root_data_path + 'radioFinal/train/bbc4A.wav', root_data_path + 'radioFinal/train/bbc4A.segments', 'hmmTemp1', 1.0, 1.0) aS.trainHMM_fromDir(root_data_path + 'radioFinal/small', 'hmmTemp2', 1.0, 1.0) aS.hmmSegmentation(root_data_path + 'pyAudioAnalysis/data//scottish.wav', 'hmmTemp1', True, root_data_path + 'pyAudioAnalysis/data//scottish.segments') # test 1 aS.hmmSegmentation(root_data_path + 'pyAudioAnalysis/data//scottish.wav', 'hmmTemp2', True, root_data_path + 'pyAudioAnalysis/data//scottish.segments') # test 2 print("\n\n\n * * * TEST 7 * * * \n\n\n") aT.featureAndTrainRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion", 1, 1, 0.050, 0.050, "svm_rbf", "temp.mod", compute_beat=False) print(aT.fileRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion/01.wav", "temp.mod", "svm_rbf")) print("\n\n\n * * * TEST 8 * * * \n\n\n") aT.featureAndTrainRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion", 1, 1, 0.050, 0.050, "svm", "temp.mod", compute_beat=False) print(aT.fileRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion/01.wav", "temp.mod", "svm")) print("\n\n\n * * * TEST 9 * * * \n\n\n") aT.featureAndTrainRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion", 1, 1, 0.050, 0.050, "randomforest", "temp.mod", compute_beat=False) print(aT.fileRegression(root_data_path + "pyAudioAnalysis/data/speechEmotion/01.wav", "temp.mod", "randomforest"))