-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
62 lines (39 loc) · 1.5 KB
/
test.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
import util
import config as cfg
import tensorflow as tf
from keras import backend as K
import numpy as np
import helpers
import os
from SegNet import SegNet
from keras.models import Model, load_model
K.tensorflow_backend._get_available_gpus()
# this needs to get generalized
class_names_list, label_values = helpers.get_label_info(os.path.join("CamVid", "class_dict.csv"))
num_classes = len(label_values)
#get data name list
train_input_names, train_output_names, test_input_names, test_output_names = util.prepare_data(cfg.DATASET_DIR)
test_data = []
test_labels = []
print("Loading test data ...")
for img_name in test_input_names:
input_image = util.load_image(img_name)
with tf.device('/cpu:0'):
input_image = np.float32(input_image) / 255.0
test_data.append(input_image)
print(img_name)
for labels_name in test_output_names:
output_image = util.load_image(labels_name)
with tf.device('/cpu:0'):
output_image = np.float32(helpers.one_hot_it(label=output_image, label_values=label_values))
test_labels.append(output_image)
print(labels_name)
test_data = np.array(test_data)
test_labels = np.array(test_labels)
print("Finish loading the data. ")
print("Start testing...")
segnet = SegNet()
segnet.load_model()
test_result = segnet.model.evaluate(x=test_data, y=test_labels, batch_size=cfg.BATCH_SIZE, verbose=cfg.VERBOSE)
print("loss = {:.2f} accuracy = {:.2f}".format(test_result[0], test_result[1]))
#model = UNet.load_model(cfg.MODEL_PATH)