-
Notifications
You must be signed in to change notification settings - Fork 2
/
PreProcess.py
57 lines (45 loc) · 1.16 KB
/
PreProcess.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
# -*- coding: utf-8 -*-
"""
Created on Thu May 26 21:11:42 2016
@author: shrestha
"""
### PreProcessing
import csv
import numpy as np
import cPickle as pickle
#import matplotlib.pyplot as plt
#import random as rand
import math
'''
XTrain=pickle.load(open('XTrain','rb'))
yTrain=pickle.load(open('yTrain','rb'))
XValid=pickle.load(open('XValid','rb'))
yValid=pickle.load(open('yValid','rb'))
XTest=pickle.load(open('XTest','rb'))
yTest=pickle.load(open('yTest','rb'))
'''
##Subtracting mean from image
def removeDC(X):
mean=np.mean(X,axis=1)
mean=np.mean(mean).transpose()
X=X-mean
return X
def normaliseAndFit(Xtrain,X):
mean=np.mean(Xtrain,axis=0)
std=np.std(Xtrain,axis=0)
Xtrain=(Xtrain-mean)/std
X=(X-mean)/std
return Xtrain,X
#XTrain=np.reshape(XTrain,(48,48))
mean=np.mean(XTrain)
'''
XTrain=removeDC(XTrain)
XValid=removeDC(XValid)
XTrain,XValid=normaliseAndFit(XTrain,XValid)
pickle.dump(XTrain,open('XNormTrain','wb'))
#pickle.dump(yTrain,open('yTrain','wb'))
pickle.dump(XValid,open('XNormValid','wb'))
#pickle.dump(yValid,open('yValid','wb'))
#pickle.dump(XTest,open('XTest','wb'))
#pickle.dump(yTest,open('yTest','wb'))
'''