ในบทความนี้จะพูดถึงการใช้ Apprentissage en profondeur และเทคนิค Réseaux de neurones convolutionnels (CNN) ในการจำแนกเสียงจากข้อมูลเสียง (ensemble de données audio) โดยการแปลงข้อมูลเสียงเป็น Spectrogramme และนำเข้าไปยังโมเดล CNN เพื่อให้สามารถจำแนกประเภทเสียงได้
บทความนี้ เราจะมาดู Apprentissage en profondeur และเทคนิค Réseaux de neurones convolutionnels (CNN) ในการจำแนกเสียงจากข้อมูลเสียง ใน Python กัน เราจะใช้ Google Colab ในการรันโค้ด โดย Tenue de données ที่เราจะใช้เป็นตัวอย่างคือ เสียงกีตาร์ และ เสียงคีย์บอร์ดเปียโน จากเว็บไซต์ FreeSound
โดยจะมีเสียงกีตาร์ และเปียโนที่เอาไว้ Train โฟลเดอร์ละ 2 เสียง และเสียงที่เอาไว้ Test อีกอย่างละ 1 เสียง
ในขั้นแรก เราใช้ Librosa ไลบรารีที่ใช้ในการประมวลผลเสียง เพื่อโหลดไฟล์เสียงและแปลงข้อมูลเสียงเป็น Spectrogramme ซึ่งเป็นภาพที่แสดงถึงการเปลี่ยนแปลงของความถี่ (fréquence) ในช่วงเวลา (temps) โดยใช้เทคนิค Transformée de Fourier à court terme (STFT) ซึ่งจะช่วยให้เราสามารถวิเคราะห์การเปลี่ยนแปลงของความถี่ได้
ต่อมา เราจะทำการแยกข้อมูลเสียงในโฟลเดอร์ Guitare และ KeyB โดยใช้ฟังก์ชัน SPECT () ที่จะทำการโหลดไฟล์เสียงจากแต่ละโฟลเดอร์และแปลงเป็น Spectrogramme จากนั้นจัดเก็บข้อมูลลงในตัวแปร X และ Y ซึ่ง X เก็บข้อมูล Spectrogramme และ Y เก็บ Étiquette ที่บ่งชี้ประเภทของเครื่องดนตรี (0 = กีตาร์, 1 = คีย์บอร์ด)
Importer Librosa, Librosa.Display Import Numpy en tant que np import Matplotlib.pyplot as PLT à partir d'Ipython.Display Importation Import Os Os de TQDM Importation TQDM AVERTISSEMENTS DE DEF (WAVE): F, SR = Librosa.Load (Wave, durée = 0.9) ST = Librosa.Stft (F) Spectrogram = NP.Abs (ST) SPECTROgrat de retour x = Lit = list () # อ่านไฟล์เสียงจากโฟลเดอร์ต่าง ๆ gt_files = os.listdir ('/ content / guitar /') kb_files = os.listdir ('/ contenu / keyb /') gt_files = [f pour f dans gt_files if os.path.isfile (os.path.join ('/ contenu / guitar os.path.isfile(os.path.join('/content/keyb/', f))] # แปลงเสียงกีตาร์เป็น Spectrogram และเก็บในตัวแปร for f in tqdm(gt_files): file1 = 'guitar/' + f data = spect(file1) x.append(data) y.append([0, 1]) # กีตาร์ = [0, 1] # แปลงเสียงคีย์บอร์ดเป็น Spectrogram และเก็บในตัวแปร for f in tqdm (kb_files): file1 = 'keyb /' + f data = spec (file1) x.append (data) y.append ([1, 0]) # คีย์บอร์ด = [1, 0]ในขั้นตอนนี้เราจะนำเข้า Sklearn สำหรับการสร้างชุดฝึกโมเดล Tensorflow สำหรับการคำนวณสร้าง Deeplearning และนำข้อมูลที่เตรียมไว้มาใช้ในการฝึกโมเดล CNN ซึ่งมีการใช้ CONV2D เพื่อการเรียนรู้ฟีเจอร์จาก Spectrogramme ในการประมวลภาพ และ Maxpooling2d เพื่อลดขนาดข้อมูล พร้อมทั้งใช้ dense และ aplatissement เพื่อให้สามารถจำแนกประเภทเสียงได้
à partir de sklearn.model_selection import train_test_split import tensorflow as tf from keras.models importe séquentiel de keras.layers importe conv2d, maxpooling2d, dense, aplatissez à partir de keras.optimizers importent rmsprop # แบ่งข้อมูลเป็น และ และ และ test x = np.array (x) y = np.Array (y) x = x.Reshape (x.shape [0], x.shape [1], x.shape [2], 1) xtrain, xTest, ytrain, ytest = Train_test_split (x, y, train_size = 0.8, random_state = 42) # สร้างโมเดล cnn modèle = séquentiel ([conv2d (128, (3, 3), activation = 'resential ([conv2d (128, (3, 3), activation =' resential ([conv2d (128, (3, 3), activation = 'resentiel (Conv2d (128, (3, 3), activation =' resential ([conv2d (128, (3, 3), activation = 'resentiel (Conv2d (128, (3, 3), Activation =' RELIEL input_shape=xtrain.shape[1:]), MaxPooling2D(pool_size=(2, 2)), Conv2D(128, (3, 3), activation='relu'), MaxPooling2D(pool_size=(2, 2)), Dense(16), Dense(8), Flatten(), Dense(2, activation='softmax') ]) # คอมไพล์โมเดล หรือการเตรียมโมเดลสำหรับการฝึกฝน Model.Compile (Optimizer = RmsProp (Learning_Rate = 0.0001), Loss = 'catégorical_crossentropy', Metrics = ['Précision']) # ฝึกฝนโมเดล 100 รอบ History = Model.Fit (xtrain, ytrain, epochs = 100, validation_data = (xTest, ytest)))จากผลลัพธ์การ Train ครบ 100 ครั้ง ผลการ Train ครั้งที่ 100 พบว่าตัวโมเดลมี ความแม่นยำสูงในการฝึก (Précision: 1,0000) และค่าความสูญเสียต่ำในข้อมูลการฝึก (Perte: 4.6967e-05) ซึ่งบ่งชี้ว่าโมเดลสามารถจำแนกประเภทของข้อมูลในชุดการฝึกได้ดี แต่ในขณะเดียวกัน, โมเดลไม่สามารถทำนายผลได้ดีในข้อมูลทดสอบ (Val_accuracy: 1.0000) และค่าความสูญเสียต่ำมาก (Val_loss: 0,0000) ซึ่งแสดงถึงผลที่ดีในการทดสอบ.
ต่อมาจะใช้ Matplotlib เพื่อวาดกราฟที่แสดงถึง ค่า Perte และ Précision ของโมเดลที่เราได้ฝึกในแต่ละรอบ
plt.figure (FigSize =...
[Courte citation de 8% de l'article original]