-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
53 lines (38 loc) · 1.12 KB
/
utils.py
File metadata and controls
53 lines (38 loc) · 1.12 KB
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
import os
import numpy as np
import matplotlib.pyplot as plt
import cv2
import pickle
import random
data_dir = './flowers'
data = []
img_size = 125
categories = ["daisy", "dandelion", "rose", "sunflower", "tulip"]
def create_data():
for category in categories:
path = os.path.join(data_dir, category)
class_num = categories.index(category)
for img in os.listdir(path):
img_arr = cv2.imread(os.path.join(path, img))
try:
new_arr = cv2.resize(img_arr, (img_size, img_size))
except cv2.error as e:
pass
cv2.waitKey()
data.append([new_arr, class_num])
create_data()
def load_data():
random.shuffle(data)
X = []
y = []
for features, labels in data:
X.append(features)
y.append(labels)
X = np.array(X).reshape(-1, img_size, img_size, 3)
y = np.array(y)
return X, y
(X, y) = load_data()
pickle_out = open('X.pickle', 'wb')
pickle.dump(X, pickle_out)
pickle_out_2 = open('y.pickle', 'wb')
pickle.dump(y, pickle_out_2)