-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_spectrogram_dataset_merged.py
More file actions
50 lines (35 loc) · 1.2 KB
/
create_spectrogram_dataset_merged.py
File metadata and controls
50 lines (35 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import re
import numpy as np
HOP_LEN = 128
SAMPLING_RATE = 44100
DURATION = 300
SHIFT = 200
audio_dataset_path = '/media/blue/ckorgial/XAI_VISION/VISION_train_bandpass/'
lists = [['01', '26'],
['02', '10'], ['03'], ['05', '14', '18'], ['06', '15'], ['07'], ['08'],
['09'], ['11'], ['13'], ['16'], ['19'], ['20'], ['21'], ['23'], ['24'], ['25'], ['27'], ['28'],
['29', '34'], ['30'], ['31'], ['32'], ['33'], ['35']]
lists = {index: value for index, value in enumerate(lists)}
excluded = [4, 12, 17, 22]
X = np.load(audio_dataset_path + 'X.npy')
y = np.load(audio_dataset_path + 'y.npy')
# 1) Delete excluded labels
for i in excluded:
# Find the indices of samples with label 5
indices_to_delete = np.where(y == i)[0]
# Delete the samples with label 5
X = [sample for i, sample in enumerate(X) if i not in indices_to_delete]
y = np.delete(y, indices_to_delete)
# 2) Assign first label of each sublist
for j in lists.keys():
correct_label = j
for l in lists[j]:
lb = int(l)
for i in range(len(y)):
print(y[i], lb)
if y[i] == lb:
y[i] = correct_label
# 3) Save
np.save('X.npy', X)
np.save('y.npy', y)