-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_dataset.py
69 lines (51 loc) · 2.64 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
from __future__ import print_function
from scipy import misc
import os
import numpy as np
import sys
def load_test_data(phone, dped_dir, IMAGE_SIZE):
test_directory_phone = dped_dir + str(phone) + '/test_data/patches/' + str(phone) + '/'
test_directory_dslr = dped_dir + str(phone) + '/test_data/patches/canon/'
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) + '.jpg'))
#I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
#test_data[i, :] = I
test_data.append(test_directory_phone + str(i) + '.jpg')
#I = np.asarray(misc.imread(test_directory_dslr + str(i) + '.jpg'))
#I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
#test_answ[i, :] = I
test_answ.append(test_directory_dslr + str(i) + '.jpg')
if i % 100 == 0:
print(str(round(i * 100 / NUM_TEST_IMAGES)) + "% done", end="\r")
return test_data, test_answ
def load_batch(phone, dped_dir, TRAIN_SIZE, IMAGE_SIZE):
train_directory_phone = dped_dir + str(phone) + '/training_data/' + str(phone) + '/'
train_directory_dslr = dped_dir + str(phone) + '/training_data/canon/'
NUM_TRAINING_IMAGES = len([name for name in os.listdir(train_directory_phone)
if os.path.isfile(os.path.join(train_directory_phone, name))])
# 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) + '.jpg'))
#I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
#train_data[i, :] = I
train_data.append(train_directory_phone + str(img) + '.jpg')
#I = np.asarray(misc.imread(train_directory_dslr + str(img) + '.jpg'))
#I = np.float16(np.reshape(I, [1, IMAGE_SIZE])) / 255
#train_answ[i, :] = I
train_answ.append(train_directory_dslr + str(img) + '.jpg')
i += 1
if i % 100 == 0:
print(str(round(i * 100 / TRAIN_SIZE)) + "% done", end="\r")
return train_data, train_answ