-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluate.py
34 lines (26 loc) · 1.2 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
# the folder path of your CheXpert and CheXphoto datasets
# e.g. your dataset is in /aaa/bbb/CheXpert-v1.0, then dataset_path='/aaa/bbb'
dataset_path = ''
ptrn_path = 'instances/best_iou.h5'
img_size = (224, 224)
from tensorflow.keras.models import load_model
from tensorflow.keras.applications.densenet import preprocess_input
from utils import *
import numpy as np
import cv2 as cv
import os
# Use CPU
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
ptrn = load_model(ptrn_path)
x_valid, y_valid = load_validation_data(dataset_path, dataset_name='CheXphoto-natural', size=img_size)
loss = ptrn.evaluate(preprocess_input(x_valid), y_valid)
y_pred = ptrn.predict(preprocess_input(x_valid))
ious = [IOU(y_t, y_p) for y_t, y_p in zip(y_valid, y_pred)]
iou = np.mean(ious)
print('PTRN evaluated on validation data: loss: {:.4f}, IOU: {:.4f}'.format(loss, iou))
x_valid, y_valid = load_validation_data(dataset_path, dataset_name='CheXphoto-film', size=img_size)
loss = ptrn.evaluate(preprocess_input(x_valid), y_valid)
y_pred = ptrn.predict(preprocess_input(x_valid))
ious = [IOU(y_t, y_p) for y_t, y_p in zip(y_valid, y_pred)]
iou = np.mean(ious)
print('PTRN evaluated on test data: loss: {:.4f}, IOU: {:.4f}'.format(loss, iou))