def __init__(self, hash_size, input_dim, random_sampling = True, dict_type = 'int32', cuda_client_type = 'local', cuda_server = 'locahost', random_dims = 32, num_hashtables=1, storage_config=None, matrices_filename=None, overwrite=False): self.hash_size = hash_size self.input_dim = input_dim self.num_hashtables = num_hashtables if storage_config is None: storage_config = {'dict': None} self.storage_config = {storage_config: {}} if storage_config == 'random': self.storage_config = {'random': {'r': random_dims, 'dim': hash_size, 'random': random_sampling, 't': dict_type}} if matrices_filename and not matrices_filename.endswith('.npz'): raise ValueError("The specified file name must end with .npz") self.matrices_filename = matrices_filename self.overwrite = overwrite self._init_uniform_planes() self._init_hashtables() self.loaded_keys = None #self.cuda_hamming = CudaHamming() cudaclient_options = {'host': cuda_server, 'port': 8080} self.cuda_hamming = cudaclient(cuda_client_type, cudaclient_options)
def main(): args = parse_parameters() (lsh, np_feature_vecs) = init_lsh(args) lsh = run(args, lsh) ground_truth = None if args.gt != None: (ground_truth, ground_truth_num) = load_ground_truth(args.gt, args.gtf) if args.c != 'y' and args.i != 'y' and args.e != None and args.s == 'random': client = cudaclient('net', {'host': args.host, 'port': 8080}) b_begin = int(args.b) b_end = int(args.b) + 1 # when given a range of expanding levels if args.b_begin != -1 and args.b_end != -1: b_begin = int(args.b_begin) b_end = int(args.b_end) for cur_expand_level in range(b_begin, b_end): client.send_query(['reset']) client.send_query([args.title]) client.send_query(['expand_level: ' + str(cur_expand_level)]) total_found = {'10': 0, '100': 0} for feature_idx in range(0, np_feature_vecs.shape[0]): feature = np_feature_vecs[feature_idx] if args.p != 'y': retrived = lsh.query(feature, num_results = int(args.k), expand_level = cur_expand_level, distance_func = 'hamming') else: retrived = lsh.query_in_compressed_domain(feature, num_results = int(args.k), expand_level = cur_expand_level, distance_func = 'hamming', gpu_mode = args.g, vlq_mode = args.l) total_found['10'] += cal_recall(retrived, ground_truth, feature_idx, int(args.k), topGT = 10) total_found['100'] += cal_recall(retrived, ground_truth, feature_idx, int(args.k), topGT = 100) recall_r = total_found['10'] / float(np_feature_vecs.shape[0]) recall_r_str = "recall@" + args.k + " GT@10: " + str(recall_r) print recall_r_str client.send_query([recall_r_str]) recall_r = total_found['100'] / float(np_feature_vecs.shape[0]) recall_r_str = "recall@" + args.k + " GT@100: " + str(recall_r) print recall_r_str client.send_query([recall_r_str])
def __init__(self, hash_size, input_dim, random_sampling=True, dict_type='int32', cuda_client_type='local', cuda_server='locahost', random_dims=32, num_hashtables=1, storage_config=None, matrices_filename=None, overwrite=False): self.hash_size = hash_size self.input_dim = input_dim self.num_hashtables = num_hashtables if storage_config is None: storage_config = {'dict': None} self.storage_config = {storage_config: {}} if storage_config == 'random': self.storage_config = { 'random': { 'r': random_dims, 'dim': hash_size, 'random': random_sampling, 't': dict_type } } if matrices_filename and not matrices_filename.endswith('.npz'): raise ValueError("The specified file name must end with .npz") self.matrices_filename = matrices_filename self.overwrite = overwrite self._init_uniform_planes() self._init_hashtables() self.loaded_keys = None #self.cuda_hamming = CudaHamming() cudaclient_options = {'host': cuda_server, 'port': 8080} self.cuda_hamming = cudaclient(cuda_client_type, cudaclient_options)
def main(): args = parse_parameters() (lsh, np_feature_vecs) = init_lsh(args) lsh = run(args, lsh) ground_truth = None if args.gt != None: (ground_truth, ground_truth_num) = load_ground_truth(args.gt, args.gtf) if args.c != 'y' and args.i != 'y' and args.e != None and args.s == 'random': client = cudaclient('net', {'host': args.host, 'port': 8080}) b_begin = int(args.b) b_end = int(args.b) + 1 # when given a range of expanding levels if args.b_begin != -1 and args.b_end != -1: b_begin = int(args.b_begin) b_end = int(args.b_end) for cur_expand_level in range(b_begin, b_end): client.send_query(['reset']) client.send_query([args.title]) client.send_query(['expand_level: ' + str(cur_expand_level)]) total_found = {'10': 0, '100': 0} for feature_idx in range(0, np_feature_vecs.shape[0]): feature = np_feature_vecs[feature_idx] if args.p != 'y': retrived = lsh.query(feature, num_results=int(args.k), expand_level=cur_expand_level, distance_func='hamming') else: retrived = lsh.query_in_compressed_domain( feature, num_results=int(args.k), expand_level=cur_expand_level, distance_func='hamming', gpu_mode=args.g, vlq_mode=args.l) total_found['10'] += cal_recall(retrived, ground_truth, feature_idx, int(args.k), topGT=10) total_found['100'] += cal_recall(retrived, ground_truth, feature_idx, int(args.k), topGT=100) recall_r = total_found['10'] / float(np_feature_vecs.shape[0]) recall_r_str = "recall@" + args.k + " GT@10: " + str(recall_r) print recall_r_str client.send_query([recall_r_str]) recall_r = total_found['100'] / float(np_feature_vecs.shape[0]) recall_r_str = "recall@" + args.k + " GT@100: " + str(recall_r) print recall_r_str client.send_query([recall_r_str])