-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathload_traindata.py
73 lines (50 loc) · 1.66 KB
/
load_traindata.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
import numpy as np
import pandas as pd
import os
import pickle
from keras.preprocessing import image
# In[2]:
X_train = []
y_train = []
input_size = (96, 96)
# In[3]:
folderpath = 'CERTH_ImageBlurDataset/TrainingSet/Undistorted/'
# load image arrays
for filename in os.listdir(folderpath):
if filename != '.DS_Store':
imagepath = folderpath + filename
img = image.load_img(imagepath, target_size = input_size)
X_train.append((1/255)*np.asarray(img))
y_train.append(0)
else:
print(filename, 'not a pic')
print("Trainset: Undistorted loaded...")
# In[4]:
folderpath = 'CERTH_ImageBlurDataset/TrainingSet/Artificially-Blurred/'
# load image arrays
for filename in os.listdir(folderpath):
if filename != '.DS_Store':
imagepath = folderpath + filename
img = image.load_img(imagepath, target_size=input_size)
X_train.append((1/255)*np.asarray(img))
y_train.append(1)
else:
print(filename, 'not a pic')
print("Trainset: Artificially Blurred loaded...")
# In[5]:
folderpath = 'CERTH_ImageBlurDataset/TrainingSet/Naturally-Blurred/'
# load image arrays
for filename in os.listdir(folderpath):
if filename != '.DS_Store':
imagepath = folderpath + filename
img = image.load_img(imagepath, target_size=input_size)
X_train.append((1/255)*np.asarray(img))
y_train.append(1)
else:
print(filename, 'not a pic')
print("Trainset: Naturally Blurred loaded...")
# Pickle the train files
with open('X_train.pkl', 'wb') as picklefile:
pickle.dump(X_train, picklefile)
with open('y_train.pkl', 'wb') as picklefile:
pickle.dump(y_train, picklefile)