def __init__(self, name=None, threshold=0.25): ''' Create a face detection test. INPUTS: @param name: Label for the test. @param threshold: The fraction of joint area that counts as success. ''' self.name = name self.threshold = threshold self.sample_id = 1 self.table = pv.Table() self.summary_table = pv.Table() # Cumulative statistic self.images = 0 self.positives = 0 self.successes = 0 self.negatives = 0 self.pixels = 0 # Summary statistics self.pos_rate = 0.0 self.pos_bounds = (0.0, 0.0) self.neg_rate = 0.0 self.image_time = None self.total_time = None self.start_time = time.time() self.end_time = None
def __init__(self, name=None, threshold=0.25, test_detect=True): '''''' self.name = name self.table = pv.Table() self.summary_table = pv.Table() self.face_successes = 0 self.both25_successes = 0 self.left25_successes = 0 self.right25_successes = 0 self.both10_successes = 0 self.left10_successes = 0 self.right10_successes = 0 self.both05_successes = 0 self.left05_successes = 0 self.right05_successes = 0 self.bothsse = 0.0 self.rightsse = 0.0 self.leftsse = 0.0 self.pixels = 0 self.images = 0 self.faces = 0 self.start_time = time.time() self.stop_time = None self.test_detect = test_detect self.sample_id = 0
def tuneAlogirthmExaustive(self, verbose=True): ''' This conducts an exaustive search of all tunable parameters to find the best tuning. ''' if len(self.options) == 0: score = self.runTest(self._alg_class, self._alg_args, self._alg_kwargs) self.best_score = score self.best_tuning = copy.deepcopy(self._alg_kwargs) results = pv.Table() results[0, 'tuning'] = 'None' results[0, 'score'] = score self.tuning_data = results else: # Get keywords and values keywords = [key for key, _ in self.options] values = [val for _, val in self.options] r = 0 results = pv.Table() # Test all possible tuning assignments for vals in it.product(*values): # construct kwargs for this assignment kwargs = copy.deepcopy(self._alg_kwargs) for i in range(len(keywords)): kw = keywords[i] val = vals[i] kwargs[kw] = val results[r, kw] = val # run a cross validation test score = self.runTest(self._alg_class, self._alg_args, kwargs, verbose=verbose) # save the best score if self.classification and (self.best_score == None or score > self.best_score): self.best_score = score self.best_tuning = kwargs if not self.classification and (self.best_score == None or score < self.best_score): self.best_score = score self.best_tuning = kwargs # construct a table of tuning information results[r, 'score'] = score r += 1 #print results self.tuning_data = results
def __init__(self, n_folds=3): CrossValidation.__init__(self, n_folds=n_folds) self.best_alg = None self.best_eval = 0.0 self.results = pv.Table()
def test_GaborFilters(self): ilog = None # pv.ImageLog(name="GaborTest1") #bank = FilterBank(tile_size=(128,128)) kernels = createGaborKernels() filters = GaborFilters(kernels) gim = filters.convolve(self.test_images[0]) template = gim.extractJet(pv.Point(64,64)) table = pv.Table() for i in range(0,128): table[i,'disp'] = i - 64 novel = gim.extractJet(pv.Point(i,64)) table[i,'simMag'] = template.simMag(novel) table[i,'simPhase'] = template.simPhase(novel) table[i,'simDisplace'] = template.simDisplace(novel) dx,dy = template.displace(novel,method="Simple") table[i,'displace_dx'] = dx table[i,'displace_dy'] = dy dx,dy = template.displace(novel,method="Blocked") table[i,'blocked_dx'] = dx table[i,'blocked_dy'] = dy dx,dy = template.displace(novel,method="Iter") table[i,'iter_dx'] = dx table[i,'iter_dy'] = dy
def stats(self): table = pv.Table() table['Mean', 'Value'] = self.matrix.mean() # not computed effecently: table['Std','Value'] = self.matrix.flatten().std() table['Min', 'Value'] = self.matrix.min() table['Max', 'Value'] = self.matrix.max() return table
def __init__(self): ''' Create and setup the timer. Also creates a mark titled "Timer Created". ''' self.table = pv.Table() self.started = False self.i = 0 self.mark("Timer Created")
def summarizeEyeDetectionTests(tests): ''' Create a summary table for a list containing FaceDetectionTest objects. ''' print 'Creating summaries...' summary25 = pv.Table() summary25.setColumnFormat('Face_Rate', '%0.4f') summary25.setColumnFormat('Rate_25', '%0.4f') summary25.setColumnFormat('Lower95_25', '%0.4f') summary25.setColumnFormat('Upper95_25', '%0.4f') summary25.setColumnFormat('Time', '%0.2f') for test in tests: print test.name summary25.setElement(test.name, 'Face_Rate', test.face_rate) summary25.setElement(test.name, 'Rate_25', test.both25_rate) summary25.setElement(test.name, 'Lower95_25', test.both25_ci[0]) summary25.setElement(test.name, 'Upper95_25', test.both25_ci[1]) summary25.setElement(test.name, 'Time', test.elapse_time) summary10 = pv.Table() summary10.setColumnFormat('Face_Rate', '%0.4f') summary10.setColumnFormat('Rate_10', '%0.4f') summary10.setColumnFormat('Lower95_10', '%0.4f') summary10.setColumnFormat('Upper95_10', '%0.4f') summary10.setColumnFormat('Time', '%0.2f') for test in tests: summary10.setElement(test.name, 'Face_Rate', test.face_rate) summary10.setElement(test.name, 'Rate_10', test.both10_rate) summary10.setElement(test.name, 'Lower95_10', test.both10_ci[0]) summary10.setElement(test.name, 'Upper95_10', test.both10_ci[1]) summary10.setElement(test.name, 'Time', test.elapse_time) summary05 = pv.Table() summary05.setColumnFormat('Face_Rate', '%0.4f') summary05.setColumnFormat('Rate_05', '%0.4f') summary05.setColumnFormat('Lower95_05', '%0.4f') summary05.setColumnFormat('Upper95_05', '%0.4f') summary05.setColumnFormat('Time', '%0.2f') for test in tests: summary05.setElement(test.name, 'Face_Rate', test.face_rate) summary05.setElement(test.name, 'Rate_05', test.both05_rate) summary05.setElement(test.name, 'Lower95_05', test.both05_ci[0]) summary05.setElement(test.name, 'Upper95_05', test.both05_ci[1]) summary05.setElement(test.name, 'Time', test.elapse_time) return summary05, summary10, summary25
def tail(self,N=10): '''Returns a table from the last N rows.''' rows = self.row_headers cols = self.col_headers result = pv.Table() for row in rows[-N:]: for col in cols: result[row,col] = self[row,col] return result
def summarizeDetectionTests(tests): ''' Create a summary table for a list containing FaceDetectionTest objects. ''' summary = pv.Table() summary.setColumnFormat('PosRate', '%0.4f') summary.setColumnFormat('Lower95', '%0.4f') summary.setColumnFormat('Upper95', '%0.4f') summary.setColumnFormat('NegRate', '%0.4f') summary.setColumnFormat('Time', '%0.2f') for test in tests: summary.setElement(test.name, 'PosRate', test.pos_rate) summary.setElement(test.name, 'Lower95', test.pos_bounds[0]) summary.setElement(test.name, 'Upper95', test.pos_bounds[1]) summary.setElement(test.name, 'NegRate', test.neg_rate) summary.setElement(test.name, 'Time', test.total_time) return summary
def histogram(self,value_range=None,bins=100,normed=True,mask=None): match_scores = self.getMatchScores(mask=mask) nonmatch_scores = self.getNonMatchScores(mask=mask) if value_range == None: value_range = (self.matrix.min(),self.matrix.max()) match_counts,vals = np.histogram(match_scores,range=value_range,bins=bins,normed=normed) nonmatch_counts,vals = np.histogram(nonmatch_scores,range=value_range,bins=bins,normed=normed) hist = pv.Table() for i in range(len(match_counts)): hist[i,'min'] = vals[i] hist[i,'center'] = 0.5*(vals[i]+vals[i+1]) hist[i,'max'] = vals[i+1] hist[i,'match_count'] = match_counts[i] hist[i,'nonmatch_count'] = nonmatch_counts[i] return hist
def results(self): table = pv.Table(default_value="") pt = self.getFAR(0.001) table[0,'FAR'] = 0.001 table[0,'TAR'] = pt.tar pt = self.getFAR(0.01) table[1,'FAR'] = 0.01 table[1,'TAR'] = pt.tar pt = self.getFAR(0.1) table[2,'FAR'] = 0.1 table[2,'TAR'] = pt.tar table[3,'EER'] = self.getEER() table[4,'AUC'] = self.getAUC() return table
def genderClassifier(clsfy, ilog=None): ''' genderClassifier takes a classifier as an argument and will use the csuScrapShot data to perform a gender classification test on that classifier. These three functions will be called:: for im in training_images: clsfy.addTraining(label,im,ilog=ilog) clsfy.train(ilog=ilog) for im in testing_images: clsfy.predict(im,ilog=ilog) label = 0 or 1 (0=Female,1=Male) im is a 64x64 pyvision image that is normalized to crop the face Output of predict should be a class label (0 or 1) @returns: the success rate for the testing set. ''' filename = os.path.join(pv.__path__[0], 'data', 'csuScrapShots', 'gender.txt') f = open(filename, 'r') image_cache = [] examples = [] for line in f: im_name, class_name = line.split() if class_name == 'F': class_name = 0 else: class_name = 1 long_name = os.path.join(pv.__path__[0], 'data', 'csuScrapShots', im_name) leye, reye = SCRAPS_EYES.getEyes(im_name)[0] im = pv.Image(long_name) image_cache.append(im) im = pv.AffineFromPoints(leye, reye, pv.Point(22, 27), pv.Point(42, 27), (64, 64)).transformImage(im) #im = pv.Image(im.asPIL().resize((64,64))) examples.append([class_name, im, im_name]) training = examples[:103] testing = examples[103:] for each in training[:103]: clsfy.addTraining(each[0], each[1], ilog=ilog) clsfy.train(ilog=ilog) table = pv.Table() values = {0: [], 1: []} correct = 0 total = 0 for each in testing: label = clsfy.predict(each[1], ilog=ilog) total += 1 if label == each[0]: correct += 1 rate = float(correct) / total if ilog: ilog.table(table) return rate
import pyvision as pv ilog = pv.ImageLog() im = pv.Image("baboon.jpg") ilog(im,"Baboon") table = pv.Table() table[1,"image"] = im.filename table[1,"width"] = im.size[0] table[1,"height"] = im.size[1] ilog(table,"ImageData") print(table) plot = pv.Plot(title="Some Dots and Lines"); plot.points([[3.5,7.1],[1,1],[5.5,2]],shape=2) plot.lines([[5.5,7.5],[2,3],[3.3,7]]) ilog(plot,"MyPlot") ilog.show()