Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import pandas as pd
  2. import matplotlib.pyplot as plt
  3. #import random
  4. from glob import glob
  5. import numpy as np
  6. import librosa as lr
  7. from sklearn.neural_network import MLPClassifier
  8. import os
  9.  
  10. reader = pd.read_csv(open('C:/Users/Douglas/Desktop/train_label.csv'))
  11. print(reader['Label'][1])
  12.  
  13. train_audio_files = glob('C:/Users/Douglas/Desktop/Train/Train/PAEP-******.wav')
  14. print(len(train_audio_files))
  15.  
  16. test_audio_files = glob('C:/Users/Douglas/Desktop/Public_Test/Public_Test/PAEP-******.wav')
  17. print(len(test_audio_files))
  18.  
  19. data, sampling_rate = lr.load(train_audio_files)
  20.  
  21. import time
  22.  
  23. path = 'C:/Users/Douglas/Desktop/Train/Train/'
  24. lst = []
  25.  
  26. start_time = time.time()
  27.  
  28. for subdir, dirs, files in os.walk(path):
  29. for file in files:
  30. try:
  31. #Load librosa array, obtain mfcss, store the file and the mcss information in a new array
  32. X, sample_rate = lr.load(os.path.join(path, 'PAEP-******.wav'), res_type='kaiser_fast')
  33. mfccs = np.mean(lr.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40).T,axis=0)
  34. # The instruction below converts the labels (from 1 to 8) to a series from 0 to 7
  35. # This is because our predictor needs to start from 0 otherwise it will try to predict also 0.
  36. file = int(file[7:8]) - 1
  37. arr = mfccs, file
  38. lst.append(arr)
  39. # If the file is not valid, skip it
  40. except ValueError:
  41. continue
  42.  
  43. #print("--- Data loaded. Loading time: %s seconds ---" % (time.time() - start_time))
  44. X, y = zip(*lst)
  45. X = np.array(X)
  46. y = np.array(y)
  47.  
  48.  
  49. print(X.shape)
  50. print(y.shape)
  51.  
  52. #
  53. #
  54. #
  55. #train_audio_files = np.array(train_audio_files)
  56. #print(train_audio_files.shape)
  57. #np.reshape(train_audio_files, (len(train_audio_files), 1))
  58. #
  59. #emotions={
  60. # '01':'neutral',
  61. # '02':'calm',
  62. # '03':'happy',
  63. # '04':'sad',
  64. # '05':'angry',
  65. # '06':'fearful',
  66. # '07':'disgust',
  67. # '08':'surprised'
  68. #}
  69. #
  70. #
  71. ##DataFlair - Initialize the Multi Layer Perceptron Classifier
  72. #model=MLPClassifier(alpha=0.01, batch_size=256, epsilon=1e-08, hidden_layer_sizes=(300,), learning_rate='adaptive', max_iter=500)
  73. #
  74. ##DataFlair - Train the model
  75. #model.fit(train_audio_files, reader['Label'])
  76. ##DataFlair - Predict for the test set
  77. ##y_pred=model.predict(test_audio_files)
  78. #print('Predict:', model.predict(test_audio_files[:5]))
  79. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement