-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreprocessing.py
163 lines (121 loc) · 5.49 KB
/
preprocessing.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 6 09:28:16 2019
@author: saireddy
"""
__author__ = 'Sai Reddy'
import numpy as np
import pandas as pd
import os
import cv2
data = pd.read_csv("/home/saireddy/Desktop/capstone/fer2013/fer2013.csv", delimiter=",")
emotion = data['emotion']
pixels = data['pixels']
Usage = data['Usage']
print(emotion.unique())
print(Usage.unique())
Usage_path = ['Training', 'PublicTest', 'PrivateTest']
for i in range(len(Usage_path)):
if not os.path.exists(Usage_path[i]):
os.mkdir(Usage_path[i])
#label_path = [0, 1, 2, 3, 4, 5, 6]
label_names = ['Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
for i in range(len(label_names)):
if not os.path.exists(os.path.join("/home/saireddy/Desktop/capstone/fer2013/Training/", label_names[i])):
os.mkdir(os.path.join("/home/saireddy/Desktop/capstone/fer2013/Training/", label_names[i]))
if not os.path.exists(os.path.join("/home/saireddy/Desktop/capstone/fer2013/PublicTest/", label_names[i])):
os.mkdir(os.path.join("/home/saireddy/Desktop/capstone/fer2013/PublicTest/", label_names[i]))
if not os.path.exists(os.path.join("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/", label_names[i])):
os.mkdir(os.path.join("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/", label_names[i]))
label = emotion.values
print(len(label))
images = np.array([np.fromstring(image, np.uint8, sep=' ') for image in pixels])
Usage_ = Usage.values
for i in range(len(label)):
if label[i] == 0 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Angry/00"+str(i)+'.jpg', img)
if label[i] == 1 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Disgust/00"+str(i)+'.jpg', img)
if label[i] == 2 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Fear/00"+str(i)+'.jpg', img)
if label[i] == 3 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Happy/00"+str(i)+'.jpg', img)
if label[i] == 4 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Sad/00"+str(i)+'.jpg', img)
if label[i] == 5 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Suprise/00"+str(i)+'.jpg', img)
if label[i] == 6 and Usage_[i] == 'Training':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/Training/Neutral/00"+str(i)+'.jpg', img)
for i in range(len(label)):
if label[i] == 0 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Angry/00"+str(i)+'.jpg', img)
if label[i] == 1 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Disgust/00"+str(i)+'.jpg', img)
if label[i] == 2 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Fear/00"+str(i)+'.jpg', img)
if label[i] == 3 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Happy/00"+str(i)+'.jpg', img)
if label[i] == 4 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Sad/00"+str(i)+'.jpg', img)
if label[i] == 5 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Suprise/00"+str(i)+'.jpg', img)
if label[i] == 6 and Usage_[i] == 'PublicTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PublicTest/Neutral/00"+str(i)+'.jpg', img)
for i in range(len(label)):
if label[i] == 0 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Angry/00"+str(i)+'.jpg', img)
if label[i] == 1 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Disgust/00"+str(i)+'.jpg', img)
if label[i] == 2 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Fear/00"+str(i)+'.jpg', img)
if label[i] == 3 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Happy/00"+str(i)+'.jpg', img)
if label[i] == 4 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Sad/00"+str(i)+'.jpg', img)
if label[i] == 5 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Suprise/00"+str(i)+'.jpg', img)
if label[i] == 6 and Usage_[i] == 'PrivateTest':
print(i)
img = images[i].reshape(48, 48)
cv2.imwrite("/home/saireddy/Desktop/capstone/fer2013/PrivateTest/Neutral/00"+str(i)+'.jpg', img)