-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_item_sockets.py
54 lines (43 loc) · 1.49 KB
/
test_item_sockets.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
from shared import test_model
from tensorflow.keras.layers import Conv2D, MaxPool2D, Dense, Flatten
from tensorflow.keras import Sequential
from tensorflow.keras.optimizers import RMSprop
import os
training_name = "item_sockets"
image_size = (200, 200)
model_file_path = "./training/{}/{}.h5".format(training_name, training_name)
classes_file_path = "./training/{}/{}-classes.txt".format(
training_name, training_name)
test_folder = "./images/{}/validation/".format(training_name)
if os.path.exists(model_file_path) and os.path.exists(classes_file_path):
f = open(classes_file_path, "r")
data = f.read()
classes = data.split(",")[:-1]
num_classes = len(classes)
model = Sequential([
Conv2D(16, (3, 3), activation="relu", input_shape=(
image_size[0], image_size[1], 3)),
MaxPool2D(2, 2),
Conv2D(32, (3, 3), activation="relu"),
MaxPool2D(2, 2),
Conv2D(64, (3, 3), activation="relu"),
MaxPool2D(2, 2),
Flatten(),
Dense(512, activation="relu"),
Dense(num_classes, activation="softmax")
])
model.compile(
loss="categorical_crossentropy",
optimizer=RMSprop(learning_rate=0.001),
metrics=["accuracy"]
)
model.load_weights(model_file_path)
test_model(
model=model,
test_folder=test_folder,
image_size=image_size,
classes=classes,
test_empty_image=False
)
else:
print("No model named {} available".format(training_name))