def test(): np.random.seed(17) X = np.load('data/cifar_gist.npy') Y = np.load('data/cifar_label.npy') traindata = X[:5000] trainlabel = Y[:5000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # train model dksh = Sparse_DKSH(64, 1000, 10, RBF) tic = time.clock() dksh.train(traindata, trainlabel) toc = time.clock() print 'time:', toc-tic H_test = dksh.queryhash(testdata) H_base = dksh.queryhash(basedata) # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']
def test(): #np.random.seed(47) X = np.load('data/cifar_gist.npy') Y = np.load('data/cifar_label.npy') traindata = X[:59000] trainlabel = Y[:59000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # train model sdh = SDH(32, 300, 10, RBF) tic = time.clock() sdh.train(traindata, trainlabel) toc = time.clock() print 'time:', toc-tic H_test = sdh.queryhash(testdata) H_base = sdh.queryhash(basedata) idx = np.argsort(sdh.trainlabel).squeeze() bb = sdh.B[idx[0:59000:6000]] classham = (32-np.dot(bb,bb.T))/2 print np.sum(classham) print classham # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']
def test(): np.random.seed(47) X = np.load('data/cifar_gist.npy') Y = np.load('data/cifar_label.npy') traindata = X[:5000] trainlabel = Y[:5000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # train model alg = SHLE(32, 10, lambda : RBFClassifier(X[:300])) alg.train(traindata, trainlabel) H_test = alg.queryhash(testdata) H_base = alg.queryhash(basedata) ''' idx = np.argsort(alg.trainlabel).squeeze() bb = alg.H[idx[0:5000:530]] classham = (32-np.dot(bb,bb.T))/2 print np.sum(classham) print classham ''' # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']
def test(): X = np.load('data/cifar_gist.npy') Y = np.load('data/cifar_label.npy') idx = np.arange(60000, dtype=np.int32) np.random.shuffle(idx) X = X[idx] Y = Y[idx] traindata = X[:5000] trainlabel = Y[:5000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) # train model ksh = KSH(48, 300, 10, RBF) tic = time.clock() ksh.train(traindata, trainlabel) # ksh = ksh2.KSH(5000, 300, 12, traindata, trainlabel, RBF) toc = time.clock() print 'time:', toc-tic H_base = ksh.basehash(basedata) H_test = ksh.queryhash(testdata) # evaluate res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']
def test(list_algo_name, list_bits, loader): seeds = [7, 17]#, 37, 47, 67, 97, 107, 127, 137, 157] for algo_name in list_algo_name: for nbit in list_bits: print '======execute {} at bit {}======'.format(algo_name, nbit) print '====total process round: {}====='.format(len(seeds)) li_results = [] for sd in seeds: print '\nround #{}...'.format(len(li_results)+1) traindata, trainlabel, basedata, baselabel, testdata, testlabel = loader.split(sd) alg = hash_factory(algo_name, nbit, 21, 300) tic = time.clock() alg.train(traindata, trainlabel) toc = time.clock() print 'time:', toc-tic H_test = alg.queryhash(testdata) H_base = alg.queryhash(basedata) # make labels #gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) gnd_truth = (np.dot(testlabel, baselabel.T) >= 1).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, len(baselabel), len(baselabel), trn_time=toc-tic) li_results.append(res) eva_checkpoint(algo_name, nbit, li_results)
def test(n_bit): np.random.seed(17) X = np.load('cifar10_data/cifar10_gist.npy') Y = np.load('cifar10_data/cifar10_label.npy') traindata = X[:59000] trainlabel = Y[:59000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # train model dish = DISH_K(n_bit, 1000, 10, RBF) tic = time.time() dish.train(traindata, trainlabel) toc = time.time() print 'time:', toc - tic H_test = dish.queryhash(testdata) H_base = dish.basehash(basedata) # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']
def test(list_algo_name, list_bits): root = '../../ILSVRC2012_caffe/npy_data/' baselabel = np.load(root+'trainlabel.npy') testlabel = np.load(root+'testlabel.npy') testdata = np.load(root+'testdata_fc6_norm.npy') basicdata = np.load(root+'traindata_fc6_norm_1.npy') seeds = [7]#, 17, 37, 47, 67, 97, 107, 127, 137, 157] for algo_name in list_algo_name: for nbit in list_bits: print '======execute {} at bit {}======'.format(algo_name, nbit) print '====total process round: {}====='.format(len(seeds)) li_results = [] for sd in seeds: print '\nround #{}...'.format(len(li_results)+1) # load data np.random.seed(sd) idx = np.arange(100000, dtype=np.int32) np.random.shuffle(idx) traindata = basicdata[idx] trainlabel = baselabel[idx] alg = hash_factory(algo_name, nbit, 1000, 1000) tic = time.clock() alg.train(traindata, trainlabel) toc = time.clock() print 'time:', toc-tic print 'hash testing data...' H_test = alg.queryhash(testdata) print 'hash training data...' H_base = np.zeros((baselabel.shape[0], H_test.shape[1]), dtype=np.uint8) pt = 0 for i in xrange(13): print 'hashing', i, '...' X = np.load('traindata_fc6_norm_{}.npy'.format(i+1)) n = X.shape[0] H_base[pt:pt+n] = alg.basehash(X) pt += n print 'testing...' batch_results = [] for i in xrange(50): # make labels print 'testing batch', i, '...' gnd_truth = np.array([y == baselabel for y in testlabel[i*1000:(i+1)*1000]]).astype(np.int8) batch_results.append(hash_evaluation(H_test, H_base, gnd_truth, 0, topN=5000, trn_time=toc-tic)) eva_checkpoint(algo_name, nbit, batch_results) li_results.append(batch_eva_ensem(batch_results)) eva_checkpoint(algo_name, nbit, li_results)
def test_cnn(n_bit): np.random.seed(17) if use_vgg: X = np.load('cifar10_data/cifar10_256_data.npy') else: X = np.load('cifar10_data/cifar10_data.npy') Y = np.load('cifar10_data/cifar10_label.npy') is_train = np.load('cifar10_data/cifar10_istrain.npy') train_idx = np.argwhere(is_train==1)[:,0] nottrain_idx = np.argwhere(is_train==0)[:,0] np.random.shuffle(nottrain_idx) test_idx = nottrain_idx[-1000:] base_idx = np.setdiff1d(np.arange(60000, dtype=np.int32), test_idx) traindata = X[train_idx] trainlabel = Y[train_idx] testdata = X[test_idx] testlabel = Y[test_idx] basedata = X[base_idx] baselabel = Y[base_idx] del X # train model dksh = DISH_D(n_bit, 10) tic = time.time() dksh.train(traindata, trainlabel) toc = time.time() print 'time:', toc-tic H_test = dksh.queryhash(testdata) H_base = dksh.queryhash(basedata) # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, len(H_base), topN=len(H_base), trn_time=toc-tic) print 'MAP:', res['map'], 'Pre2:', res['pre2']
np.random.seed(97) X = np.load('data/cifar_gist.npy') Y = np.load('data/cifar_label.npy') traindata = X[:59000] trainlabel = Y[:59000] basedata = X[:59000] baselabel = Y[:59000] testdata = X[59000:] testlabel = Y[59000:] # train model dksh = DGH(48, 300) tic = time.clock() dksh.train(traindata) toc = time.clock() print 'time:', toc-tic H_test = dksh.queryhash(testdata) H_base = dksh.queryhash(basedata) idx = np.argsort(baselabel) print H_base[idx[0:59000:3000]] # make labels gnd_truth = np.array([y == baselabel for y in testlabel]).astype(np.int8) print 'testing...' res = hash_evaluation(H_test, H_base, gnd_truth, 59000) print 'MAP:', res['map']