亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python初學者ML項目問題

Python初學者ML項目問題

夢里花落0921 2023-06-06 16:40:57
所以我復制了一些代碼來嘗試在 python 中弄清楚機器學習??偟膩碚f效果很好,但現在我不知道如何使用它(輸入我自己的文件并分析它)。import librosaimport numpy as npimport soundfileimport sklearnimport os, glob, picklefrom sklearn.model_selection import train_test_splitfrom sklearn.neural_network import MLPClassifierfrom sklearn.metrics import accuracy_scoredef extract_feture(filepath,mfcc,chroma,mel):? ? with soundfile.SoundFile(filepath) as sound_file:? ? ? ? X = sound_file.read(dtype="float32")? ? ? ? sample_rate=sound_file.samplerate? ? ? ? if chroma:? ? ? ? ? ? stft = np.abs(librosa.stft(X))? ? ? ? result = np.array([])? ? ? ? if mfcc:? ? ? ? ? ? mfccs = np.mean(librosa.feature.mfcc(y=X, sr=sample_rate, n_mfcc=40) .T, axis=0)? ? ? ? ? ? result = np.hstack((result, mfccs))? ? ? ? if chroma:? ? ? ? ? ? chroma = np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T, axis=0)? ? ? ? ? ? result = np.hstack((result, chroma))? ? ? ? if mel:? ? ? ? ? ? mel = np.mean(librosa.feature.melspectrogram(X, sr= sample_rate).T,axis=0)? ? ? ? ? ? result = np.hstack((result, mel))? ? return resultemotions = {? ? '01':'neutral',? ? '02':'calm',? ? '03':'happy',? ? '04':'sad',? ? '05': 'angry',? ? '06': 'fearful',? ? '07': 'disgust',? ? '08': 'surprised'}observed_emotions =['calm', 'happy', 'fearful', 'disgust']def load_data(test_size=0.2):? ? x, y = [], []? ? for file in glob.glob("/home/adobug2/Documents/ravdess-data/Actor_*/*.wav"):? ? ? ? file_name = os.path.basename(file)? ? ? ? emotion = emotions[file_name.split("-")[2]]? ? ? ? if emotion not in observed_emotions:? ? ? ? ? ? continue? ? ? ? feature = extract_feture(file, mfcc=True, chroma=True, mel=True)? ? ? ? x.append(feature)? ? ? ? y.append(emotion)? ? return train_test_split(np.array(x), y, test_size=test_size, random_state=9)x_train,x_test,y_train,y_test=load_data(test_size=0.25)print((x_train.shape[0], x_test.shape[0]))
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

model.predict()在您的新音頻文件上使用。那應該返回您想要的輸出。



查看完整回答
反對 回復 2023-06-06
  • 1 回答
  • 0 關注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號