def find_threshold(args, filter_string, feature_vector, query_image_id): data_matrix, image_ids = get_data_matrix(args.model, filter_string) if args.model == "SIFT": # Sift needs special hand-holding here, as it is slightly tricky. max_vector_length = data_matrix.shape[1] sift_vectors = [] for feature in feature_vector: if len(sift_vectors) == max_vector_length: break sift_vectors.extend(feature) new_data_matrix = np.append(data_matrix, np.array(sift_vectors).reshape( 1, len(sift_vectors)), axis=0) else: new_data_matrix = np.append(data_matrix, np.array(feature_vector).reshape( 1, len(feature_vector)), axis=0) image_ids.append(query_image_id) dimensionality_reduction(new_data_matrix, image_ids, args, args.label) max_threshold = float("-inf") for image_id in image_ids: similar_images = find_similar_images(image_id, args.model, len(image_ids) - 1, args.label) distance_score = 0 for similar_image in similar_images: distance_score += similar_image["distance_score"] max_threshold = max(max_threshold, distance_score / (len(image_ids) - 1)) return max_threshold
def main(): parser = setup_arg_parse() args = parser.parse_args() populate_database(args) data_matrix, image_ids = get_data_matrix(args.model) dimensionality_reduction(data_matrix, image_ids, args, viz=True) similar_images = find_similar_images(args.query_image, args.model, args.m) for similar_image in similar_images: print(similar_image) plot_results(similar_images, args.image_folder + "/" + args.query_image)
def main(): parser = setup_arg_parse() args = parser.parse_args() mongo_client = connect_to_db() images = list( mongo_client.mwdb_project.image_features.find({}, {"label": 1})) mongo_client.close() if len(images) == 0: print("Running task3") filter_string = convert_label_to_filterstring(args.label) data_matrix, image_ids = get_data_matrix(args.model, filterstring) dimensionality_reduction(data_matrix, image_ids, args, args.label) similar_images = find_similar_images(args.query_image, args.model, args.m, args.label) for similar_image in similar_images: print(similar_image) plot_results(similar_images, args.image_folder + "/" + args.query_image)