def vl_test_hikmeans(): """ VL_TEST_HIKMEANS Test VL_HIKMEANS function """ K = 3 nleaves = 100 data = numpy.array(numpy.random.rand(2, 1000) * 255, 'uint8') datat = numpy.array(numpy.random.rand(2, 10000) * 255, 'uint8') [tree, A] = vlfeat.vl_hikmeans(data, K, nleaves, verb=1) AT = vlfeat.vl_hikmeanspush(tree, datat) pylab.figure() plottree(tree) pylab.xlim(0, 255) pylab.ylim(0, 255) print('hikmeans-tree') pylab.figure() gen = color_gen() for k in range(K * K): color = next(gen) sel = pylab.find(A[-1, :] == k) pylab.plot(data[0, sel], data[1, sel], '.', color=color) sel = pylab.find(AT[-1, :] == k) pylab.plot(datat[0, sel], datat[1, sel], '+', color=color) plottree(tree, linewidth=4) pylab.xlim(0, 255) pylab.ylim(0, 255) print('hikmeans-clusters')
def vl_test_hikmeans(): """ VL_TEST_HIKMEANS Test VL_HIKMEANS function """ K = 3 nleaves = 100 data = numpy.array(numpy.random.rand(2, 1000) * 255, 'uint8') datat = numpy.array(numpy.random.rand(2, 10000) * 255, 'uint8') [tree, A] = vlfeat.vl_hikmeans(data, K, nleaves, verb=1) AT = vlfeat.vl_hikmeanspush(tree, datat) pylab.figure() plottree(tree) pylab.xlim(0, 255) pylab.ylim(0, 255) print('hikmeans-tree') ; pylab.figure() gen = color_gen() for k in range(K*K): color = next(gen) sel = pylab.find(A[-1, :] == k) pylab.plot(data[0, sel], data[1, sel], '.', color=color) sel = pylab.find(AT[-1, :] == k) pylab.plot(datat[0, sel], datat[1, sel], '+', color=color) plottree(tree, linewidth=4) pylab.xlim(0, 255) pylab.ylim(0, 255) print('hikmeans-clusters') ;
def generate_tree(self, data, K, nleaves, file_dir, file_name): self.K = K self.nleaves = nleaves [tr, A] = vl.vl_hikmeans(data, self.K, self.nleaves, verb=1) tr.save(os.path.join(file_dir, file_name))
def vl_test_hikmeans_io(): """ VL_TEST_HIKMEANS_IO Test VL_HIKMEANS function """ K = 3 nleaves = 100 data = numpy.array(numpy.random.rand(2, 1000) * 255, 'uint8') [tree, A] = vlfeat.vl_hikmeans(data, K, nleaves, verb=1) tree.save('/tmp/test.vlhkm') tree2 = vlfeat._vlfeat.VlHIKMTree(0, 0) tree2.load('/tmp/test.vlhkm') pylab.figure() plottree(tree) pylab.xlim(0, 255) pylab.ylim(0, 255) pylab.figure() plottree(tree2) pylab.xlim(0, 255) pylab.ylim(0, 255) print('hikmeans-tree-io')
def learn(bk, descr): if bk['dictionary'] == 'ikm': print('block_dictionary: === Running IKM ===') print('block_dictionary: num words (K): %d'%(bk['ikm_nwords'])) dict_ = vlfeat.vl_ikmeans(descr, bk['ikm_nwords'], verbosity=1, method='elkan') print('block_dictionary: IKM done') elif bk['dictionary'] == 'hikm': print('block_dictionary: === Runnining HIKM ===') print('block_dictionary: num leaves: %d'%(bk['hikm_nleaves'])) print('block_dictionary: branching (K): %d'%(bk['hikm_K'])) print('block_dictionary: only_leaves: %d'%(bk['hikm_only_leaves'])) dict_,asgn = vlfeat.vl_hikmeans(descr, bk['hikm_K'], bk['hikm_nleaves'], verbosity=1 , method='elkan') print('block_dictionary: HIKM done') else: raise TypeError('block_dictionary.py :learn() unknown dictionary type') return dict_