# coding: utf-8 # In[1]: import pandas as pd import numpy as np from pathing_utils import image_name_from_path from random import sample from .models import Image from utils import ci_lower_bound from pathing_utils import path_to_static indices_euclidean_path = path_to_static() + "indices_euclidean.csv" INDICIES = np.genfromtxt(indices_euclidean_path, delimiter=',', dtype=str) # INDICIES = INDICIES[:1000] distances_euclidean_path = path_to_static() + "distances_euclidean.csv" DISTANCES = np.genfromtxt(distances_euclidean_path, delimiter=',') # DISTANCES = DISTANCES[:1000] def index_from_image_name(image_path): return int(image_name_from_path(image_path).split(".jpg")[0]) def get_images_similar_to_image(img_name, indices, distances, k, form="df"): """ Returns list or df of k similar images, with or without path Parameters: 1. img_name - "00001.jpg" 2. indices - nested np array with top 50 closest images for each image 3. distances - nested np array with top 50 distances for each image
build_Index, \ get_tl_vector, \ get_ol_vector from inception import Inception, maybe_download import gc from pathing_utils import path_to_image_frontend, \ path_to_static, \ path_to_images_folder_absolute, \ image_name_from_path,\ path_to_uploads from utils import image_from_base64str maybe_download() inception_layer_path = path_to_static() + "inception_output_layer2" inverted_index_path = path_to_static() + "inverted_index" vocab_path = path_to_static() + "vocab.csv" word2vec_vocab_path = path_to_static() + "word2vecvocab.csv" word_vec_path = path_to_static() + "GoogleNews-vectors-negative300.bin.gz" print("READ inception_layer_path") inverted_index = pd.read_pickle(inverted_index_path) df_in = pd.read_pickle(inception_layer_path) df_in.columns = ['img', 'output_layer', 'scores'] # print("DROP column - output_layer") df_in.drop('output_layer', axis=1, inplace=True) # print(df_in.head()) known_words = defaultdict(list) annoy_index = None inception_object = None vocabs = list(pd.read_csv(vocab_path).vocab)
def __init__(self): self.HISTORY_FILE_PATH = path.join(path_to_static(), "history.csv") self.HISTORY_COLS = ["query", "times"]
import numpy as np import tensorflow as tf import download from cache import cache import os import sys from pathing_utils import path_to_static ######################################################################## # Various directories and file-names. # Internet URL for the tar-file with the Inception model. # Note that this might change in the future and will need to be updated. data_url = "http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz" # Directory to store the downloaded data. data_dir = path_to_static() + "inception" + os.path.sep # File containing the mappings between class-number and uid. (Downloaded) path_uid_to_cls = "imagenet_2012_challenge_label_map_proto.pbtxt" # File containing the mappings between uid and string. (Downloaded) path_uid_to_name = "imagenet_synset_to_human_label_map.txt" # File containing the TensorFlow graph definition. (Downloaded) path_graph_def = "classify_image_graph_def.pb" ######################################################################## def maybe_download(): """
def __init__(self): self.FEEDBACK_FILE_PATH = path_to_static() + "feedback.csv" self.FEEDBACK_COLS = ["query", "step", "image", "status"] self.df_feedback = self.read_feedback()