Exemplo n.º 1
0
import os, random

import simpleknn
from bigfile import BigFile

rootpath = '/Users/xirong/VisualSearch'
collection = 'train10k'
nr_of_images = 10000
feature = 'color64'
dim = 64

feature_dir = os.path.join(rootpath, collection, 'FeatureData', feature)
feature_file = BigFile(feature_dir, dim)
imset = map(
    str.strip,
    open(os.path.join(rootpath, collection, 'ImageSets',
                      '%s.txt' % collection)).readlines())
imset = random.sample(imset, 10)

searcher = simpleknn.load_model(os.path.join(feature_dir, "feature.bin"), dim,
                                nr_of_images,
                                os.path.join(feature_dir, "id.txt"))
searcher.set_distance('l1')
renamed, vectors = feature_file.read(imset)

for name, vec in zip(renamed, vectors):
    visualNeighbors = searcher.search_knn(vec, max_hits=100)
    print name, visualNeighbors[:3]
Exemplo n.º 2
0
import os, random

import simpleknn
from bigfile import BigFile

rootpath = '/Users/xirong/VisualSearch'
collection = 'train10k'
nr_of_images = 10000
feature = 'color64'
dim = 64

feature_dir = os.path.join(rootpath,collection,'FeatureData',feature)
feature_file = BigFile(feature_dir, dim)
imset = map(str.strip, open(os.path.join(rootpath,collection,'ImageSets','%s.txt'%collection)).readlines())
imset = random.sample(imset, 10)

searcher = simpleknn.load_model(os.path.join(feature_dir, "feature.bin"), dim, nr_of_images, os.path.join(feature_dir, "id.txt"))
searcher.set_distance('l1')
renamed,vectors = feature_file.read(imset)

for name,vec in zip(renamed,vectors):
    visualNeighbors = searcher.search_knn(vec, max_hits=100)
    print name, visualNeighbors[:3]
Exemplo n.º 3
0
feature = 'f3d'
feat_dim = 3

feat_dir = '%s/FeatureData/%s' % (collection, feature)
txt_file = os.path.join(feat_dir, 'id.feature.txt')
os.system('python txt2bin.py %d %s 0 %s --overwrite 1' %
          (feat_dim, txt_file, feat_dir))

for p in [1, 2]:
    os.system('python norm_feat.py %s --p %d --overwrite 1' % (feat_dir, p))

for feature in str.split('f3d f3dl1 f3dl2'):
    feat_dir = os.path.join(rootpath, collection, 'FeatureData', feature)
    id_file = os.path.join(feat_dir, "id.txt")
    with open(os.path.join(feat_dir, 'shape.txt')) as fr:
        nr_of_images, dim = map(int, fr.readline().split())
        fr.close()

    feat_file = BigFile(feat_dir)
    imset = feat_file.names

    searcher = simpleknn.load_model(os.path.join(feat_dir, "feature.bin"), dim,
                                    nr_of_images, id_file)
    renamed, vectors = feat_file.read(imset)

    for name, vec in zip(renamed, vectors):
        for distance in ['l1', 'l2']:
            searcher.set_distance(distance)
            visualNeighbors = searcher.search_knn(vec, max_hits=100)
            print name, feature, distance, visualNeighbors[:3]