class_docstr: A pre-trained CNN model provided by MSRA.
  
  When you specify the path of the pre-trained chainer model serialized as
  a ``.npz`` file in the constructor, this chain model automatically
  initializes all the parameters with it.
  This model would be useful when you want to extract a semantic feature
  vector per image, or fine-tune the model on a different dataset.
  Note that unlike ``VGG16Layers``, it does not automatically download a
  pre-trained caffemodel. This caffemodel can be downloaded at
  `GitHub <https://github.com/KaimingHe/deep-residual-networks>`_.
  
  If you want to manually convert the pre-trained caffemodel to a chainer
  model that can be specified in the constructor,
  please use ``convert_caffemodel_to_npz`` classmethod instead.
  
  See: K. He et. al., `Deep Residual Learning for Image Recognition
  <https://arxiv.org/abs/1512.03385>`_
  
  Args:
      pretrained_model (str): the destination of the pre-trained
          chainer model serialized as a ``.npz`` file.
          If this argument is specified as ``auto``,
          it automatically loads and converts the caffemodel from
          ``$CHAINER_DATASET_ROOT/pfnet/chainer/models/ResNet-{n-layers}-model.caffemodel``,
          where ``$CHAINER_DATASET_ROOT`` is set as
          ``$HOME/.chainer/dataset`` unless you specify another value
          by modifying the environment variable and {n_layers} is replaced
          with the specified number of layers given as the first argument to
          this constructor. Note that in this case the converted chainer
          model is stored on the same directory and automatically used from
          the next time.
          If this argument is specified as ``None``, all the parameters
          are not initialized by the pre-trained model, but the default
          initializer used in the original paper, i.e.,
          ``chainer.initializers.HeNormal(scale=1.0)``.
      n_layers (int): The number of layers of this model. It should be either
          50, 101, or 152.
      downsample_fb (bool): If this argument is specified as ``False``,
          it performs downsampling by placing stride 2
          on the 1x1 convolutional layers (the original MSRA ResNet).
          If this argument is specified as ``True``, it performs downsampling
          by placing stride 2 on the 3x3 convolutional layers
          (Facebook ResNet).
  
  Attributes:
      available_layers (list of str): The list of available layer names
          used by ``forward`` and ``extract`` methods.
class_docstr_tok: ["A","pre-trained","CNN","model","provided","by","MSRA",".","When","you","specify","the","path","of","the","pre-trained","chainer","model","serialized","as","a","``",".npz","``","file","in","the","constructor",",","this","chain","model","automatically","initializes","all","the","parameters","with","it",".","This","model","would","be","useful","when","you","want","to","extract","a","semantic","feature","vector","per","image",",","or","fine-tune","the","model","on","a","different","dataset",".","Note","that","unlike","``","VGG16Layers","``",",","it","does","not","automatically","download","a","pre-trained","caffemodel",".","This","caffemodel","can","be","downloaded","at","`","GitHub","<","https",":","\/\/github.com\/KaimingHe\/deep-residual-networks",">","`","_",".","If","you","want","to","manually","convert","the","pre-trained","caffemodel","to","a","chainer","model","that","can","be","specified","in","the","constructor",",","please","use","``","convert_caffemodel_to_npz","``","classmethod","instead",".","See",":","K.","He","et",".","al.",",","`","Deep","Residual","Learning","for","Image","Recognition","<","https",":","\/\/arxiv.org\/abs\/1512.03385",">","`","_","Args",":","pretrained_model","(","str",")",":","the","destination","of","the","pre-trained","chainer","model","serialized","as","a","``",".npz","``","file",".","If","this","argument","is","specified","as","``","auto","``",",","it","automatically","loads","and","converts","the","caffemodel","from","``","$","CHAINER_DATASET_ROOT\/pfnet\/chainer\/models\/ResNet-","{","n-layers","}","-model.caffemodel","``",",","where","``","$","CHAINER_DATASET_ROOT","``","is","set","as","``","$","HOME\/.chainer\/dataset","``","unless","you","specify","another","value","by","modifying","the","environment","variable","and","{","n_layers","}","is","replaced","with","the","specified","number","of","layers","given","as","the","first","argument","to","this","constructor",".","Note","that","in","this","case","the","converted","chainer","model","is","stored","on","the","same","directory","and","automatically","used","from","the","next","time",".","If","this","argument","is","specified","as","``","None","``",",","all","the","parameters","are","not","initialized","by","the","pre-trained","model",",","but","the","default","initializer","used","in","the","original","paper",",","i.e.",",","``","chainer.initializers.HeNormal","(","scale=1.0",")","``",".","n_layers","(","int",")",":","The","number","of","layers","of","this","model",".","It","should","be","either","50",",","101",",","or","152.","downsample_fb","(","bool",")",":","If","this","argument","is","specified","as","``","False","``",",","it","performs","downsampling","by","placing","stride","2","on","the","1x1","convolutional","layers","(","the","original","MSRA","ResNet",")",".","If","this","argument","is","specified","as","``","True","``",",","it","performs","downsampling","by","placing","stride","2","on","the","3x3","convolutional","layers","(","Facebook","ResNet",")",".","Attributes",":","available_layers","(","list","of","str",")",":","The","list","of","available","layer","names","used","by","``","forward","``","and","``","extract","``","methods","."]
docstr: extract(self, images, layers=['pool5'], size=(224, 224))
  
  Extracts all the feature maps of given images.
  
  The difference of directly executing ``forward`` is that
  it directly accepts images as an input and automatically
  transforms them to a proper variable. That is,
  it is also interpreted as a shortcut method that implicitly calls
  ``prepare`` and ``forward`` functions.
  
  Unlike ``predict`` method, this method does not override
  ``chainer.config.train`` and ``chainer.config.enable_backprop``
  configuration. If you want to extract features without updating
  model parameters, you need to manually set configuration when
  calling this method as follows:
  
   .. code-block:: python
  
       # model is an instance of ResNetLayers (50 or 101 or 152 layers)
       with chainer.using_config('train', False):
           with chainer.using_config('enable_backprop', False):
               feature = model.extract([image])
  
  Args:
      images (iterable of PIL.Image or numpy.ndarray): Input images.
      layers (list of str): The list of layer names you want to extract.
      size (pair of ints): The resolution of resized images used as
          an input of CNN. All the given images are not resized
          if this argument is ``None``, but the resolutions of
          all the images should be the same.
  
  Returns:
      Dictionary of ~chainer.Variable: A directory in which
      the key contains the layer name and the value contains
      the corresponding feature map variable.
docstr_tok: ["extract","(","self",",","images",",","layers=","[","'pool5","'","]",",","size=","(","224",",","224",")",")","Extracts","all","the","feature","maps","of","given","images",".","The","difference","of","directly","executing","``","forward","``","is","that","it","directly","accepts","images","as","an","input","and","automatically","transforms","them","to","a","proper","variable",".","That","is",",","it","is","also","interpreted","as","a","shortcut","method","that","implicitly","calls","``","prepare","``","and","``","forward","``","functions",".","Unlike","``","predict","``","method",",","this","method","does","not","override","``","chainer.config.train","``","and","``","chainer.config.enable_backprop","``","configuration",".","If","you","want","to","extract","features","without","updating","model","parameters",",","you","need","to","manually","set","configuration","when","calling","this","method","as","follows",":","..","code-block",":",":","python","#","model","is","an","instance","of","ResNetLayers","(","50","or","101","or","152","layers",")","with","chainer.using_config","(","'train","'",",","False",")",":","with","chainer.using_config","(","'enable_backprop","'",",","False",")",":","feature","=","model.extract","(","[","image","]",")","Args",":","images","(","iterable","of","PIL.Image","or","numpy.ndarray",")",":","Input","images",".","layers","(","list","of","str",")",":","The","list","of","layer","names","you","want","to","extract",".","size","(","pair","of","ints",")",":","The","resolution","of","resized","images","used","as","an","input","of","CNN",".","All","the","given","images","are","not","resized","if","this","argument","is","``","None","``",",","but","the","resolutions","of","all","the","images","should","be","the","same",".","Returns",":","Dictionary","of","~chainer.Variable",":","A","directory","in","which","the","key","contains","the","layer","name","and","the","value","contains","the","corresponding","feature","map","variable","."]
code: def extract(self, images, layers=None, size=(224, 224), **kwargs):
      """extract(self, images, layers=['pool5'], size=(224, 224))
  
      Extracts all the feature maps of given images.
  
      The difference of directly executing ``forward`` is that
      it directly accepts images as an input and automatically
      transforms them to a proper variable. That is,
      it is also interpreted as a shortcut method that implicitly calls
      ``prepare`` and ``forward`` functions.
  
      Unlike ``predict`` method, this method does not override
      ``chainer.config.train`` and ``chainer.config.enable_backprop``
      configuration. If you want to extract features without updating
      model parameters, you need to manually set configuration when
      calling this method as follows:
  
       .. code-block:: python
  
           # model is an instance of ResNetLayers (50 or 101 or 152 layers)
           with chainer.using_config('train', False):
               with chainer.using_config('enable_backprop', False):
                   feature = model.extract([image])
  
      Args:
          images (iterable of PIL.Image or numpy.ndarray): Input images.
          layers (list of str): The list of layer names you want to extract.
          size (pair of ints): The resolution of resized images used as
              an input of CNN. All the given images are not resized
              if this argument is ``None``, but the resolutions of
              all the images should be the same.
  
      Returns:
          Dictionary of ~chainer.Variable: A directory in which
          the key contains the layer name and the value contains
          the corresponding feature map variable.
  
      """
  
      if layers is None:
          layers = ["pool5"]
  
      if kwargs:
          argument.check_unexpected_kwargs(
              kwargs,
              test="test argument is not supported anymore. "
              "Use chainer.using_config",
              volatile="volatile argument is not supported anymore. "
              "Use chainer.using_config",
          )
          argument.assert_kwargs_empty(kwargs)
  
      x = concat_examples([prepare(img, size=size) for img in images])
      x = Variable(self.xp.asarray(x))
      return self(x, layers=layers)
  
imports: import collections
  import os
  import sys
  import warnings
  import numpy
  import chainer
  from chainer.dataset.convert import concat_examples
  from chainer.dataset import download
  from chainer import function
  from chainer.functions.activation.relu import relu
  from chainer.functions.activation.softmax import softmax
  from chainer.functions.array.reshape import reshape
  from chainer.functions.math.sum import sum
  from chainer.functions.pooling.average_pooling_2d import average_pooling_2d
  from chainer.functions.pooling.max_pooling_nd import max_pooling_2d
  from chainer.initializers import constant
  from chainer.initializers import normal
  from chainer import link
  from chainer.links.connection.convolution_2d import Convolution2D
  from chainer.links.connection.linear import Linear
  from chainer.links.normalization.batch_normalization import BatchNormalization
  from chainer.serializers import npz
  from chainer.utils import argument
  from chainer.utils import imgproc
  from chainer.variable import Variable
label_desc: Use image node_id 6 for calling the ResNetLayers obj's underlying member method code with example usage: obj.extract(images, layers, size) and returns: self