Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def batch_checkpoint(algo_name, nbit, li_results):
	dump('results_imagenet/{}_{}_batch'.format(algo_name, nbit), li_results)
	res = batch_eva_ensem(li_results)
	print 'mean: mAP={}, pre2={}'.format(res['map'], res['pre2'])