def test_get_next_image(self): img = imread(self.test_path_image, IMREAD_COLOR) img = cvtColor(img, COLOR_BGR2RGB) img_resized = resize(img, (224, 224)) img_final = img_resized / 255.0 img_actual = modelUtils.get_image_at_index([self.test_path_image], 0) assert_allclose(img_actual, img_final)
def test_create_training_data(self): expected_x_value = modelUtils.get_image_at_index( [self.test_path_image], 0) expected_y_value = 0 makeDataset.create_training_data(1, 'x_data_test', 'y_data_test') actual_x_value = np.load('x_data_test.npy')[0] / 255.0 actual_y_value = np.load('y_data_test.npy')[0] assert_allclose(expected_x_value, actual_x_value) self.assertEqual(expected_y_value, actual_y_value)
def test_generator(self): expected = ([modelUtils.get_image_at_index([self.test_path_image], 0)], 0) for batch in modelUtils.generator(array([self.test_path_image]), array([self.test_path_descriptions]), 1): actual_image, actual_label = batch expected_image, expected_label = expected self.assertEqual(len(actual_image), len(expected_image)) self.assertEqual(actual_label, expected_label) break
else: thisplot[0].set_color('red') num_rows = 5 num_cols = 3 num_images = num_rows * num_cols test_images = [] test_labels = [] for i in range(num_images): index = int(random.choice(len(X_file_names), 1)) file_name = os.path.join(DATADIR, X_file_names[index]) print(file_name) image = get_image_at_index(np.array([file_name]), 0) test_images.append(image) test_labels.append(get_label(os.path.join(DATADESC, y_file_names[index]))) model = load_model('resmodel') predictions = model.predict(np.array(test_images)) plt.figure(figsize=(2 * 2 * num_cols, 2 * num_rows)) for i in range(num_images): plt.subplot(num_rows, 2 * num_cols, 2 * i + 1) plot_image(i, predictions, test_labels, test_images) plt.subplot(num_rows, 2 * num_cols, 2 * i + 2) plot_value_array(i, predictions, test_labels) plt.show()
X_file_names = np.array(os.listdir(DATADIR)) y_file_names = np.array(os.listdir(DATADESC)) num_rows = 5 num_cols = 3 num_images = num_rows * num_cols images = [] images_aug = [] for i in range(num_images): index = int(random.choice(len(X_file_names), 1)) #test_images.append(cv2.resize(cv2.imread(os.path.join(DATADIR,X_file_names[index])),(224,224))) file_name = os.path.join(DATADIR, X_file_names[index]) print(file_name) image = modelUtils.get_image_at_index(np.array([file_name]), 0) image_aug = modelUtils.get_image_at_index_with_transform( np.array([file_name]), 0) images.append(image) images_aug.append(image_aug) plt.figure(figsize=(2 * 2 * num_cols, 2 * num_rows)) for i in range(num_images): plt.subplot(num_rows, 2 * num_cols, 2 * i + 1) plt.imshow(images[i]) plt.xticks([]) plt.yticks([]) plt.subplot(num_rows, 2 * num_cols, 2 * i + 2) plt.imshow(images_aug[i]) plt.xticks([]) plt.yticks([])