-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluate.py
61 lines (42 loc) · 1.6 KB
/
evaluate.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
"""
@Author Sujith Umapathy
Code to evaluate the performance of the trained model
"""
import os
import keras.backend as K
import numpy as np
from configuration import Config as conf
from utils.patch_images import patch_images
from utils.read_images import read_images
K.set_image_data_format('channels_last')
os.environ['SM_FRAMEWORK'] = 'tf.keras'
import segmentation_models as sm
def clean_list(list_data):
mod_list = []
for im, ma in list_data:
if ma.any():
mod_list.append((im, ma))
return mod_list
if __name__ == '__main__':
backbone = conf.backbone
pre_process_ip = sm.get_preprocessing(backbone)
print('Reading Images from test folder')
test_images = read_images(conf.test_folder_images)
test_mask = read_images(conf.test_folder_mask)
test_images = np.array(test_images)
test_mask = np.array(test_mask)
print('Patching Test Image Set')
# patch_images
t_test_images = patch_images(test_images)
t_test_masks = patch_images(test_mask)
t_test_images = np.stack((t_test_images,) * 3, axis=-1)
t_test_masks = np.expand_dims(t_test_masks, axis=-1)
t_test_images = pre_process_ip(t_test_images)
model = sm.Unet(backbone, encoder_weights='imagenet')
model.load_weights(f'{conf.model_path}model_resnet_18.h5')
model.compile(optimizer='Adam',
loss=sm.losses.binary_focal_jaccard_loss,
metrics=sm.metrics.IOUScore(threshold=0.5))
prediction_set = model.predict(t_test_images[:600])
score = model.evaluate(t_test_images[:600], prediction_set)
print(f'Test score: {score}')