-
Notifications
You must be signed in to change notification settings - Fork 0
/
hickle_data.py
54 lines (43 loc) · 1.38 KB
/
hickle_data.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
import gzip, cPickle
from glob import glob
import numpy as np
from PIL import Image
import os
from tqdm import tqdm
import hickle as hkl
print("converting image to numpy array rgb format ---- White")
imlist = os.listdir('./resized_images_white_n/')
pbar = tqdm(total=len(imlist))
ImageDataWhite = []
for img in imlist:
img = np.array(Image.open('./resized_images_white_n/'+img).convert('RGB'))
# from scipy.misc import toimage
# toimage(img).show()
ImageDataWhite.append(img)
pbar.update(1)
pbar.close()
ImageDataWhite = np.array(ImageDataWhite)
print("converting image to numpy array rgb format ---- Black")
imlist = os.listdir('./resized_images_black_n/')
pbar = tqdm(total=len(imlist))
ImageDataBlack = []
for img in imlist:
img = np.array(Image.open('./resized_images_black_n/'+img).convert('RGB'))
ImageDataBlack.append(img)
pbar.update(1)
pbar.close()
ImageDataBlack = np.array(ImageDataBlack)
dataset = np.array([ImageDataWhite, ImageDataBlack])
print("Pickling dataset now. Sit tight :) ")
try:
# f = gzip.open( direcory + 'dataset.pkl.gz','wb')
# cPickle.dump(dataset, f, protocol=2)
# f.close()
# Dump data, with compression
hkl.dump(dataset, 'dataset.hkl', mode='w', compression='gzip')
except Exception as e:
print (e)
raise
# with open('dataset.pickle', 'wb') as f:
# cPickle.dump(dataset, f, protocol=4)
print("All done :):)")