-
Notifications
You must be signed in to change notification settings - Fork 5
/
read_data.py
executable file
·209 lines (183 loc) · 7.37 KB
/
read_data.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#import cv2
import pickle
import numpy as np
import PIL
from PIL import Image
import os.path
import sys
# import cv2
def get_train_data(chunk, img_row, img_col):
# print(" \n get train data - running")
X_train = []
Y_train = []
with open("/home/amit/Desktop/vignesh/allmerge2.pickle",'rb') as f1:
spatial_train_data=pickle.load(f1)
try:
for imgname in chunk:
filename = "/home/amit/Desktop/vignesh/allmerge/"+str(imgname)+'.jpg'
if os.path.exists(filename) == True:
# print(filename)
# img = cv2.imread(filename)
# img = np.rollaxis(cv2.resize(img,(img_row,img_col)).astype(np.float32),2)
a = Image.open(filename)
# print("image opened")
a = a.resize((img_row,img_col), PIL.Image.ANTIALIAS)
# print("resized")
img = np.asarray(a)
# print("converted")
img = np.rollaxis(img.astype(np.float32),2)
# print("rolled")
X_train.append(img)
# print("image appended")
# print("X_train shape is {0}".format(len(X_train)))
Y_train.append(spatial_train_data[imgname])
# print("Y_train shape is {0}".format(len(Y_train)))
X_train = np.asarray(X_train)
Y_train = np.asarray(Y_train)
# print(Y_train.shape)
# print(" \n get train data - finished")
return X_train,Y_train
except:
X_train=None
Y_train=None
print(" \n get train data exception- finished")
return X_train,Y_train
def get_train_data_11_04(chunk, img_row, img_col):
print(" \n get train data - running")
X_train = []
Y_train = []
with open("/home/amit/Desktop/vignesh/11_04_backsub.pickle",'rb') as f1:
spatial_train_data=pickle.load(f1)
try:
for imgname in chunk:
filename = "/home/amit/Desktop/vignesh/11_04_merge/"+str(imgname)+'.jpg'
if os.path.exists(filename) == True:
print(filename)
# img = cv2.imread(filename)
# img = np.rollaxis(cv2.resize(img,(img_row,img_col)).astype(np.float32),2)
a = Image.open(filename)
print("image opened")
a = a.resize((img_row,img_col), PIL.Image.ANTIALIAS)
print("resized")
img = np.asarray(a)
print("converted")
img = np.rollaxis(img.astype(np.float32),2)
print("rolled")
X_train.append(img)
print("image appended")
# print("X_train shape is {0}".format(len(X_train)))
Y_train.append(spatial_train_data[imgname])
# print("Y_train shape is {0}".format(len(Y_train)))
X_train = np.asarray(X_train)
Y_train = np.asarray(Y_train)
print(Y_train.shape)
print(" \n get train data - finished")
return X_train,Y_train
except:
X_train=None
Y_train=None
print(" \n get train data exception- finished")
return X_train,Y_train
def get_train_data_11_03(chunk, img_row, img_col):
print(" \n get train data - running")
X_train = []
Y_train = []
with open("/home/amit/Desktop/vignesh/11_03_backsub.pickle",'rb') as f1:
spatial_train_data=pickle.load(f1)
try:
for imgname in chunk:
filename = "/home/amit/Desktop/vignesh/11_03_merge/"+str(imgname)+'.jpg'
if os.path.exists(filename) == True:
print(filename)
# img = cv2.imread(filename)
# img = np.rollaxis(cv2.resize(img,(img_row,img_col)).astype(np.float32),2)
a = Image.open(filename)
print("image opened")
a = a.resize((img_row,img_col), PIL.Image.ANTIALIAS)
print("resized")
img = np.asarray(a)
print("converted")
img = np.rollaxis(img.astype(np.float32),2)
print("rolled")
X_train.append(img)
print("image appended")
# print("X_train shape is {0}".format(len(X_train)))
Y_train.append(spatial_train_data[imgname])
# print("Y_train shape is {0}".format(len(Y_train)))
X_train = np.asarray(X_train)
Y_train = np.asarray(Y_train)
print(Y_train.shape)
print(" \n get train data - finished")
return X_train,Y_train
except:
X_train=None
Y_train=None
print(" \n get train data exception- finished")
return X_train,Y_train
def get_train_data_08_02(chunk, img_row, img_col):
print(" \n get train data - running")
X_train = []
Y_train = []
with open("/home/amit/Desktop/vignesh/08_02_backsub.pickle",'rb') as f1:
spatial_train_data=pickle.load(f1)
try:
for imgname in chunk:
filename = "/home/amit/Desktop/vignesh/08_02_merge/"+str(imgname)+'.jpg'
if os.path.exists(filename) == True:
print(filename)
# img = cv2.imread(filename)
# img = np.rollaxis(cv2.resize(img,(img_row,img_col)).astype(np.float32),2)
a = Image.open(filename)
print("image opened")
a = a.resize((img_row,img_col), PIL.Image.ANTIALIAS)
print("resized")
img = np.asarray(a)
print("converted")
img = np.rollaxis(img.astype(np.float32),2)
print("rolled")
X_train.append(img)
print("image appended")
# print("X_train shape is {0}".format(len(X_train)))
Y_train.append(spatial_train_data[imgname])
# print("Y_train shape is {0}".format(len(Y_train)))
X_train = np.asarray(X_train)
Y_train = np.asarray(Y_train)
print(Y_train.shape)
print(" \n get train data - finished")
return X_train,Y_train
except:
X_train=None
Y_train=None
print(" \n get train data exception- finished")
return X_train,Y_train
def get_test_data(chunk, img_row, img_col):
# print(" \n get test data - running")
# print(len(chunk))
X_test = []
Y_test = []
with open("/home/amit/Desktop/vignesh/allmerge2.pickle",'rb') as f1:
spatial_test_data=pickle.load(f1)
try:
for imgname in chunk:
filename = "/home/amit/Desktop/vignesh/allmerge/"+imgname+'.jpg'
if os.path.exists(filename) == True:
# print(filename)
# img = cv2.imread(filename)
# img = np.rollaxis(cv2.resize(img,(img_row,img_col)).astype(np.float32),2)
a = Image.open(filename)
a = a.resize((img_row,img_col), PIL.Image.ANTIALIAS)
img = np.asarray(a)
img = np.rollaxis(img.astype(np.float32),2)
X_test.append(img)
Y_test.append(spatial_test_data[imgname])
X_test = np.asarray(X_test)
Y_test = np.asarray(Y_test)
# print(" \n get test data - finished")
return X_test,Y_test
except:
X_test=None
Y_test=None
print(" \n get test data exception - finished")
return X_test,Y_test
if __name__ == '__main__':
gc.collect()