def execute(self): if self.options.input_file == None: raise FLANNException("No input file given.") if self.options.algorithm == None: raise FLANNException("No algorithm specified") if self.options.test_file == None: raise FLANNException("No test file given.") if self.options.output_file == None: raise FLANNException("No output file given.") print 'Reading input dataset from', self.options.input_file dataset = read(self.options.input_file) flann = FLANN(log_level=self.options.log_level) flann.build_index(dataset, algorithm = self.options.algorithm, trees=self.options.trees, branching=self.options.branching, iterations=self.options.max_iterations, centers_init=self.options.centers_init) print 'Reading test dataset from', self.options.test_file testset = read(self.options.test_file) print "Searching for nearest neighbors" matches,dists = flann.nn_index(testset, self.options.nn, checks = self.options.checks) print "Writing matches to", self.options.output_file write(matches, self.options.output_file, format="dat")
def execute(self): if self.options.input_file == None: raise FLANNException("No input file given.") if self.options.algorithm == None: raise FLANNException("No algorithm specified") if self.options.test_file == None: raise FLANNException("No test file given.") if self.options.output_file == None: raise FLANNException("No output file given.") print 'Reading input dataset from', self.options.input_file dataset = read(self.options.input_file) flann = FLANN(log_level=self.options.log_level) flann.build_index(dataset, algorithm=self.options.algorithm, trees=self.options.trees, branching=self.options.branching, iterations=self.options.max_iterations, centers_init=self.options.centers_init) print 'Reading test dataset from', self.options.test_file testset = read(self.options.test_file) print "Searching for nearest neighbors" matches, dists = flann.nn_index(testset, self.options.nn, checks=self.options.checks) print "Writing matches to", self.options.output_file write(matches, self.options.output_file, format="dat")
def execute(self): if self.options.input_file==None: raise FLANNException("Need an input file") if self.options.output_file==None: raise FLANNException("Need an output file") print "Reading input data from file "+self.options.input_file dataset = read(self.options.input_file, dtype=numpy.dtype(self.options.dtype)) print "Writing to file %s"%self.options.output_file write(dataset,self.options.output_file, format=self.options.format)
def execute(self): if self.options.count>0 and self.options.length>0 and self.options.filename!=None: print "Saving a random (%d,%d) matrix in file %s... "%(self.options.count,self.options.length, self.options.filename), stdout.flush() data = float32(random((self.options.count,self.options.length))) write(data,self.options.filename) print "done" else: raise FLANNException("Error: Incorrect arguments specified (a filename must be given and the count and length must be positive)")
def execute(self): if self.options.input_file==None: raise FLANNException("Need an input file") print "Reading input data from file "+self.options.input_file dataset = read(self.options.input_file) if self.options.count>0: print "Sampling %d features"%self.options.count sampledset = sample_dataset(dataset, self.options.count) print "Writing sampled dataset to file %s"%self.options.save_file write(sampledset,self.options.save_file, format=self.options.format)
def execute(self): if self.options.count > 0 and self.options.length > 0 and self.options.filename != None: print "Saving a random (%d,%d) matrix in file %s... " % ( self.options.count, self.options.length, self.options.filename), stdout.flush() data = float32(random((self.options.count, self.options.length))) write(data, self.options.filename) print "done" else: raise FLANNException( "Error: Incorrect arguments specified (a filename must be given and the count and length must be positive)" )
def execute(self): if self.options.input_file == None: raise FLANNException("Need an input file") print "Reading input data from file " + self.options.input_file dataset = read(self.options.input_file) if self.options.count > 0: print "Sampling %d features" % self.options.count sampledset = sample_dataset(dataset, self.options.count) print "Writing sampled dataset to file %s" % self.options.save_file write(sampledset, self.options.save_file, format=self.options.format)
def execute(self): if self.options.input_file == None: raise FLANNException("No input file given.") if self.options.clusters_file == None: raise FLANNException("No clusters file given.") print 'Reading input dataset from', self.options.input_file dataset = read(self.options.input_file) print "Computing clusters" flann = FLANN(log_level = self.options.log_level) num_clusters = self.options.clusters branching = self.options.branching num_branches = (num_clusters-1)/(branching-1) clusters = flann.hierarchical_kmeans(dataset, branching, num_branches, self.options.max_iterations, centers_init=self.options.centers_init) print "Saving %d clusters to file %s"%(clusters.shape[0],self.options.clusters_file) write(clusters, self.options.clusters_file, format="dat")
def execute(self): if self.options.input_file == None: raise FLANNException("Need an input file") print "Reading input data from file " + self.options.input_file dataset = read(self.options.input_file) if self.options.test_file == None: raise FLANNException("Need a test file") if isfile(self.options.test_file): print "Reading test data from file " + self.options.test_file testset = read(self.options.test_file) else: print "Sampling test file" testset = sample_dataset(dataset, self.options.count, remove=True) dataset = dataset[0:dataset.shape[0] - self.options.count] print "Wrinting new dataset file" write(dataset, "new_" + self.options.input_file) print "Writing testset file" write(testset, self.options.test_file) print "Computing ground truth" start = time.clock() match = compute_ground_truth(dataset, testset, self.options.nn) print "It took %g seconds" % (time.clock() - start) print "Writing match file" write(match, self.options.match_file, format="dat")
def execute(self): if self.options.input_file==None: raise FLANNException("Need an input file") print "Reading input data from file "+self.options.input_file dataset = read(self.options.input_file) if self.options.test_file==None: raise FLANNException("Need a test file") if isfile(self.options.test_file): print "Reading test data from file "+self.options.test_file testset = read(self.options.test_file) else: print "Sampling test file" testset = sample_dataset(dataset, self.options.count, remove=True) dataset = dataset[0:dataset.shape[0]-self.options.count] print "Wrinting new dataset file" write(dataset,"new_"+self.options.input_file) print "Writing testset file" write(testset,self.options.test_file) print "Computing ground truth" start = time.clock() match = compute_ground_truth(dataset, testset, self.options.nn) print "It took %g seconds"%(time.clock()-start) print "Writing match file" write(match,self.options.match_file, format="dat")
def execute(self): if self.options.input_file == None: raise FLANNException("No input file given.") if self.options.clusters_file == None: raise FLANNException("No clusters file given.") print 'Reading input dataset from', self.options.input_file dataset = read(self.options.input_file) print "Computing clusters" flann = FLANN(log_level=self.options.log_level) num_clusters = self.options.clusters branching = self.options.branching num_branches = (num_clusters - 1) / (branching - 1) clusters = flann.hierarchical_kmeans( dataset, branching, num_branches, self.options.max_iterations, centers_init=self.options.centers_init) print "Saving %d clusters to file %s" % (clusters.shape[0], self.options.clusters_file) write(clusters, self.options.clusters_file, format="dat")