<commit_before>import copy
import os
import warnings

import chainer

from chainercv.visualizations.vis_bbox import vis_bbox

try:
    from matplotlib import pyplot as plot
    _available = True

except ImportError:
    _available = False


def _check_available():
    if not _available:
        warnings.warn('matplotlib is not installed on your environment, '
                      'so nothing will be plotted at this time. '
                      'Please install matplotlib to plot figures.\n\n'
                      '  $ pip install matplotlib\n')


class DetectionVisReport(chainer.training.extension.Extension):

    """An extension that visualizes output of a detection model.

    This extension visualizes the predicted bounding boxes together with the
    ground truth bounding boxes.

    The process can be illustrated in the following code.

    .. code:: python

        img, gt_bbox, gt_label = dataset[i]
        pred_bbox, pred_label, pred_score = target.predict(img)
        # Visualization code
        # Uses (img, gt_bbox, gt_label) as the ground truth output
        # Uses (img, pred_bbox, pred_label, pred_score) as the predicted output

    .. note::
        :obj:`gt_bbox` and :obj:`pred_bbox` are float arrays
        of shape :math:`(R, 4)`, where :math:`R` is the number of
        bounding boxes in the image. Each bounding box is organized
        by :obj:`(x_min, y_min, x_max, y_max)` in the second axis.

        :obj:`gt_label` and :obj:`pred_label` are intenger arrays
        of shape :math:`(R,)`. Each label indicates the class of
        the bounding box.

        :obj:`pred_score` is a float array of shape :math:`(R,)`.
        Each score indicates how confident the prediction is.

    Args:
        target (chainercv.links.DetectionLink): Link object used for detection.
        dataset : Dataset class that produces inputs to :obj:`target`.
        filename (str): Basename for saved image.
    """

    invoke_before_training = False

    def __init__(
            self, iterator, target, label_names=None,
            filename='detection_iter={iteration}_idx={index}.jpg'):
        _check_available()

        self.iterator = iterator
        self.target = target
        self.label_names = label_names
        self.filename = filename
<commit_msg>update docs<commit_after>import copy
import os
import warnings

import chainer

from chainercv.visualizations.vis_bbox import vis_bbox

try:
    from matplotlib import pyplot as plot
    _available = True

except ImportError:
    _available = False


def _check_available():
    if not _available:
        warnings.warn('matplotlib is not installed on your environment, '
                      'so nothing will be plotted at this time. '
                      'Please install matplotlib to plot figures.\n\n'
                      '  $ pip install matplotlib\n')


class DetectionVisReport(chainer.training.extension.Extension):

    """An extension that visualizes output of a detection model.

    This extension visualizes the predicted bounding boxes together with the
    ground truth bounding boxes.

    The process can be illustrated in the following code.

    .. code:: python

        batch = next(iterator)
        # Convert batch -> imgs, gt_bboxes, gt_labels
        pred_bboxes, pred_labels, pred_scores = target.predict(imgs)
        # Visualization code
        # Uses (img, gt_bbox, gt_label) as the ground truth output
        # Uses (img, pred_bbox, pred_label, pred_score) as the predicted output

    .. note::
        :obj:`gt_bbox` and :obj:`pred_bbox` are float arrays
        of shape :math:`(R, 4)`, where :math:`R` is the number of
        bounding boxes in the image. Each bounding box is organized
        by :obj:`(x_min, y_min, x_max, y_max)` in the second axis.

        :obj:`gt_label` and :obj:`pred_label` are intenger arrays
        of shape :math:`(R,)`. Each label indicates the class of
        the bounding box.

        :obj:`pred_score` is a float array of shape :math:`(R,)`.
        Each score indicates how confident the prediction is.

    Args:
        iterator: Iterator object that produces images and ground truth.
        target: Link object used for detection.
        label_names (iterable of str): Name of labels ordered according
            to label_ids. If this is :obj:`None`, labels will be skipped.
        filename (str): Basename for saved image.
    """

    invoke_before_training = False

    def __init__(
            self, iterator, target, label_names=None,
            filename='detection_iter={iteration}_idx={index}.jpg'):
        _check_available()

        self.iterator = iterator
        self.target = target
        self.label_names = label_names
        self.filename = filename

{'fraction_non_alphanumeric': 0.07846024400504838, 'fraction_numerical': 0.00042069835927639884, 'mean_word_length': 2.596822995461422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, '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': '132278', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1278, 'n_words': 479}