def __init__(self, options): self.VERSION = int( VERSION ) # Version number if we change how the stats are calculated. self.options = options # To record all the settings self.accuracy = [] self.precision = [] self.recall = [] self.errorRate = [] self.groundTruths = [] self.resampleHogStats = [] self.scaledHogStats = [] self.nWindows = [] self.processingTime = [] self.matthewsCoefficients = [] self.hogPRCurves = [] self.vuNegPrecision = [] self.vuRecall = [] self.vuPrecision = [] self.peopleWindowCount = { } # (imageFile, personId)-># positive windows PrepareCache(options) garb, self.hogProcessingTime, hogTiming = \ PlottingUtils.ParseHogTiming(options) annotationsMap = PlottingUtils.ParseAnnotationFiles(options) bags, datasets, vuTypes = PlottingUtils.FindVUBags(options) scaledHogBags = FindScaledHogBags(options) self.nVUEstimators = len(vuTypes) if options.do_resampling: self.nVUEstimators += 1 scalingFactors = sorted( set([ scalingFactor for x, scalingFactor in scaledHogBags.iterkeys() ])) timingData = PlottingUtils.FindTimingData(vuTypes, options) hogBag = CreateVUScore([bags[(options.hog_name, x)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, options.do_nms, options.hog_thresh, options.min_overlap, cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex) hogOffsetBag = None if options.frame_subset_rate >= 2: hogOffsetBag = hogBag hogBag = CreateVUScore( [bags[(options.hog_name, x)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, options.do_nms, options.hog_thresh, options.min_overlap, cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex, frameSubsetOffset=1) for vuType in vuTypes: offsetVuBags = None vuBags = [ CreateVUScore([bags[(vuType, x)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, thresholdTimes=timingData[vuType], cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex) ] if options.frame_subset_rate >= 2: offsetVuBags = vuBags vuBags = [ CreateVUScore([bags[(vuType, x)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, thresholdTimes=timingData[vuType], cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex, frameSubsetOffset=1) ] scoreMatrix = ScoreMatrix(hogBag, vuBags, options.min_overlap, options.hog_thresh, options.cache_dir, options.do_vu_nms, options.prop_pos, offsetVuBags, hogOffsetBag) (curAccuracy, curPrecision, curRecall, curErrorRate, curNWindows, curProcessingTime, curMatCoefs, curVuNegPrecision, curVuPrecision, curVuRecall) = \ scoreMatrix.GetStats(options.min_overlap, options.hog_thresh, 20, hogTiming) self.accuracy.append(curAccuracy) self.precision.append(curPrecision) self.recall.append(curRecall) self.errorRate.append(curErrorRate) self.nWindows.append(curNWindows) self.processingTime.append(curProcessingTime) self.matthewsCoefficients.append(curMatCoefs) self.vuNegPrecision.append(curVuNegPrecision) self.vuPrecision.append(curVuPrecision) self.vuRecall.append(curVuRecall) if len(self.peopleWindowCount) == 0: self.peopleWindowCount = scoreMatrix.peopleWindowCount del vuBags del scoreMatrix gc.collect() # Do the calculator for resampling the boxes if options.do_resampling: for scaleStep in range(1, 8, 2): for strideStep in range(1, 8, 2): self.resampleHogStats.append( CalculateHOGStatistics(hogBag, options.min_overlap, options.hog_thresh, strideStep, scaleStep, options.cache_dir)) self.resampleHogStats.extend([ tuple([float('nan') for x in range(10)]) for y in range(curAccuracy.shape[1] - len(self.resampleHogStats)) ]) resampleProcessingTime = hogTiming( [x[4] for x in self.resampleHogStats]) sortIdx = np.argsort(resampleProcessingTime) self.accuracy.append( [[self.resampleHogStats[x][0] for x in sortIdx]]) self.precision.append( [[self.resampleHogStats[x][1] for x in sortIdx]]) self.recall.append([[self.resampleHogStats[x][2] for x in sortIdx]]) self.errorRate.append( [[self.resampleHogStats[x][3] for x in sortIdx]]) self.nWindows.append( [[self.resampleHogStats[x][4] for x in sortIdx]]) self.matthewsCoefficients.append( [[self.resampleHogStats[x][5] for x in sortIdx]]) self.processingTime.append([np.sort(resampleProcessingTime)]) self.vuNegPrecision.append( [[self.resampleHogStats[x][7] for x in sortIdx]]) self.vuRecall.append( [[self.resampleHogStats[x][9] for x in sortIdx]]) self.vuPrecision.append( [[self.resampleHogStats[x][8] for x in sortIdx]]) # Calculate the statistics for no VU filter self.groundTruths.append( CalculateHOGStatistics(hogBag, options.min_overlap, options.hog_thresh, cacheDir=options.cache_dir)) self.hogPRCurves.append(CalculatePRCurve(hogBag, options.min_overlap)) del hogBag gc.collect() # Now cycle through all the scaled hog bags to get a baseline # assuming resizing. if options.do_scaling: for scalingFactor in scalingFactors: scaledHogBag = CreateVUScore( [scaledHogBags[(x, scalingFactor)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, options.do_nms, options.hog_thresh, options.min_overlap, cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex) self.scaledHogStats.append( CalculateHOGStatistics(scaledHogBag, options.min_overlap, options.hog_thresh, cacheDir=options.cache_dir)) del scaledHogBag gc.collect() self.accuracy = np.concatenate(self.accuracy, 0) self.precision = np.concatenate(self.precision, 0) self.recall = np.concatenate(self.recall, 0) self.errorRate = np.concatenate(self.errorRate, 0) self.nWindows = np.concatenate(self.nWindows, 0) self.processingTime = np.concatenate(self.processingTime, 0) self.matthewsCoefficients = np.concatenate(self.matthewsCoefficients, 0) self.vuNegPrecision = np.concatenate(self.vuNegPrecision, 0) self.vuPrecision = np.concatenate(self.vuPrecision, 0) self.vuRecall = np.concatenate(self.vuRecall, 0) self.vuTypes = vuTypes
'--min_overlap', type='float', help='Minimum fraction overlap for a target to be correct', default=0.5) parser.add_option( '--cache_dir', default='/data/mdesnoye/pedestrian/vu_estimation/eth/cache', help= 'Directory to use to cache subcomponents in this data so that it can be computed faster' ) (options, args) = parser.parse_args() hogProcessingTime, hogTiming = PlottingUtils.ParseHogTiming(options) timingData = PlottingUtils.FindTimingData(vuTypes, options) annotationsMap = PlottingUtils.ParseAnnotationFiles(options) bags, datasets, vuTypes = PlottingUtils.FindVUBags(options) hogScore = VUAccuracy.CreateVUScore( [bags[(options.hog_name, x)] for x in datasets], [annotationsMap[x] for x in datasets], options.frame_subset_rate, False, # doNMS options.hog_thresh, options.min_overlap, cacheDir=options.cache_dir, imageIdRegex=options.imageid_regex)