예제 #1
0
def tf_spec_structure(spec,
                      inputs=None,
                      input_shape=None,
                      input_type=dtypes.float32):
    """Return a postfix representation of the specification.

  This is intended to be used as part of test cases to
  check for gross differences in the structure of the graph.
  The resulting string is not invertible or unabiguous
  and cannot be used to reconstruct the graph accurately.

  Args:
      spec: specification
      inputs: input to the spec construction (usually a Tensor)
      input_shape: tensor shape (in lieu of inputs)
      input_type: type of the input tensor

  Returns:
      A string with a postfix representation of the
      specification.
  """

    if inputs is None:
        inputs = array_ops.placeholder(input_type, input_shape)
    outputs = specs.create_net(spec, inputs)
    return str(tf_structure(outputs).strip())
예제 #2
0
 def testSummary(self):
   with self.cached_session():
     inputs = constant_op.constant(_rand(1, 18, 19, 5))
     spec = "net = Cr(64, [5, 5])"
     outputs = specs.create_net(spec, inputs)
     variables.global_variables_initializer().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
     summaries.tf_spec_summary(spec, inputs)
예제 #3
0
 def testStructureFromTensor(self):
   with self.cached_session():
     inputs = constant_op.constant(_rand(1, 18, 19, 5))
     spec = "net = Cr(64, [5, 5])"
     outputs = specs.create_net(spec, inputs)
     variables.global_variables_initializer().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
     self.assertEqual(
         summaries.tf_spec_structure(spec, inputs),
         "_ variablev2 conv variablev2 biasadd relu")
예제 #4
0
def tf_spec_print(spec,
                  inputs=None,
                  input_shape=None,
                  input_type=dtypes.float32):
    """Print a tree representing the spec.

  Args:
      spec: specification
      inputs: input to the spec construction (usually a Tensor)
      input_shape: optional shape of input
      input_type: type of the input tensor
  """

    if inputs is None:
        inputs = array_ops.placeholder(input_type, input_shape)
    outputs = specs.create_net(spec, inputs)
    tf_print(outputs)
예제 #5
0
def tf_spec_summary(spec,
                    inputs=None,
                    input_shape=None,
                    input_type=dtypes.float32):
    """Output a summary of the specification.

  This prints a list of left-most tensor operations and summarized the
  variables found in the right branches. This kind of representation
  is particularly useful for networks that are generally structured
  like pipelines.

  Args:
      spec: specification
      inputs: input to the spec construction (usually a Tensor)
      input_shape: optional shape of input
      input_type: type of the input tensor
  """

    if inputs is None:
        inputs = array_ops.placeholder(input_type, input_shape)
    outputs = specs.create_net(spec, inputs)
    tf_parameter_summary(outputs)