Esempio n. 1
0
    def get_results(self):
        """
        Reruns the evaluation using the accumulated detections, returns COCO results with AP metrics

        :return: dict with COCO AP metrics
        """
        if self.cached_results:
            return self.results

        self.coco_evaluator = CocoEvaluator(self.coco, self.iou_types)
        self.coco_evaluator.update(self.detections)
        self.coco_evaluator.evaluate()
        self.coco_evaluator.accumulate()
        self.coco_evaluator.summarize()

        self.results = get_coco_metrics(self.coco_evaluator)
        self.speed_mem_metrics[
            'Max Memory Allocated (Total)'] = get_max_memory_allocated()

        return self.results
Esempio n. 2
0
    def add(self, detections: list):
        """
        Update the evaluator with new detections

        :param annotations (list): List of detections, that will be used by the COCO.loadRes method in the
        pycocotools API.  Each detection can take a dictionary format like the following:

        {'image_id': 397133, 'bbox': [386.1628112792969, 69.48855590820312, 110.14895629882812, 278.2847595214844],
        'score': 0.999152421951294, 'category_id': 1}

        I.e is a list of dictionaries.

        :return: void - updates self.detection with the new IDSs and prediction

        Examples:
            Update the evaluator with two results:

            .. code-block:: python

                my_evaluator.add([{'image_id': 397133, 'bbox': [386.1628112792969, 69.48855590820312,
                110.14895629882812, 278.2847595214844], 'score': 0.999152421951294, 'category_id': 1}])
        """
        self.detections.extend(detections)

        self.coco_evaluator.update(detections)

        if not self.first_batch_processed:
            self.coco_evaluator.evaluate()
            self.coco_evaluator.accumulate()

            if any(
                [detection["bbox"] for detection in detections]
            ):  # we can only hash if we have predictions
                self.batch_hash = calculate_batch_hash(
                    self.cache_values(
                        annotations=detections,
                        metrics=get_coco_metrics(self.coco_evaluator),
                    )
                )
                self.first_batch_processed = True