-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcifar.py
executable file
·51 lines (40 loc) · 1.68 KB
/
cifar.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
#!/usr/bin/env python
import image_formatter
from tensorflow.keras import datasets
import pandas as pd
import cv2
import model
def load(width=32, height=32):
(train_images, train_labels), (test_images, test_labels) = \
datasets.cifar10.load_data()
for image in train_images:
cv2.resize(image, (width, height))
for image in test_images:
cv2.resize(image, (width, height))
return train_images, test_images, train_labels, test_labels
def main():
loss = {}
accuracy = {}
val_loss = {}
val_accuracy = {}
(orig_train_images, orig_test_images,
train_labels, test_labels) = load()
out_size = max(train_labels.max(), test_labels.max())+1
for color_space in image_formatter.color_spaces:
train_images = image_formatter.convert_images(orig_train_images,
color_space)
test_images = image_formatter.convert_images(orig_test_images,
color_space)
cifar_model = model.model(out_size)
history = cifar_model.fit(train_images, train_labels, epochs=10,
validation_data=(test_images, test_labels))
loss["cifar_" + color_space] = history.history["loss"]
val_loss["cifar_" + color_space] = history.history["val_loss"]
accuracy["cifar_" + color_space] = history.history["accuracy"]
val_accuracy["cifar_" + color_space] = history.history["val_accuracy"]
loss_df = pd.DataFrame(loss)
val_loss_df = pd.DataFrame(val_loss)
accuracy_df = pd.DataFrame(accuracy)
val_accuracy_df = pd.DataFrame(val_accuracy)
if __name__ == "__main__":
main()