コード例 #1
0
def CalculateResamplingModel(options, windowCount, baselineTime=None):
  nWindows, maxHogTime, EstimateTime = PlottingUtils.ParseHogTiming(options)
  if baselineTime is None:
    baselineTime = maxHogTime
  nPeople = len(windowCount)
  fracWindows = np.exp(np.arange(0.0, 6, 0.01))
  nonZeroCounts = filter(lambda x: x>0, windowCount)
  nFound = np.array([sum([min(count/frac,1) for count in nonZeroCounts])
            for frac in fracWindows])
  #nFound = np.append(nFound, [0.0])
  meanRecall = np.divide(nFound, nPeople)
  nVariance = np.array([sum([GetVarianceOfOnePerson(count, frac)
                             for count in nonZeroCounts])
                        for frac in fracWindows])
  #nVariance = np.append(nVariance, [0.0])
  stdRecall = np.divide(np.sqrt(nVariance), nPeople)
  windowCount = np.array([nWindows/frac for frac in fracWindows])
  #windowCount = np.append(windowCount, [0.0])
  processingTime = EstimateTime(windowCount)
  speedup = np.divide(baselineTime, processingTime)

  return (speedup, meanRecall, stdRecall, windowCount, processingTime)
コード例 #2
0
                               stats.nWindows[0:1],
                               groupColors,
                               groupMarkers,
                               groupNames,
                               'Recall',
                               'Number of Windows',
                               stats.nVUEstimators,
                               validEntries=validEntries)
  AddLineToPlot(curFig, resamplingModel[1], resamplingModel[3],
                '.', 'chocolate', 'Resampling Initial Boxes', 2)
  if options.output_prefix is not None:
    savefig(options.output_prefix + '_winVrecall.eps')
    savefig(options.output_prefix + '_winVrecall.png')

  # Calculate the timing of just using the visual utility estimator
  garb1, garb2, EstimateTime = PlottingUtils.ParseHogTiming(options)
  vuProcessingTime = stats.processingTime - EstimateTime(stats.nWindows)

  # Bayes risk vs. speedup
  PlotAccuracyScatter([slowHogProcessingTime / x[6] for
                       x in stats.scaledHogStats],
                      [x[1] for x in stats.scaledHogStats],
                      (stats.accuracy / np.max(stats.accuracy)) +
                      (stats.processingTime / slowHogProcessingTime),
                      stats.recall,
                      groupColors,
                      groupMarkers,
                      groupNames,
                      'Bayes Risk * Processing Time',
                      'Recall',
                      stats.nVUEstimators,
コード例 #3
0
    scores = VUScores(options)

    # Plot a histogram of the number of positive windows per person
    nonZeroCounts = filter(lambda x: x > 0, scores.windowCount.values())
    figure()
    hist(nonZeroCounts, 50, histtype='step')

    # Plot a histogram of the size of people
    figure()
    hist([math.sqrt(x.Area()) for x in scores.personLoc.itervalues()],
         50,
         histtype='step')

    # Plot a model for the recall vs. speedup assuming resampling
    nWindows, maxHogTime, EstimateTime = PlottingUtils.ParseHogTiming(options)
    nPeople = len(scores.windowCount)
    fracWindows = np.arange(1.0, 40.0)
    nFound = np.array([
        sum([min(count / frac, 1) for count in nonZeroCounts])
        for frac in fracWindows
    ])
    meanRecall = np.divide(nFound, nPeople)
    nVariance = np.array([
        sum([GetVarianceOfOnePerson(count, frac) for count in nonZeroCounts])
        for frac in fracWindows
    ])
    stdRecall = np.sqrt(np.divide(nVariance, nPeople * nPeople))
    speedup = [
        maxHogTime / EstimateTime(nWindows / frac) for frac in fracWindows
    ]
コード例 #4
0
ファイル: VUAccuracy.py プロジェクト: balghane/reefbot-1
    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
コード例 #5
0
                      default='HOGCachedDetector')
    parser.add_option(
        '--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,