예제 #1
0
 def finish(self):
         self.face_rate    = float(self.face_successes)/self.faces
         self.face_ci      = pv.cibinom(self.faces,self.face_successes,alpha=0.05)
         self.both25_rate  = float(self.both25_successes)/self.faces
         self.both25_ci    = pv.cibinom(self.faces,self.both25_successes,alpha=0.05)
         self.both10_rate  = float(self.both10_successes)/self.faces
         self.both10_ci    = pv.cibinom(self.faces,self.both10_successes,alpha=0.05)
         self.both05_rate  = float(self.both05_successes)/self.faces
         self.both05_ci    = pv.cibinom(self.faces,self.both05_successes,alpha=0.05)
         self.left25_rate  = float(self.left25_successes)/self.faces
         self.left25_ci    = pv.cibinom(self.faces,self.left25_successes,alpha=0.05)
         self.left10_rate  = float(self.left10_successes)/self.faces
         self.left10_ci    = pv.cibinom(self.faces,self.left10_successes,alpha=0.05)
         self.left05_rate  = float(self.left05_successes)/self.faces
         self.left05_ci    = pv.cibinom(self.faces,self.left05_successes,alpha=0.05)
         self.right25_rate  = float(self.right25_successes)/self.faces
         self.right25_ci    = pv.cibinom(self.faces,self.right25_successes,alpha=0.05)
         self.right10_rate  = float(self.right10_successes)/self.faces
         self.right10_ci    = pv.cibinom(self.faces,self.right10_successes,alpha=0.05)
         self.right05_rate  = float(self.right05_successes)/self.faces
         self.right05_ci    = pv.cibinom(self.faces,self.right05_successes,alpha=0.05)
         if self.face_successes > 0:
             self.bothrmse = math.sqrt(self.bothsse/(2*self.face_successes))
             self.leftrmse = math.sqrt(self.leftsse/self.face_successes)
             self.rightrmse = math.sqrt(self.rightsse/self.face_successes)
         self.elapse_time  = self.stop_time - self.start_time
         self.time_per_image = self.elapse_time / self.images
         self.time_per_face  = self.elapse_time / self.faces
예제 #2
0
 def finish(self):
     self.face_rate = float(self.face_successes) / self.faces
     self.face_ci = pv.cibinom(self.faces, self.face_successes, alpha=0.05)
     self.both25_rate = float(self.both25_successes) / self.faces
     self.both25_ci = pv.cibinom(self.faces,
                                 self.both25_successes,
                                 alpha=0.05)
     self.both10_rate = float(self.both10_successes) / self.faces
     self.both10_ci = pv.cibinom(self.faces,
                                 self.both10_successes,
                                 alpha=0.05)
     self.both05_rate = float(self.both05_successes) / self.faces
     self.both05_ci = pv.cibinom(self.faces,
                                 self.both05_successes,
                                 alpha=0.05)
     self.left25_rate = float(self.left25_successes) / self.faces
     self.left25_ci = pv.cibinom(self.faces,
                                 self.left25_successes,
                                 alpha=0.05)
     self.left10_rate = float(self.left10_successes) / self.faces
     self.left10_ci = pv.cibinom(self.faces,
                                 self.left10_successes,
                                 alpha=0.05)
     self.left05_rate = float(self.left05_successes) / self.faces
     self.left05_ci = pv.cibinom(self.faces,
                                 self.left05_successes,
                                 alpha=0.05)
     self.right25_rate = float(self.right25_successes) / self.faces
     self.right25_ci = pv.cibinom(self.faces,
                                  self.right25_successes,
                                  alpha=0.05)
     self.right10_rate = float(self.right10_successes) / self.faces
     self.right10_ci = pv.cibinom(self.faces,
                                  self.right10_successes,
                                  alpha=0.05)
     self.right05_rate = float(self.right05_successes) / self.faces
     self.right05_ci = pv.cibinom(self.faces,
                                  self.right05_successes,
                                  alpha=0.05)
     if self.face_successes > 0:
         self.bothrmse = math.sqrt(self.bothsse / (2 * self.face_successes))
         self.leftrmse = math.sqrt(self.leftsse / self.face_successes)
         self.rightrmse = math.sqrt(self.rightsse / self.face_successes)
     self.elapse_time = self.stop_time - self.start_time
     self.time_per_image = self.elapse_time / self.images
     self.time_per_face = self.elapse_time / self.faces
예제 #3
0
    def computeRates(self, alpha=0.05):
        ''' 
        Populates the distance matrix with more information such as 
        recognition rates for each row. Call this only after all of the 
        data has been added. 
        '''
        self.row_headers.sort()
        self.col_headers.sort()

        for row in self.classes:
            successes = 0
            total = 0
            for col in self.classes:
                total += self.element(row, col)
                if row == col:
                    successes += self.element(row, col)
            rate = float(successes) / total
            self.setData(row, 'Rate', rate)
            self.setData(row, 'Bar', "#" * int(10 * rate + 0.5))
            self.setData(row, 'Lower', pv.cibinom(total, successes, alpha)[0])
            self.setData(row, 'Upper', pv.cibinom(total, successes, alpha)[1])

        for col in self.classes:
            successes = 0
            total = 0
            for row in self.classes:
                total += self.element(row, col)
                if row == col:
                    successes += self.element(row, col)
            rate = 'N/A'
            self.setData('Total', col, "%s" % rate)
            try:
                rate = float(successes) / total
                self.setData('Total', col, "%0.4f" % rate)
            except:
                pass

        self.setData('Total', 'Rate', self.update_rate())
        self.setData('Total', 'Bar', "#" * int(10 * self.update_rate() + 0.5))
        self.setData('Total', 'Lower', self.confidenceInterval(alpha)[0])
        self.setData('Total', 'Upper', self.confidenceInterval(alpha)[1])
예제 #4
0
 def computeRates(self,alpha=0.05):
     ''' 
     Populates the distance matrix with more information such as 
     recognition rates for each row. Call this only after all of the 
     data has been added. 
     '''
     self.row_headers.sort()
     self.col_headers.sort()
     
     for row in self.classes:
         successes = 0
         total = 0
         for col in self.classes:
             total += self.element(row,col)
             if row == col:
                 successes += self.element(row,col)
         rate = float(successes)/total
         self.setData(row,'Rate',rate)
         self.setData(row,'Bar',"#"*int(10*rate+0.5))
         self.setData(row,'Lower',pv.cibinom(total,successes,alpha)[0])
         self.setData(row,'Upper',pv.cibinom(total,successes,alpha)[1])
     
     for col in self.classes:
         successes = 0
         total = 0
         for row in self.classes:
             total += self.element(row,col)
             if row == col:
                 successes += self.element(row,col)
         rate = float(successes)/total
         self.setData('Total',col,"%0.4f"%rate)
     
     self.setData('Total','Rate',self.update_rate())
     self.setData('Total','Bar',"#"*int(10*self.update_rate()+0.5))
     self.setData('Total','Lower',self.confidenceInterval(alpha)[0])
     self.setData('Total','Upper',self.confidenceInterval(alpha)[1])
예제 #5
0
 def confidenceInterval(self, alpha=0.05):
     '''
     Returns the estimated a confidence interval for the success update_rate by 
     modeling the success update_rate as a binomial distribution.
     '''
     return pv.cibinom(self.total, self.successes, alpha=alpha)
예제 #6
0
 def confidenceInterval(self,alpha=0.05):
     '''
     Returns the estimated a confidence interval for the success update_rate by 
     modeling the success update_rate as a binomial distribution.
     '''
     return pv.cibinom(self.total,self.successes,alpha=alpha)
예제 #7
0
    def addSample(self, truth_rects, detected_rects, im=None, annotate=False):
        '''
        Adds a sample to face detection test.
        
        @param truth_rects:    truth for an image.
        @param detected_rects: output of the detector
        @param im:             the image or filename to assciate with the sample.
        @param annotate:       add diagnostic annotations to the images.
        '''
        self.images += 1
        name = None
        detected_rects = copy.copy(detected_rects)

        if isinstance(im, pv.Image):
            name = im.filename
            if self.pixels != None:
                self.pixels += im.asPIL().size[0] * im.asPIL().size[1]
        elif isinstance(im, str):
            name = im
            self.pixels = None
        else:
            name = "%d" % self.sample_id
            self.pixels = None

        table = self.table

        for i in range(len(truth_rects)):
            truth = truth_rects[i]
            self.positives += 1
            success = False
            best_overlap = 0.0
            best_detection = None

            for j in range(len(detected_rects)):
                detected = detected_rects[j]
                overlap = overlap_score(truth, detected)
                if overlap >= self.threshold and overlap > best_overlap:
                    success = True
                    best_overlap = overlap
                    best_detection = j

            table.setData(self.sample_id, 'id', self.sample_id)
            table.setData(self.sample_id, 'name', name)
            table.setData(self.sample_id, 'truth_rect', str(truth))
            if best_detection != None:
                table.setData(self.sample_id, 'detection_rect',
                              str(detected_rects[best_detection]))
            else:
                table.setData(self.sample_id, 'detection_rect', None)
            table.setData(self.sample_id, 'success', success)
            table.setData(self.sample_id, 'overlap', best_overlap)
            self.sample_id += 1

            if success:
                self.successes += 1
            if annotate and isinstance(im, pv.Image):
                if success:
                    im.annotateEllipse(truth, color='green')
                else:
                    im.annotateEllipse(truth, color='red')

            # Remove the best detection if success
            if best_detection != None:
                del detected_rects[best_detection]

        if annotate:
            for each in detected_rects:
                im.annotateRect(each, color='red')

        self.negatives += len(detected_rects)

        self.end_time = time.time()
        self.total_time = self.end_time - self.start_time
        self.image_time = self.total_time / float(self.images)
        # Update summary statistics
        if self.positives > 0:
            self.pos_rate = float(self.successes) / self.positives
            self.pos_bounds = pv.cibinom(self.positives,
                                         self.successes,
                                         alpha=0.05)
        if self.pixels != None:
            self.neg_rate = float(self.negatives) / float(1.0e-6 * self.pixels)

        self.createSummary()