Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import matplotlib.pyplot as plt
- #import random
- from glob import glob
- import numpy as np
- import librosa as lr
- from sklearn.neural_network import MLPClassifier
- import os
- reader = pd.read_csv(open('C:/Users/Douglas/Desktop/train_label.csv'))
- print(reader['Label'][1])
- train_audio_files = glob('C:/Users/Douglas/Desktop/Train/Train/PAEP-******.wav')
- print(len(train_audio_files))
- test_audio_files = glob('C:/Users/Douglas/Desktop/Public_Test/Public_Test/PAEP-******.wav')
- print(len(test_audio_files))
- data, sampling_rate = lr.load(train_audio_files)
- import time
- path = 'C:/Users/Douglas/Desktop/Train/Train/'
- lst = []
- start_time = time.time()
- for subdir, dirs, files in os.walk(path):
- for file in files:
- try:
- #Load librosa array, obtain mfcss, store the file and the mcss information in a new array
- X, sample_rate = lr.load(os.path.join(path, 'PAEP-******.wav'), res_type='kaiser_fast')
- mfccs = np.mean(lr.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T,axis=0)
- # The instruction below converts the labels (from 1 to 8) to a series from 0 to 7
- # This is because our predictor needs to start from 0 otherwise it will try to predict also 0.
- file = int(file[7:8]) - 1
- arr = mfccs, file
- lst.append(arr)
- # If the file is not valid, skip it
- except ValueError:
- continue
- #print("--- Data loaded. Loading time: %s seconds ---" % (time.time() - start_time))
- X, y = zip(*lst)
- X = np.array(X)
- y = np.array(y)
- print(X.shape)
- print(y.shape)
- #
- #
- #
- #train_audio_files = np.array(train_audio_files)
- #print(train_audio_files.shape)
- #np.reshape(train_audio_files, (len(train_audio_files), 1))
- #
- #emotions={
- # '01':'neutral',
- # '02':'calm',
- # '03':'happy',
- # '04':'sad',
- # '05':'angry',
- # '06':'fearful',
- # '07':'disgust',
- # '08':'surprised'
- #}
- #
- #
- ##DataFlair - Initialize the Multi Layer Perceptron Classifier
- #model=MLPClassifier(alpha=0.01, batch_size=256, epsilon=1e-08, hidden_layer_sizes=(300,), learning_rate='adaptive', max_iter=500)
- #
- ##DataFlair - Train the model
- #model.fit(train_audio_files, reader['Label'])
- ##DataFlair - Predict for the test set
- ##y_pred=model.predict(test_audio_files)
- #print('Predict:', model.predict(test_audio_files[:5]))
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement