<commit_before>import numpy as np
import warnings

import chainer
from chainer import cuda

from chainercv.transforms import center_crop
from chainercv.transforms import scale
from chainercv.transforms import ten_crop


class FeatureExtractionPredictor(chainer.Chain):

    """Wrapper around a feature extraction model to add predict method.

    This chain wraps aroudn a feature extraction model to predict features
    from images.
    The :meth:`predict` takes three steps to make predictions.

    1. Preprocess images
    2. Forward the preprocessed images to the network
    3. Average features in the case when ten-crop is used.

    Example:

        >>> from chainercv.links import VGG16
        >>> from chainercv.links import FeatureExtractionPredictor
        >>> base_model = VGG16(layer_names='prob')
        >>> model = FeatureExtractionPredictor(base_model)
        >>> prob = model.predict([img])

    """

    def __init__(self, extractor,
                 size=(224, 224), scale_size=256,
                 do_ten_crop=False):
        super(FeatureExtractionPredictor, self).__init__()
        self.scale_size = scale_size
        self.size = size
        self.do_ten_crop = do_ten_crop

        with self.init_scope():
            self.extractor = extractor

    @property
    def mean(self):
        return self.extractor.mean

    def _prepare(self, img):
        """Transform an image to the input for VGG network.<commit_msg>fix doc<commit_after>import numpy as np
import warnings

import chainer
from chainer import cuda

from chainercv.transforms import center_crop
from chainercv.transforms import scale
from chainercv.transforms import ten_crop


class FeatureExtractionPredictor(chainer.Chain):

    """Wrapper class that adds predict method to a feature extraction model.

    The :meth:`predict` takes three steps to make predictions.

    1. Preprocess images
    2. Forward the preprocessed images to the network
    3. Average features in the case when ten-crop is used.

    Example:

        >>> from chainercv.links import VGG16
        >>> from chainercv.links import FeatureExtractionPredictor
        >>> base_model = VGG16()
        >>> model = FeatureExtractionPredictor(base_model)
        >>> prob = model.predict([img])

    """

    def __init__(self, extractor,
                 size=(224, 224), scale_size=256,
                 do_ten_crop=False):
        super(FeatureExtractionPredictor, self).__init__()
        self.scale_size = scale_size
        self.size = size
        self.do_ten_crop = do_ten_crop

        with self.init_scope():
            self.extractor = extractor

    @property
    def mean(self):
        return self.extractor.mean

    def _prepare(self, img):
        """Transform an image to the input for VGG network.
{'fraction_non_alphanumeric': 0.07463222102619303, 'fraction_numerical': 0.011481880157875853, 'mean_word_length': 2.8349381017881705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5522158', 'n_tokens_mistral': 822, 'n_tokens_neox': 755, 'n_words': 246}