def index_images(folder, features_path, mapping_path, model, glove_path): print("Now indexing images...") word_vectors = utils.load_glove_vectors(glove_path) _, _, paths = utils.load_paired_img_wrd(folder=folder, word_vectors=word_vectors) images_features, file_index = utils.generate_features(paths, model) utils.save_features(features_path, images_features, mapping_path, file_index) return images_features, file_index
def index_images(folder, features_path, mapping_path, model, features_from_new_model_boolean, glove_path): print ("Now indexing images...") # Use word vectors if leveraging the new model if features_from_new_model_boolean: word_vectors=vector_search.load_glove_vectors(glove_path) else: word_vectors=[] # Use utiliy function _, _, paths = load_paired_img_wrd( folder=folder, word_vectors=word_vectors, use_word_vectors=features_from_new_model_boolean) images_features, file_index = vector_search.generate_features(paths, model) vector_search.save_features(features_path, images_features, mapping_path, file_index) return images_features, file_index
def load_images_vectors_paths(glove_model_path, data_path): word_vectors = vector_search.load_glove_vectors(glove_model_path) images, vectors, image_paths = load_paired_img_wrd(data_path, word_vectors) return images, vectors, image_paths, word_vectors
default=50) return par if __name__ == "__main__": parser = build_parser() options = parser.parse_args() model_save_path = options.model_save_path checkpoint_path = options.checkpoint_path glove_path = options.glove_path dataset_path = options.dataset_path num_epochs = options.num_epochs word_vectors = vector_search.load_glove_vectors(glove_path) images, vectors, image_paths = load_paired_img_wrd(dataset_path, word_vectors) x, y = shuffle(images, vectors, random_state=2) X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=2) checkpointer = ModelCheckpoint(filepath=checkpoint_path, verbose=1, save_best_only=True) custom_model = vector_search.setup_custon_model() custom_model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=num_epochs, batch_size=32,
def index_images(folder, features_path, mapping_path, model): _, _, paths = load_paired_img_wrd(folder, [], use_word_vectors=False) images_features, file_index = vector_search.generate_features(paths, model) vector_search.save_features(features_path, images_features, mapping_path, file_index) return images_features, file_index