create-dataset.py 1.02 KB
Newer Older
Bc. Matej Slebodník's avatar
Bc. Matej Slebodník committed
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
from os import listdir
from numpy import asarray
from numpy import vstack
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from numpy import savez_compressed

#nacitanie obrazkov
def load_images(path, size=(256,256)):
	data_list = list()
	for filename in listdir(path):
		pixels = load_img(path + filename, target_size=size)
		pixels = img_to_array(pixels)
		data_list.append(pixels)
	return asarray(data_list)

# nacitat z google drive
path = '/content/drive/MyDrive/data-final/'

#nacitat dataset A = bernese
dataA1 = load_images(path + 'bernese-train/')
dataAB = load_images(path + 'bernese-test/')
dataA = vstack((dataA1, dataAB))
print('Loaded dataA: ', dataA.shape)

#nacitat  dataset B = samoyed
dataB1 = load_images(path + 'samoyed-train/')
dataB2 = load_images(path + 'samoyed-test/')
dataB = vstack((dataB1, dataB2))
print('Loaded dataB: ', dataB.shape)

#ulozit do numpy array
filename = 'bernese-samoyed.npz'
savez_compressed(filename, dataA, dataB)
print('Saved dataset: ', filename)