<commit_before>import contextlib
import itertools
import numpy as np
import os
import six
import sys

try:
    import pycocotools.coco
    import pycocotools.cocoeval
    _available = True
except ImportError:
    _available = False


def eval_detection_coco(pred_bboxes, pred_labels, pred_scores, gt_bboxes,
                        gt_labels, gt_areas=None, gt_crowdeds=None):
    """Evaluate detections based on evaluation code of MS COCO.

    This function evaluates predicted bounding boxes obtained from a dataset
    by using average precision for each class.
    The code is based on the evaluation code used in MS COCO.

    .. _`evaluation page`: http://cocodataset.org/#detections-eval

    Args:
        pred_bboxes (iterable of numpy.ndarray): See the table below.
        pred_labels (iterable of numpy.ndarray): See the table below.
        pred_scores (iterable of numpy.ndarray): See the table below.
        gt_bboxes (iterable of numpy.ndarray): See the table below.
        gt_labels (iterable of numpy.ndarray): See the table below.
        gt_areas (iterable of numpy.ndarray): See the table below.
        gt_crowdeds (iterable of numpy.ndarray): See the table below.

    .. csv-table::
        :header: name, shape, dtype, format

        :obj:`pred_bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
        ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
        :obj:`pred_labels`, ":math:`[(R,)]`", :obj:`int32`, \
        ":math:`[0, \#fg\_class - 1]`"
        :obj:`pred_scores`, ":math:`[(R,)]`", :obj:`float32`, \
        --
        :obj:`gt_bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
        ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
        :obj:`gt_labels`, ":math:`[(R,)]`", :obj:`int32`, \
        ":math:`[0, \#fg\_class - 1]`"
        :obj:`gt_areas`, ":math:`[(R,)]`", \
        :obj:`float32`, --
        :obj:`gt_crowdeds`, ":math:`[(R,)]`", :obj:`bool`, --

    All inputs should have the same length. For more detailed explanation
    of the inputs, please refer to
    :class:`chainercv.datasets.COCOBboxDataset`.

    .. seealso::
        :class:`chainercv.datasets.COCOBboxDataset`.

    Returns:
        dict:

        The keys, value-types and the description of the values are listed
        below. The APs and ARs calculated with different iou
        thresholds, sizes of objects, and numbers of detections
        per image. For more details on the 12 patterns of evaluation metrics,
        please refer to COCO's official `evaluation page`_.

        .. csv-table::
            :header: key, type, description

            ap/iou=0.50:0.95/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.75/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=small/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=medium/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=large/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ar/iou=0.50:0.95/area=all/maxDets=1, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50/area=all/maxDets=10, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.75/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=small/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=medium/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=large/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            map/iou=0.50:0.95/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.75/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=small/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=medium/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=large/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            ar/iou=0.50:0.95/area=all/maxDets=1, *float*, \
                [#coco_det_eval_4]_
            ar/iou=0.50/area=all/maxDets=10, *float*, \
                [#coco_det_eval_4]_
            ar/iou=0.75/area=all/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            ar/iou=0.50:0.95/area=small/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            ar/iou=0.50:0.95/area=medium/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            ar/iou=0.50:0.95/area=large/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            coco_eval, *pycocotools.cocoeval.COCOeval*, \
                result from :obj:`pycocotools`

    .. [#coco_det_eval_1] An array of average precisions. \
        The :math:`l`-th value corresponds to the average precision \
        for class :math:`l`. If class :math:`l` does not exist in \
        either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding \
        value is set to :obj:`numpy.nan`.
    .. [#coco_det_eval_2] An array of average recalls. \
        The :math:`l`-th value corresponds to the average precision \
        for class :math:`l`. If class :math:`l` does not exist in \
        either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding \
        value is set to :obj:`numpy.nan`.
    .. [#coco_det_eval_3] The average of average precisions over classes.
    .. [#coco_det_eval_4] The average of average recalls over classes.

    """
    if not _available:
        raise ValueError(
            'Please install pycocotools \n'
            'pip install -e \'git+https://github.com/pdollar/coco.git'
            '#egg=pycocotools&subdirectory=PythonAPI\'')
<commit_msg>fix doc of eval_detection_coco<commit_after>import contextlib
import itertools
import numpy as np
import os
import six
import sys

try:
    import pycocotools.coco
    import pycocotools.cocoeval
    _available = True
except ImportError:
    _available = False


def eval_detection_coco(pred_bboxes, pred_labels, pred_scores, gt_bboxes,
                        gt_labels, gt_areas=None, gt_crowdeds=None):
    """Evaluate detections based on evaluation code of MS COCO.

    This function evaluates predicted bounding boxes obtained from a dataset
    by using average precision for each class.
    The code is based on the evaluation code used in MS COCO.

    .. _`evaluation page`: http://cocodataset.org/#detections-eval

    Args:
        pred_bboxes (iterable of numpy.ndarray): See the table below.
        pred_labels (iterable of numpy.ndarray): See the table below.
        pred_scores (iterable of numpy.ndarray): See the table below.
        gt_bboxes (iterable of numpy.ndarray): See the table below.
        gt_labels (iterable of numpy.ndarray): See the table below.
        gt_areas (iterable of numpy.ndarray): See the table below.
        gt_crowdeds (iterable of numpy.ndarray): See the table below.

    .. csv-table::
        :header: name, shape, dtype, format

        :obj:`pred_bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
        ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
        :obj:`pred_labels`, ":math:`[(R,)]`", :obj:`int32`, \
        ":math:`[0, \#fg\_class - 1]`"
        :obj:`pred_scores`, ":math:`[(R,)]`", :obj:`float32`, \
        --
        :obj:`gt_bboxes`, ":math:`[(R, 4)]`", :obj:`float32`, \
        ":math:`(y_{min}, x_{min}, y_{max}, x_{max})`"
        :obj:`gt_labels`, ":math:`[(R,)]`", :obj:`int32`, \
        ":math:`[0, \#fg\_class - 1]`"
        :obj:`gt_areas`, ":math:`[(R,)]`", \
        :obj:`float32`, --
        :obj:`gt_crowdeds`, ":math:`[(R,)]`", :obj:`bool`, --

    All inputs should have the same length. For more detailed explanation
    of the inputs, please refer to
    :class:`chainercv.datasets.COCOBboxDataset`.

    .. seealso::
        :class:`chainercv.datasets.COCOBboxDataset`.

    Returns:
        dict:

        The keys, value-types and the description of the values are listed
        below. The APs and ARs calculated with different iou
        thresholds, sizes of objects, and numbers of detections
        per image. For more details on the 12 patterns of evaluation metrics,
        please refer to COCO's official `evaluation page`_.

        .. csv-table::
            :header: key, type, description

            ap/iou=0.50:0.95/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.75/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=small/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=medium/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ap/iou=0.50:0.95/area=large/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_1]_
            ar/iou=0.50:0.95/area=all/maxDets=1, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50/area=all/maxDets=10, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.75/area=all/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=small/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=medium/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            ar/iou=0.50:0.95/area=large/maxDets=100, *numpy.ndarray*, \
                [#coco_det_eval_2]_
            map/iou=0.50:0.95/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.75/area=all/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=small/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=medium/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            map/iou=0.50:0.95/area=large/maxDets=100, *float*, \
                [#coco_det_eval_3]_
            mar/iou=0.50:0.95/area=all/maxDets=1, *float*, \
                [#coco_det_eval_4]_
            mar/iou=0.50/area=all/maxDets=10, *float*, \
                [#coco_det_eval_4]_
            mar/iou=0.75/area=all/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            mar/iou=0.50:0.95/area=small/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            mar/iou=0.50:0.95/area=medium/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            mar/iou=0.50:0.95/area=large/maxDets=100, *float*, \
                [#coco_det_eval_4]_
            coco_eval, *pycocotools.cocoeval.COCOeval*, \
                result from :obj:`pycocotools`

    .. [#coco_det_eval_1] An array of average precisions. \
        The :math:`l`-th value corresponds to the average precision \
        for class :math:`l`. If class :math:`l` does not exist in \
        either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding \
        value is set to :obj:`numpy.nan`.
    .. [#coco_det_eval_2] An array of average recalls. \
        The :math:`l`-th value corresponds to the average precision \
        for class :math:`l`. If class :math:`l` does not exist in \
        either :obj:`pred_labels` or :obj:`gt_labels`, the corresponding \
        value is set to :obj:`numpy.nan`.
    .. [#coco_det_eval_3] The average of average precisions over classes.
    .. [#coco_det_eval_4] The average of average recalls over classes.

    """
    if not _available:
        raise ValueError(
            'Please install pycocotools \n'
            'pip install -e \'git+https://github.com/pdollar/coco.git'
            '#egg=pycocotools&subdirectory=PythonAPI\'')

{'fraction_non_alphanumeric': 0.14517311608961303, 'fraction_numerical': 0.038126272912423625, 'mean_word_length': 2.206896551724138, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '123479', 'n_tokens_mistral': 4724, 'n_tokens_neox': 4328, 'n_words': 853}