-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.py
38 lines (32 loc) · 1.02 KB
/
loader.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
import os
import Image
import numpy as np
numberOfImgs = 1020
def load_img():
"""
Load training image
Return: The labels and the images
"""
# Create the temporary folder
if not os.path.exists("./temp"):
os.mkdir("./temp")
# Resize the images to the temporary folder
imgs = os.listdir("./Img/Train/All/")
for i in range(len(imgs)):
img = Image.open("./Img/Train/All/" + imgs[i])
img = img.resize((200, 200))
img.save("./temp/" + imgs[i])
# Load the images again and product the labels
datas = np.empty((numberOfImgs, 3, 200, 200), dtype="float32")
labls = np.empty((numberOfImgs), dtype="uint8")
imgs = os.listdir("./temp")
print len(imgs)
for i in range(len(imgs)):
img = Image.open("./temp/" + imgs[i])
img = np.asarray(img, dtype="float32")
img = img.reshape((3, 200, 200))
datas[i, :, :, :] = img
labls[i] = int( imgs[i].split('.')[0] )
print np.shape(datas)
return datas, labls
load_img()