def test_feature_extraction_with_bow_with_export_and_load( self, detector: str): k = 3 dst = test_utils.get_test_output_csv_route() vocabulary_file = test_utils.get_test_output_ndarray_route() runner = CliRunner() result: Result = runner.invoke(cli, [ 'extract', '--bow', '--size', 64, '--detector', detector, '--src', test_utils.get_test_base_route(), '--dst', dst, '--k', k, '--export', '--vocabulary-route', vocabulary_file ]) test_utils.assert_validation_test(result) vocabulary = np.load(vocabulary_file) assert (vocabulary.shape[0] == k) test_utils.clean_test_output_csv_route() result: Result = runner.invoke(cli, [ 'extract', '--bow', '--size', 64, '--detector', detector, '--src', test_utils.get_test_base_route(), '--dst', dst, '--k', k, '--load', '--vocabulary-route', vocabulary_file ]) test_utils.assert_validation_test(result)
def test_features_are_extracted_using_a_loaded_model(self, method: str): output_file = test_utils.get_test_output_csv_route() vocabulary_file = test_utils.get_test_output_ndarray_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') extractor.setup() extractor.fit() extractor.export(vocabulary_file) new_extractor = BoWExtractor( base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') new_extractor.setup() new_extractor.load(vocabulary_file) new_extractor.extract_and_save(output_file) features = test_utils.load_csv_from_route(output_file) expected_width = extractor.k + 1 expected_height = test_utils.count_test_images() assert (features.shape == (expected_height, expected_width))
def test_image_is_converted_into_matrix_of_selected_size(self): extractor = LBPExtractor(test_utils.get_test_base_route(), size=64, points=3, radius=1, grid_x=2, grid_y=2) image = extractor._read_image(test_utils.get_test_image_route()) assert (image.shape == (extractor.width, extractor.height))
def test_feature_extraction_with_bow(self, detector: str): dst = test_utils.get_test_output_csv_route() runner = CliRunner() result: Result = runner.invoke(cli, [ 'extract', '--bow', '--size', 64, '--detector', detector, '--src', test_utils.get_test_base_route(), '--dst', dst, '--k', 2 ]) test_utils.assert_validation_test(result)
def test_feature_extraction_with_deep_models(self, cnn: str): dst = test_utils.get_test_output_csv_route() runner = CliRunner() result: Result = runner.invoke(cli, [ 'extract', '--deep', '--cnn', 'vgg19', '--size', 64, '--src', test_utils.get_test_base_route(), '--dst', dst ]) test_utils.assert_validation_test(result)
def test_local_binary_patterns_are_extracted_from_image(self): extractor = LBPExtractor(test_utils.get_test_base_route(), size=64, points=3, radius=1, grid_x=2, grid_y=2) image = extractor._read_image(test_utils.get_test_image_route()) lbp = extractor._extract_lbp(image) assert (lbp.shape == (extractor.width, extractor.height))
def test_single_image_features_extraction(self, x, y): extractor = LBPExtractor(test_utils.get_test_base_route(), size=64, points=3, radius=1, grid_x=x, grid_y=y) features = extractor.extract(test_utils.get_test_image_route()) expected_size = x * y * extractor.bins assert (features.shape[0] == expected_size)
def test_features_are_extracted_from_a_given_image_route(self, model: str): extractor = DeepExtractor(base_route=test_utils.get_test_base_route(), model_name=model, size=75) features = extractor.extract( image_route=test_utils.get_test_image_route()) output_shape = extractor.model.layers[-1].output_shape expected_shape = output_shape[1] * output_shape[2] * output_shape[3] assert (features.shape[0] == expected_shape)
def test_extraction_setup(self, method: str): extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64) extractor.setup() descriptors = extractor.bow_kmeans.getDescriptors() assert (len(descriptors) > 0) assert (len(descriptors) <= len(extractor.image_keypoints.keys()))
def test_keypoints_and_descriptors_detection(self, method: str): extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64) descriptors, keypoints = extractor._process_image( image_route=test_utils.get_test_image_route()) assert (len(descriptors) > 0) assert (keypoints.shape[0] == len(descriptors)) assert (keypoints.shape[1] == extractor.detector.descriptorSize())
def test_feature_extraction_with_lbp(self): dst = test_utils.get_test_output_csv_route() runner = CliRunner() result: Result = runner.invoke(cli, [ 'extract', '--lbp', '--size', 64, '--grid', 4, '--points', 8, '--radius', 1, '--src', test_utils.get_test_base_route(), '--dst', dst ]) test_utils.assert_validation_test(result)
def test_kmeans_model_is_loaded_from_file(self, method: str): vocabulary_file = test_utils.get_test_output_ndarray_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') extractor.setup() extractor.fit() extractor.export(vocabulary_file) new_extractor = BoWExtractor( base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') new_extractor.setup() new_extractor.load(vocabulary_file) assert (np.array_equal(new_extractor.bow_extractor.getVocabulary(), extractor.bow_extractor.getVocabulary()))
def test_feature_detection_and_addition(self, method: str): image_route = test_utils.get_test_image_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64) extractor._extract_and_add_image(image_route) descriptors = extractor.bow_kmeans.getDescriptors() expected_keypoints, expected_descriptors = extractor._process_image( image_route) assert (len(descriptors[0]) == len(expected_descriptors)) assert (len(descriptors[0]) == len(expected_keypoints))
def test_histogram_is_generated_from_local_binary_patterns(self, x, y): extractor = LBPExtractor(test_utils.get_test_base_route(), size=64, points=3, radius=1, grid_x=x, grid_y=y) image = extractor._read_image(test_utils.get_test_image_route()) lbp = extractor._extract_lbp(image) histogram = extractor._convert_lbp_to_histogram(lbp) assert (len(histogram) == x * y) for histogram_row in histogram: assert (histogram_row.shape[0] == extractor.bins)
def test_features_are_extracted_from_a_given_image_route(self, model: str): output_csv = test_utils.get_test_output_csv_route() extractor = DeepExtractor(base_route=test_utils.get_test_base_route(), model_name=model, size=75) extractor.extract_and_save(output_csv) features = test_utils.load_csv_from_route(output_csv) cnn_output_shape = extractor.model.layers[-1].output_shape expected_width = cnn_output_shape[1] * cnn_output_shape[ 2] * cnn_output_shape[3] + 1 expected_height = test_utils.count_test_images() assert (features.shape == (expected_height, expected_width))
def test_kmeans_model_is_exported(self, method: str): vocabulary_file = test_utils.get_test_output_ndarray_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') extractor.setup() extractor.fit() extractor.export(vocabulary_file) assert (os.path.exists(vocabulary_file)) vocabulary = np.load(vocabulary_file) assert (vocabulary.shape[0] == extractor.k) assert (np.array_equal(vocabulary, extractor.bow_extractor.getVocabulary()))
def test_features_are_extracted_from_a_given_image_route(self, x, y): output_csv = test_utils.get_test_output_csv_route() base_route = test_utils.get_test_base_route() extractor = LBPExtractor(base_route=base_route, size=64, points=3, radius=1, grid_x=x, grid_y=y) extractor.extract_and_save(output_csv) features = test_utils.load_csv_from_route(output_csv) expected_width = x * y * extractor.bins + 1 # Number of features + label column expected_height = test_utils.count_test_images() assert (features.shape == (expected_height, expected_width))
def test_features_are_extracted_from_a_given_image_route_in_manual_mode( self, method: str): output_file = test_utils.get_test_output_csv_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), k=3, method=method, size=64, cluster_mode='manual') extractor.setup() extractor.fit() extractor.extract_and_save(output_file) features = test_utils.load_csv_from_route(output_file) expected_width = extractor.k + 1 expected_height = test_utils.count_test_images() assert (features.shape == (expected_height, expected_width))
def test_features_are_extracted_from_a_given_image_route_in_automatic_mode( self, method: str): output_file = test_utils.get_test_output_csv_route() extractor = BoWExtractor(base_route=test_utils.get_test_base_route(), method=method, size=64, cluster_mode='auto', min_k=2, max_k=100, step=1, threshold=0.95) extractor.setup() extractor.fit() extractor.extract_and_save(output_file) features = test_utils.load_csv_from_route(output_file) expected_width = extractor.k + 1 expected_height = test_utils.count_test_images() assert (features.shape == (expected_height, expected_width))