Skip to content

Instantly share code, notes, and snippets.

@venuktan
Created February 16, 2016 01:09
Show Gist options
  • Save venuktan/a112cfa264aeb02a7e0c to your computer and use it in GitHub Desktop.
Save venuktan/a112cfa264aeb02a7e0c to your computer and use it in GitHub Desktop.
import numpy
from nearpy import Engine
from nearpy.hashes import RandomBinaryProjections, HashPermutationMapper, HashPermutations
from nearpy.distances import CosineDistance
from nearpy.filters.nearestfilter import NearestFilter
from nearpy.storage import RedisStorage
import glob
import time
from redis import Redis
redis_storage = RedisStorage(
Redis(host='similar-images-index.i4cyv7.0001.use1.cache.amazonaws.com',
port=6379, db=0))
# Create a random binary hash with 10 bits
hashes = HashPermutations('permut2')
# Create binary hash as child hash
rbp_perm = RandomBinaryProjections('rbp_perm', 14)
rbp_conf = {'num_permutation':50,'beam_size':10,'num_neighbour':100}
# Add rbp as child hash of permutations hash
hashes.add_child_hash(rbp_perm, rbp_conf)
# for k in range(5):
# hashes.append(HashPermutationMapper ('rbp_%d' % k, 10))
# Create engine
dimension =2048
engine = Engine(dimension, lshashes=[hashes],
vector_filters = [NearestFilter(10)],
distance=CosineDistance(),
storage=redis_storage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment