-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_dataset.py
70 lines (49 loc) · 2.36 KB
/
load_dataset.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
from __future__ import print_function
from scipy import misc
import os
import numpy as np
import sys
TEST_LOCATION="C:/FER/Projekt/unmasked_test/"
def load_test_data(IMAGE_SIZE):
test_directory_phone = TEST_LOCATION+"/"
test_directory_dslr = TEST_LOCATION + "/original/"
NUM_TEST_IMAGES = len([name for name in os.listdir(test_directory_phone)
if os.path.isfile(os.path.join(test_directory_phone, name))])
test_data = np.zeros((NUM_TEST_IMAGES, IMAGE_SIZE))
test_answ = np.zeros((NUM_TEST_IMAGES, IMAGE_SIZE))
for i in range(0, NUM_TEST_IMAGES):
I = np.asarray(misc.imread(test_directory_phone + str(i+9014) + '.png'))
I = np.float16(np.reshape(I, [1, IMAGE_SIZE]))/255
test_data[i, :] = I
I = np.asarray(misc.imread(test_directory_dslr + str(i+9014) + '.png'))
I = np.float16(np.reshape(I, [1, IMAGE_SIZE]))/255
test_answ[i, :] = I
if i % 100 == 0:
print(str(round(i * 100 / NUM_TEST_IMAGES)) + "% done", end="\r")
return test_data, test_answ
def load_batch(dped_dir, TRAIN_SIZE, IMAGE_SIZE):
train_directory_phone = dped_dir+"/"
train_directory_dslr = dped_dir + "/original/"
NUM_TRAINING_IMAGES = len([name for name in os.listdir(train_directory_phone)
if os.path.isfile(os.path.join(train_directory_phone, name))])
NUM_TRAINING_IMAGES-=3
# if TRAIN_SIZE == -1 then load all images
if TRAIN_SIZE == -1:
TRAIN_SIZE = NUM_TRAINING_IMAGES
TRAIN_IMAGES = np.arange(0, TRAIN_SIZE)
else:
TRAIN_IMAGES = np.random.choice(np.arange(0, NUM_TRAINING_IMAGES), TRAIN_SIZE, replace=False)
train_data = np.zeros((TRAIN_SIZE, IMAGE_SIZE))
train_answ = np.zeros((TRAIN_SIZE, IMAGE_SIZE))
i = 0
for img in TRAIN_IMAGES:
I = np.asarray(misc.imread(train_directory_phone + str(img) + '.png'))
I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
train_data[i, :] = I
I = np.asarray(misc.imread(train_directory_dslr + str(img) + '.png'))
I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
train_answ[i, :] = I
i += 1
if i % 100 == 0:
print(str(round(i * 100 / TRAIN_SIZE)) + "% done", end="\r")
return train_data, train_answ