-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataProcessor.py
More file actions
62 lines (53 loc) · 2.2 KB
/
Copy pathdataProcessor.py
File metadata and controls
62 lines (53 loc) · 2.2 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
54
55
56
57
58
59
60
61
62
import numpy as np
import matplotlib.pyplot as plt
class DataProcessor:
def __init__(self):
self.__train_data = None
self.__test_data = None
@property
def training_data(self):
return self.__train_data
@training_data.setter
def training_data(self, new_data):
self.__train_data = new_data
@property
def testing_data(self):
return self.__test_data
@testing_data.setter
def testing_data(self, new_data):
self.__test_data = new_data
def print_sample(self):
if self.__train_data is None:
raise Exception("Data has not been set.")
fig, axs = plt.subplots(2, 5)
for j in [0, 1]:
for i in range(5):
index = np.random.randint(100, size=10)[i + (5 * j)]
image = self.__train_data["X"][:, :, :, index]
label = self.__train_data["y"][index]
axs[j, i].imshow(image, cmap="gray")
axs[j, i].axis("off")
axs[j, i].set_title(f'Image {index},\n label {label}')
plt.suptitle("Random Image Sample")
plt.show()
def print_sample_grey(self):
if self.__train_data is None:
raise Exception("Data has not been set.")
fig, axs = plt.subplots(2, 5)
for j in [0, 1]:
for i in range(5):
index = np.random.randint(100, size=10)[i + (5 * j)]
image = self.__train_data["X"][index, :, :, :]
label = self.__train_data["y"][index]
axs[j, i].imshow(image, cmap="gray")
axs[j, i].axis("off")
axs[j, i].set_title(f'Image {index},\n label {label}')
plt.suptitle("Random Image Sample \n Grey Version")
plt.show()
def grey_scaling(self):
if self.__train_data is None:
raise Exception("Data has not been set.")
self.__train_data["X"] = np.moveaxis(self.__train_data["X"], -1, 0)
self.__train_data["X"] = np.mean(self.__train_data["X"], 3).reshape(73257, 32, 32, 1)/255
self.__test_data["X"] = np.moveaxis(self.__test_data["X"], -1, 0)
self.__test_data["X"] = np.mean(self.__test_data["X"], 3).reshape(26032, 32, 32, 1)/255