-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluate.py
44 lines (32 loc) · 1.21 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
import cv2
import numpy as np
from tensorflow.keras.preprocessing import image
from keras.models import load_model
class Evaluator:
@staticmethod
def __load_image(img_path, w=200, h=200):
img = image.load_img(img_path, target_size=(w, h))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255.
return img_tensor
@staticmethod
def __show_result(img_path, probability):
img = cv2.imread(img_path)
img = cv2.resize(img, (800, 800))
font = cv2.FONT_HERSHEY_SIMPLEX
org = (25, 25)
font_scale = 1
color = (10, 10, 255)
thickness = 1
img = cv2.putText(img, 'tumor probability:' + str(probability[0][0] * 100.0)[0:5], org, font,
font_scale, color, thickness, cv2.LINE_AA)
cv2.imshow("tumor probability", img)
cv2.waitKey(0)
def evaluate(self, model_path, image_path):
model = load_model(model_path)
print(model.summary())
img_path = image_path
input_image = self.__load_image(img_path)
tumor_prob = model.predict(input_image)
self.__show_result(img_path, tumor_prob)