from ResUnet import * model = ResUnet(input_size=(512, 512, 3), start_neurons=16, keep_prob=1, block_size=1) weight = "Model/Luna/ResUnet.h5" if os.path.isfile(weight): model.load_weights(weight) model_checkpoint = ModelCheckpoint(weight, monitor='val_acc', verbose=1, save_best_only=True) y_pred = model.predict(x_test) y_pred_threshold = [] i = 0 for y in y_pred: _, temp = cv2.threshold(y, 0.5, 1, cv2.THRESH_BINARY) y_pred_threshold.append(temp) y = y * 255 cv2.imwrite('./Luna/test/result/%d.png' % i, y) i += 1 y_test = list(np.ravel(y_test)) y_pred_threshold = list(np.ravel(y_pred_threshold)) tn, fp, fn, tp = confusion_matrix(y_test, y_pred_threshold).ravel() print('Accuracy:', accuracy_score(y_test, y_pred_threshold))
import os import cv2 import numpy as np from sklearn.metrics import recall_score, roc_auc_score, accuracy_score, confusion_matrix from keras.callbacks import ModelCheckpoint from util import * import scipy.misc as mc import math data_location = '' testing_images_loc = data_location + 'Drive/test/images/' testing_label_loc = data_location + 'Drive/test/label/' test_files = os.listdir(testing_images_loc) test_data = [] test_label = [] desired_size = 592 for i in test_files: im = mc.imread(testing_images_loc + i) label = mc.imread(testing_label_loc + i.split('_')[0] + '_manual1.png') old_size = im.shape[:2] # old_size is in (height, width) format delta_w = desired_size - old_size[1] delta_h = desired_size - old_size[0] top, bottom = delta_h // 2, delta_h - (delta_h // 2) left, right = delta_w // 2, delta_w - (delta_w // 2) color = [0, 0, 0] color2 = [0] new_im = cv2.copyMakeBorder(im, top, bottom, left, right,