Exemplo n.º 1
0
def quantity():
    center = np.fromfile(clstbinfilename, dtype="float32")
    center = center.reshape((K, D))
    #center.dtype = "float64"
    print center.dtype
    print "kdtree build start"
    nno = fastann.build_kdtree(center, 8, 768)
    print "kdtree build finish"
    for filename in os.listdir(featurefilename):
        if filename.endswith(postfix):
            name = filename.split("_")
            nametxt = name[0] + '_box.txt'
            fc6feat = np.fromfile(featurefilename + filename, dtype='float32')
            fc6feat = fc6feat.reshape((fc6feat.shape[0] / 4096, 4096))
            argmins, mins = nno.search_nn(fc6feat)
            argmins = argmins.reshape((argmins.shape[0], 1))
            index = np.loadtxt(featurefilename + nametxt, dtype="int32")
            clst = np.append(index, argmins, axis=1)
            #clst.dtype="int32"
            clst.tofile(featurefilename + name[0] + '_clst.bin')
            print featurefilename + name[0] + '_clst.txt'
Exemplo n.º 2
0
def quantity():
    center = np.fromfile(clstbinfilename, dtype="float32")
    center = center.reshape((K, D))
    # center.dtype = "float64"
    print center.dtype
    print "kdtree build start"
    nno = fastann.build_kdtree(center, 8, 768)
    print "kdtree build finish"
    for filename in os.listdir(featurefilename):
        if filename.endswith(postfix):
            name = filename.split("_")
            nametxt = name[0] + "_box.txt"
            fc6feat = np.fromfile(featurefilename + filename, dtype="float32")
            fc6feat = fc6feat.reshape((fc6feat.shape[0] / 4096, 4096))
            argmins, mins = nno.search_nn(fc6feat)
            argmins = argmins.reshape((argmins.shape[0], 1))
            index = np.loadtxt(featurefilename + nametxt, dtype="int32")
            clst = np.append(index, argmins, axis=1)
            # clst.dtype="int32"
            clst.tofile(featurefilename + name[0] + "_clst.bin")
            print featurefilename + name[0] + "_clst.txt"
Exemplo n.º 3
0
import numpy as np
import h5py
import fastann
bow_save_prefix=""
clst_file=h5py.File('../data/clst.h5','r')
print('loading clusters...')
clst_point=clst_file['clusters'].value
print('complete')
print('buiding kd tree...')
nno_kdt = fastann.build_kdtree(clst_point, 8, 768)
print('complete')

path = 'video_query.h5'

file_name=path.split('/')[len(path.split('/'))-1]
bow_name='bow_query.h5'
video_file=h5py.File(path,'r')
bow_file=h5py.File(bow_save_prefix + bow_name,'w')
print('loading video h5 file:'+file_name)
data=video_file['data'].value
#print('dimention of data:'+data.shape)
num_image=data.shape[0]
num_point=data.shape[1]
dim=data.shape[2]
data.resize(num_image*num_point,dim)
print('compute bow features')
argmins_kdt, mins_kdt = nno_kdt.search_nn(data)
argmins_kdt.resize(num_image,num_point)
print('saving bow features to:'+bow_save_prefix + bow_name)
bow_file.create_dataset('data',data=argmins_kdt)
bow_file.flush()
Exemplo n.º 4
0
import numpy as np
import h5py
import fastann
bow_save_prefix = ""
clst_file = h5py.File('../data/clst.h5', 'r')
print('loading clusters...')
clst_point = clst_file['clusters'].value
print('complete')
print('buiding kd tree...')
nno_kdt = fastann.build_kdtree(clst_point, 8, 768)
print('complete')

path = 'video_query.h5'

file_name = path.split('/')[len(path.split('/')) - 1]
bow_name = 'bow_query.h5'
video_file = h5py.File(path, 'r')
bow_file = h5py.File(bow_save_prefix + bow_name, 'w')
print('loading video h5 file:' + file_name)
data = video_file['data'].value
#print('dimention of data:'+data.shape)
num_image = data.shape[0]
num_point = data.shape[1]
dim = data.shape[2]
data.resize(num_image * num_point, dim)
print('compute bow features')
argmins_kdt, mins_kdt = nno_kdt.search_nn(data)
argmins_kdt.resize(num_image, num_point)
print('saving bow features to:' + bow_save_prefix + bow_name)
bow_file.create_dataset('data', data=argmins_kdt)
bow_file.flush()
Exemplo n.º 5
0
import fastann
import numpy as np
import numpy.random as npr

A = npr.rand(10000,128)
B = npr.rand(10000,128)

nno = fastann.build_exact(A)
argmins, mins = nno.search_nn(B)
nno_kdt = fastann.build_kdtree(A, 8, 768)
argmins_kdt, mins_kdt = nno_kdt.search_nn(B)

print float(np.sum(argmins == argmins_kdt))/10000