Example #1
0
    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")
Example #2
0
 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")
Example #3
0
 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.match_file == None:
         raise FLANNException("No match 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 'Reading ground truth from matches from', self.options.test_file
     matches = read(self.options.match_file, dtype = int)
     
     if self.options.precision>0:
         checks, time = test_with_precision(flann, dataset, testset, matches, self.options.precision, self.options.nn)
     else:
         precision, time = test_with_checks(flann, dataset, testset, matches, self.options.checks, self.options.nn)
Example #4
0
    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")
Example #5
0
    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")
Example #6
0
    def execute(self):
        self.nn = FLANN(log_level=self.options.log_level)

        if self.options.input_file == None:
            raise FLANNException("No input file given.")
        print 'Reading input dataset from', self.options.input_file
        self.dataset = read(self.options.input_file)

        if self.options.precision < 0 or self.options.precision > 1:
            raise FLANNException(
                "The precision argument must be between 0 and 1.")
        params = self.nn.build_index(
            self.dataset,
            target_precision=self.options.precision,
            build_weight=self.options.build_weight,
            memory_weight=self.options.memory_weight,
            sample_fraction=self.options.sample_fraction)

        if self.options.params_file != None:
            params_stream = open(self.options.params_file, "w")
        else:
            params_stream = sys.stdout
        configdict = ConfigParser()
        configdict.add_section('params')
        for (k, v) in params.items():
            configdict.set('params', k, v)
        configdict.write(params_stream)
Example #7
0
 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)
Example #8
0
 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.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)
Example #10
0
    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)
Example #11
0
    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.match_file == None:
            raise FLANNException("No match 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 'Reading ground truth from matches from', self.options.test_file
        matches = read(self.options.match_file, dtype=int)

        if self.options.precision > 0:
            checks, time = test_with_precision(flann, dataset, testset,
                                               matches, self.options.precision,
                                               self.options.nn)
        else:
            precision, time = test_with_checks(flann, dataset, testset,
                                               matches, self.options.checks,
                                               self.options.nn)
Example #12
0
    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")
Example #13
0
 def execute(self):
     self.nn = FLANN(log_level=self.options.log_level)
     
     if self.options.input_file == None:
         raise FLANNException("No input file given.")
     print 'Reading input dataset from', self.options.input_file
     self.dataset = read(self.options.input_file)
     
     if self.options.precision<0 or self.options.precision>1:
         raise FLANNException("The precision argument must be between 0 and 1.")
     params = self.nn.build_index(self.dataset, target_precision=self.options.precision, build_weight=self.options.build_weight,
             memory_weight=self.options.memory_weight, sample_fraction=self.options.sample_fraction)
     
     if self.options.params_file != None:
         params_stream = open(self.options.params_file,"w")
     else:
         params_stream = sys.stdout
     configdict = ConfigParser();
     configdict.add_section('params')
     for (k,v) in params.items():
         configdict.set('params',k,v)
     configdict.write(params_stream)
Example #14
0
    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")