def test_model(model_save_dir_path): print('Started') (model_name, channel_numbers, img_size, epochs, batch_size, starts_neuron, start_case_index_train, end_case_index_train, start_case_index_test, end_case_index_test) = load_variables() print('Variables loaded') model = get_model_builder(model_name)(img_size, img_size, channel_numbers, starts_neuron) print("Model built") model.summary() print("Model summary") test_images, test_labels = get_images_and_masks(img_size, img_size, start_case_index_test, end_case_index_test, True) print("Test data loaded") loss, acc = model.evaluate(test_images, test_labels, verbose=1) print("Restored model, accuracy: {:5.2f}%".format(100 * acc)) model.load_weights(model_save_dir_path) print("Model weights loaded") print("Prediction started") preds_test = model.predict(test_images, verbose=1) preds_test_t = (preds_test > 0.6).astype(np.uint8) f1_score_result = f1_score(test_labels.flatten().flatten(), preds_test_t.flatten().flatten()) print('F1 score: %f' % f1_score_result)
import numpy as np import pandas as pd from numpy import arange from sklearn.metrics import f1_score, precision_score, recall_score from models_builders import get_model_builder from utils.read_data import get_images_and_masks from utils.utils import load_variables print("[LOG] Starting application") print('[LOG] Loading variables') (model_name, channel_numbers, img_size, epochs, batch_size, starts_neuron, start_case_index_train, end_case_index_train, start_case_index_test, end_case_index_test, trained_model_weights_path) = load_variables() print('[LOG] Did load variables') print('[LOG] Building model') model = get_model_builder(model_name)(img_size, img_size, channel_numbers, starts_neuron) print('[LOG] Load trained model weights') model.load_weights(trained_model_weights_path) print('[LOG] Loading test data for cases from: ', start_case_index_test, " to: ", end_case_index_test) test_images, test_labels = get_images_and_masks(img_size, img_size, start_case_index_test, end_case_index_test, True) print("[LOG] Did load test data")
import numpy as np from sklearn.metrics import f1_score from models_builders import get_model_builder from utils.paths_definition import get_prediction_results_image_path, get_prediction_results_case_dir from utils.prediction_result_utils import add_text_to_image, add_original_mask_to_image, add_predict_mask_to_image from utils.read_data import get_images_and_masks from utils.utils import load_variables print("[LOG] Starting application") print('[LOG] Loading variables') (model_name, channel_numbers, img_size, epochs, batch_size, starts_neuron, start_case_index_train, end_case_index_train, start_case_index_test, end_case_index_test, trained_model_weights_path, threshold) = load_variables() print('[LOG] Did load variables') print('[LOG] Building model') model = get_model_builder(model_name)(img_size, img_size, channel_numbers, starts_neuron) print('[LOG] Load trained model weights') model.load_weights(trained_model_weights_path) for case_index in range(start_case_index_test, end_case_index_test + 1): print('[LOG] Loading test data for case: ', case_index) test_images, test_labels = get_images_and_masks(img_size, img_size, case_index, case_index, True) print("[LOG] Did load test data")
print('[LOG] Loading variables') ( model_name, channel_numbers, img_size, epochs, batch_size, starts_neuron, start_case_index_train, end_case_index_train, start_case_index_test, end_case_index_test, trained_model_weights_path, threshold ) = load_variables() print('[LOG] Did load variables') print('[LOG] Building model') model = get_model_builder(model_name)( img_size, img_size, channel_numbers, starts_neuron ) print('[LOG] Load trained model weights') model.load_weights(trained_model_weights_path) for case_index in range(start_case_index_test, end_case_index_test + 1): print('[LOG] Loading test data for case: ', case_index)