-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_kmu.py
79 lines (63 loc) · 2.1 KB
/
preprocess_kmu.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv
import os
import numpy as np
import h5py
import skimage.io
import torch
ck_path = 'datasets/KMUMTCN'
anger_path = os.path.join(ck_path, 'anger')
disgust_path = os.path.join(ck_path, 'disgust')
fear_path = os.path.join(ck_path, 'fear')
happy_path = os.path.join(ck_path, 'happy')
sadness_path = os.path.join(ck_path, 'sadness')
surprise_path = os.path.join(ck_path, 'surprise')
# # Creat the list to store the data and label information
data_x = []
data_y = []
datapath = os.path.join('KMUtada','mtcnnkmunew.h5')
if not os.path.exists(os.path.dirname(datapath)):
os.makedirs(os.path.dirname(datapath))
# order the file, so the training set will not contain the test set (don't random)
files = os.listdir(anger_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(anger_path,filename))
data_x.append(I.tolist())
data_y.append(0)
files = os.listdir(disgust_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(disgust_path,filename))
data_x.append(I.tolist())
data_y.append(1)
files = os.listdir(fear_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(fear_path,filename))
data_x.append(I.tolist())
data_y.append(2)
files = os.listdir(happy_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(happy_path,filename))
data_x.append(I.tolist())
data_y.append(3)
files = os.listdir(sadness_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(sadness_path,filename))
data_x.append(I.tolist())
data_y.append(4)
files = os.listdir(surprise_path)
files.sort()
for filename in files:
I = skimage.io.imread(os.path.join(surprise_path,filename))
data_x.append(I.tolist())
data_y.append(5)
print(np.shape(data_x))
print(np.shape(data_y))
datafile = h5py.File(datapath, 'w')
datafile.create_dataset("data_pixel", dtype = 'uint8', data=data_x)
datafile.create_dataset("data_label", dtype = 'int64', data=data_y)
datafile.close()
print("Save data finish!!!")