class_docstr: A helper class to encode/decode bounding boxes.
  
  This class encodes :obj:`(bbox, label)` to :obj:`(mb_loc, mb_label)`
  and decodes :obj:`(mb_loc, mb_conf)` to :obj:`(bbox, label, score)`.
  These encoding/decoding are used in Single Shot Multibox Detector [#]_.
  
  * :obj:`mb_loc`: An array representing offsets and scales          from the default bounding boxes.          Its shape is :math:`(K, 4)`, where :math:`K` is the number of          the default bounding boxes.          The second axis is composed by          :math:`(\Delta y, \Delta x, \Delta h, \Delta w)`.          These values are computed by the following formulas.
  
       * :math:`\Delta y = (b_y - m_y) / (m_h * v_0)`
       * :math:`\Delta x = (b_x - m_x) / (m_w * v_0)`
       * :math:`\Delta h = log(b_h / m_h) / v_1`
       * :math:`\Delta w = log(b_w / m_w) / v_1`
  
       :math:`(m_y, m_x)` and :math:`(m_h, m_w)` are          center coodinates and size of a default bounding box.          :math:`(b_y, b_x)` and :math:`(b_h, b_w)` are          center coodinates and size of          a given bounding boxes that is assined to the default bounding box.          :math:`(v_0, v_1)` are coefficients that can be set          by argument :obj:`variance`.
  * :obj:`mb_label`: An array representing classes of          ground truth bounding boxes. Its shape is :math:`(K,)`.
  * :obj:`mb_conf`: An array representing classes of          predicted bounding boxes. Its shape is :math:`(K, n\_fg\_class + 1)`.
  
  .. [#] Wei Liu, Dragomir Anguelov, Dumitru Erhan, Christian Szegedy,
     Scott Reed, Cheng-Yang Fu, Alexander C. Berg.
     SSD: Single Shot MultiBox Detector. ECCV 2016.
  
  Args:
      grids (iterable of ints): An iterable of integers.
          Each integer indicates the size of a feature map.
      aspect_ratios (iterable of tuples of ints):
          An iterable of tuples of integers
          used to compute the default bounding boxes.
          Each tuple indicates the aspect ratios of
          the default bounding boxes at each feature maps.
          The length of this iterable should be :obj:`len(grids)`.
      steps (iterable of floats): The step size for each feature map.
          The length of this iterable should be :obj:`len(grids)`.
      sizes (iterable of floats): The base size of default bounding boxes
          for each feature map.
          The length of this iterable should be :obj:`len(grids) + 1`.
      variance (tuple of floats): Two coefficients for encoding/decoding
          the locations of bounding boxes. The first value is used to
          encode/decode coordinates of the centers.
          The second value is used to encode/decode the sizes of
          bounding boxes.
class_docstr_tok: ["A","helper","class","to","encode\/decode","bounding","boxes",".","This","class","encodes",":","obj",":","`","(","bbox",",","label",")","`","to",":","obj",":","`","(","mb_loc",",","mb_label",")","`","and","decodes",":","obj",":","`","(","mb_loc",",","mb_conf",")","`","to",":","obj",":","`","(","bbox",",","label",",","score",")","`",".","These","encoding\/decoding","are","used","in","Single","Shot","Multibox","Detector","[","#","]","_",".","*",":","obj",":","`","mb_loc","`",":","An","array","representing","offsets","and","scales","from","the","default","bounding","boxes",".","Its","shape","is",":","math",":","`","(","K",",","4",")","`",",","where",":","math",":","`","K","`","is","the","number","of","the","default","bounding","boxes",".","The","second","axis","is","composed","by",":","math",":","`","(","\\Delta","y",",","\\Delta","x",",","\\Delta","h",",","\\Delta","w",")","`",".","These","values","are","computed","by","the","following","formulas",".","*",":","math",":","`","\\Delta","y","=","(","b_y","-","m_y",")","\/","(","m_h","*","v_0",")","`","*",":","math",":","`","\\Delta","x","=","(","b_x","-","m_x",")","\/","(","m_w","*","v_0",")","`","*",":","math",":","`","\\Delta","h","=","log","(","b_h","\/","m_h",")","\/","v_1","`","*",":","math",":","`","\\Delta","w","=","log","(","b_w","\/","m_w",")","\/","v_1","`",":","math",":","`","(","m_y",",","m_x",")","`","and",":","math",":","`","(","m_h",",","m_w",")","`","are","center","coodinates","and","size","of","a","default","bounding","box",".",":","math",":","`","(","b_y",",","b_x",")","`","and",":","math",":","`","(","b_h",",","b_w",")","`","are","center","coodinates","and","size","of","a","given","bounding","boxes","that","is","assined","to","the","default","bounding","box",".",":","math",":","`","(","v_0",",","v_1",")","`","are","coefficients","that","can","be","set","by","argument",":","obj",":","`","variance","`",".","*",":","obj",":","`","mb_label","`",":","An","array","representing","classes","of","ground","truth","bounding","boxes",".","Its","shape","is",":","math",":","`","(","K",",",")","`",".","*",":","obj",":","`","mb_conf","`",":","An","array","representing","classes","of","predicted","bounding","boxes",".","Its","shape","is",":","math",":","`","(","K",",","n\\_fg\\_class","+","1",")","`",".","..","[","#","]","Wei","Liu",",","Dragomir","Anguelov",",","Dumitru","Erhan",",","Christian","Szegedy",",","Scott","Reed",",","Cheng-Yang","Fu",",","Alexander","C.","Berg",".","SSD",":","Single","Shot","MultiBox","Detector",".","ECCV","2016",".","Args",":","grids","(","iterable","of","ints",")",":","An","iterable","of","integers",".","Each","integer","indicates","the","size","of","a","feature","map",".","aspect_ratios","(","iterable","of","tuples","of","ints",")",":","An","iterable","of","tuples","of","integers","used","to","compute","the","default","bounding","boxes",".","Each","tuple","indicates","the","aspect","ratios","of","the","default","bounding","boxes","at","each","feature","maps",".","The","length","of","this","iterable","should","be",":","obj",":","`","len","(","grids",")","`",".","steps","(","iterable","of","floats",")",":","The","step","size","for","each","feature","map",".","The","length","of","this","iterable","should","be",":","obj",":","`","len","(","grids",")","`",".","sizes","(","iterable","of","floats",")",":","The","base","size","of","default","bounding","boxes","for","each","feature","map",".","The","length","of","this","iterable","should","be",":","obj",":","`","len","(","grids",")","+","1","`",".","variance","(","tuple","of","floats",")",":","Two","coefficients","for","encoding\/decoding","the","locations","of","bounding","boxes",".","The","first","value","is","used","to","encode\/decode","coordinates","of","the","centers",".","The","second","value","is","used","to","encode\/decode","the","sizes","of","bounding","boxes","."]
code: def __init__(self, grids, aspect_ratios, steps, sizes, variance):
      if not len(aspect_ratios) == len(grids):
          raise ValueError("The length of aspect_ratios is wrong.")
      if not len(steps) == len(grids):
          raise ValueError("The length of steps is wrong.")
      if not len(sizes) == len(grids) + 1:
          raise ValueError("The length of sizes is wrong.")
  
      default_bbox = []
  
      for k, grid in enumerate(grids):
          for v, u in itertools.product(range(grid), repeat=2):
              cy = (v + 0.5) * steps[k]
              cx = (u + 0.5) * steps[k]
  
              s = sizes[k]
              default_bbox.append((cy, cx, s, s))
  
              s = np.sqrt(sizes[k] * sizes[k + 1])
              default_bbox.append((cy, cx, s, s))
  
              s = sizes[k]
              for ar in aspect_ratios[k]:
                  default_bbox.append(
                      (cy, cx, s / np.sqrt(ar), s * np.sqrt(ar))
                  )
                  default_bbox.append(
                      (cy, cx, s * np.sqrt(ar), s / np.sqrt(ar))
                  )
  
      # (center_y, center_x, height, width)
      self._default_bbox = np.stack(default_bbox)
      self._variance = variance
  
file_path: chainercv/chainercv/links/model/ssd/multibox_coder.py
imports: from __future__ import division
  import itertools
  import numpy
  import chainer
  from chainercv import utils
label_desc: Use image node_id 1 to create a new MultiboxCoder object from inherited base classes: object with example: obj = MultiboxCoder(grids, aspect_ratios, steps, sizes, variance)