-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_training.py
65 lines (43 loc) · 1.6 KB
/
extra_training.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
55
56
57
58
59
60
61
62
63
64
65
import os
import pickle
import numpy as np
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import tensorflow as tf
from tensorflow import keras
from keras import layers
from time import perf_counter
from sklearn.model_selection import train_test_split
list_of_images = 'list_of_images.pkl'
list_of_answers = 'list_of_answers.pkl'
open_images_file = open(list_of_images, "rb")
images_list = pickle.load(open_images_file)
open_images_file.close()
open_answers_file = open(list_of_answers, "rb")
answers_list = pickle.load(open_answers_file)
open_answers_file.close()
images_list = list(images_list)
answers_list = list(answers_list)
images_list = np.array(images_list)
answers_list = np.array(answers_list)
train_images, test_images, train_labels, test_labels = train_test_split(
images_list, answers_list, test_size=0.25
)
train_images = train_images / 255.0
test_images = test_images / 255.0
print(train_images.shape)
print(train_labels.shape)
model = tf.keras.models.load_model("BCM_LiteTurboPrime4.h5")
print(model.summary())
loss = keras.losses.BinaryCrossentropy(from_logits=True)
optim = keras.optimizers.Adam(learning_rate=0.01)
metrics = ["accuracy"]
model.compile(optimizer=optim, loss=loss, metrics=metrics)
batch_size = 64
epochs = 3
start_time = perf_counter()
model.fit(train_images, train_labels, epochs=epochs, batch_size=batch_size, verbose=2)
model.evaluate(test_images, test_labels, batch_size=batch_size, verbose=2)
model.save("BCM_LiteTurboPrime5.h5")
end_time = perf_counter()
print("\n-----------------------------\n")
print(f"Operation took {round(end_time - start_time)} second(s) to complete!")