-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
62 lines (50 loc) · 1.43 KB
/
Copy pathtest.py
File metadata and controls
62 lines (50 loc) · 1.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#D:/kaggle/表情识别/test.py
import numpy as np
import pandas as pd
import tensorflow as tf
import keras
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D, AveragePooling2D
from keras.layers import Dense, Activation, Dropout, Flatten
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# get the data
filname = r'D:/kaggle/表情识别/test.csv'
label_map = ['Anger', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
names=['id','feature']
df=pd.read_csv(r'D:/kaggle/表情识别/test.csv',names=names, na_filter=False)
im=df['feature']
df.head(10)
def getData(filname):
# images are 48x48
# N = 28709
Y = []
X = []
first = True
for line in open(filname):
if first:
first = False
else:
row = line.split(',')
Y.append(int(row[0]))
X.append([int(p) for p in row[1].split()])
X = np.array(X) / 255.0
return X
X = getData(filname)
N, D = X.shape
X = X.reshape(N, 48, 48, 1)
from keras.models import load_model
model = load_model('D:/kaggle/表情识别/my_model.h5')
Y = model.predict(X)
ans = []
rows,columns=Y.shape
for i in range(rows):
tmp=0
for j in range(columns):
if Y[i,j]>Y[i,tmp]:
tmp=j
ans.append(tmp)
np.savetxt('D:/kaggle/表情识别/answer.csv',ans,fmt='%lf')