-
Notifications
You must be signed in to change notification settings - Fork 28
/
load_testdata.py
91 lines (53 loc) · 1.92 KB
/
load_testdata.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
import numpy as np
import pandas as pd
import os
import pickle
from keras.preprocessing import image
# In[2]:
input_size = (96, 96)
X_test = []
y_test = []
# In[7]:
dgbset = pd.read_excel('CERTH_ImageBlurDataset/EvaluationSet/DigitalBlurSet.xlsx')
nbset = pd.read_excel('CERTH_ImageBlurDataset/EvaluationSet/NaturalBlurSet.xlsx')
# In[8]:
dgbset['MyDigital Blur'] = dgbset['MyDigital Blur'].apply(lambda x : x.strip())
dgbset = dgbset.rename(index=str, columns={"Unnamed: 1": "Blur Label"})
# In[9]:
nbset['Image Name'] = nbset['Image Name'].apply(lambda x : x.strip())
# In[18]:
folderpath = 'CERTH_ImageBlurDataset/EvaluationSet/DigitalBlurSet/'
# 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_test.append((1/255)*np.asarray(img))
blur = dgbset[dgbset['MyDigital Blur'] == filename].iloc[0]['Blur Label']
if blur == 1:
y_test.append(1)
else:
y_test.append(0)
else:
print(filename, 'not a pic')
print("Testset: Artificially Blurred loaded...")
# In[19]:
folderpath = 'CERTH_ImageBlurDataset/EvaluationSet/NaturalBlurSet/'
# 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_test.append((1/255)*np.asarray(img))
blur = nbset[nbset['Image Name'] == filename.split('.')[0]].iloc[0]['Blur Label']
if blur == 1:
y_test.append(1)
else:
y_test.append(0)
else:
print(filename, 'not a pic')
print("Trainset: Naturally Blurred loaded...")
with open('X_test.pkl', 'wb') as picklefile:
pickle.dump(X_test, picklefile)
with open('y_test.pkl', 'wb') as picklefile:
pickle.dump(y_test, picklefile)