Esempio n. 1
0
 def testParseInputSpec(self):
     """The parser must return the numbers in the correct order.
 """
     shape = vgsl_model._ParseInputSpec(input_spec='32,42,256,3')
     self.assertEqual(
         shape,
         vgsl_input.ImageShape(batch_size=32, height=42, width=256,
                               depth=3))
     # Nones must be inserted for zero sizes.
     shape = vgsl_model._ParseInputSpec(input_spec='1,0,0,3')
     self.assertEqual(
         shape,
         vgsl_input.ImageShape(batch_size=1,
                               height=None,
                               width=None,
                               depth=3))
Esempio n. 2
0
def _ParseInputSpec(input_spec):
    """Parses input_spec and returns the numbers obtained therefrom.

  Args:
    input_spec:  Specification of the input layer. See Build.

  Returns:
    shape:      ImageShape with the desired shape of the input.

  Raises:
    ValueError: if syntax is incorrect.
  """
    pattern = re.compile(R'(\d+),(\d+),(\d+),(\d+)')
    m = pattern.match(input_spec)
    if m is None:
        raise ValueError('Failed to parse input spec:' + input_spec)
    batch_size = int(m.group(1))
    y_size = int(m.group(2)) if int(m.group(2)) > 0 else None
    x_size = int(m.group(3)) if int(m.group(3)) > 0 else None
    depth = int(m.group(4))
    if depth not in [1, 3]:
        raise ValueError('Depth must be 1 or 3, had:', depth)
    return vgsl_input.ImageShape(batch_size, y_size, x_size, depth)