コード例 #1
0
ファイル: summaries.py プロジェクト: 1000sprites/tensorflow
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 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 code 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())
コード例 #3
0
 def testPrint(self):
     with self.test_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_print(spec, inputs)
コード例 #4
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testLstm2to0(self):
     with self.test_session():
         inputs = tf.constant(_rand(1, 64, 64, 5))
         spec = "net = Lstm2to0(15)"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [1, 15])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (1, 15))
コード例 #5
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testLstm2to0(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 64, 64, 5))
     spec = "net = Lstm2to0(15)"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [1, 15])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 15))
コード例 #6
0
 def testSummary(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 18, 19, 5))
     spec = "net = Cr(64, [5, 5])"
     outputs = specs.create_net(spec, inputs)
     tf.global_variables_initializer().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
     summaries.tf_spec_summary(spec, inputs)
コード例 #7
0
 def testSummary(self):
     with self.test_session():
         inputs = tf.constant(_rand(1, 18, 19, 5))
         spec = "net = Cr(64, [5, 5])"
         outputs = specs.create_net(spec, inputs)
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
         summaries.tf_spec_summary(spec, inputs)
コード例 #8
0
 def testStructureFromTensor(self):
     with self.test_session():
         inputs = tf.constant(_rand(1, 18, 19, 5))
         spec = "net = Cr(64, [5, 5])"
         outputs = specs.create_net(spec, inputs)
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
         self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                          "_ var conv var biasadd relu")
コード例 #9
0
 def testStructureFromTensor(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 18, 19, 5))
     spec = "net = Cr(64, [5, 5])"
     outputs = specs.create_net(spec, inputs)
     tf.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")
コード例 #10
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testUnary(self):
     # This is just a quick and dirty check that these ops exist
     # and work as unary ops.
     with self.test_session():
         inputs = tf.constant(_rand(17, 55))
         spec = "net = Do(0.5) | Bn | Unit(1) | Relu | Sig | Tanh | Smax"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [17, 55])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (17, 55))
コード例 #11
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testMpPower(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 64, 64, 5))
     spec = "M2 = Mp([2, 2]); net = M2**3"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [1, 8, 8, 5])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 8, 8, 5))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ maxpool maxpool maxpool")
コード例 #12
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testUnary(self):
   # This is just a quick and dirty check that these ops exist
   # and work as unary ops.
   with self.test_session():
     inputs = tf.constant(_rand(17, 55))
     spec = "net = Do(0.5) | Bn | Unit(1) | Relu | Sig | Tanh | Smax"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [17, 55])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (17, 55))
コード例 #13
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testSimpleConv(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 18, 19, 5))
     spec = "net = Cr(64, [5, 5])"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [1, 18, 19, 64])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 18, 19, 64))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ var conv var biasadd relu")
コード例 #14
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testMpPower(self):
     with self.test_session():
         inputs = tf.constant(_rand(1, 64, 64, 5))
         spec = "M2 = Mp([2, 2]); net = M2**3"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [1, 8, 8, 5])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (1, 8, 8, 5))
         self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                          "_ maxpool maxpool maxpool")
コード例 #15
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testImport(self):
   with self.test_session():
     inputs = tf.constant(_rand(10, 20))
     spec = "S = Import('import tensorflow as tf; f = tf.nn.sigmoid')"
     spec += "; net = S | S"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [10, 20])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (10, 20))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ sig sig")
コード例 #16
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testAdd(self):
   with self.test_session():
     inputs = tf.constant(_rand(17, 55))
     spec = "net = Fs(10) + Fr(10)"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [17, 10])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (17, 10))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ var dot var biasadd sig "
                      "<> var dot var biasadd relu add")
コード例 #17
0
 def testStructure(self):
     with self.test_session():
         inputs_shape = (1, 18, 19, 5)
         inputs = constant_op.constant(_rand(*inputs_shape))
         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, input_shape=inputs_shape),
             "_ variablev2 conv variablev2 biasadd relu")
コード例 #18
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testConc(self):
   with self.test_session():
     inputs = tf.constant(_rand(10, 20))
     spec = "net = Conc(1, Fs(20), Fs(10))"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [10, 30])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (10, 30))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ _ var dot var biasadd sig "
                      "<> var dot var biasadd sig concat")
コード例 #19
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testImport(self):
     with self.test_session():
         inputs = tf.constant(_rand(10, 20))
         spec = "S = Import('import tensorflow as tf; f = tf.nn.sigmoid')"
         spec += "; net = S | S"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [10, 20])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (10, 20))
         self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                          "_ sig sig")
コード例 #20
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testAdd(self):
     with self.test_session():
         inputs = tf.constant(_rand(17, 55))
         spec = "net = Fs(10) + Fr(10)"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [17, 10])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (17, 10))
         self.assertEqual(
             summaries.tf_spec_structure(spec, inputs),
             "_ var dot var biasadd sig "
             "<> var dot var biasadd relu add")
コード例 #21
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testAbbrevPower(self):
   with self.test_session():
     inputs = tf.constant(_rand(1, 64, 64, 5))
     spec = "C3 = Cr([3, 3]); M2 = Mp([2, 2]); net = (C3(5) | M2)**3"
     outputs = specs.create_net(spec, inputs)
     self.assertEqual(outputs.get_shape().as_list(), [1, 8, 8, 5])
     tf.initialize_all_variables().run()
     result = outputs.eval()
     self.assertEqual(tuple(result.shape), (1, 8, 8, 5))
     self.assertEqual(summaries.tf_spec_structure(spec, inputs),
                      "_ var conv var biasadd relu maxpool var conv var"
                      " biasadd relu maxpool var conv var"
                      " biasadd relu maxpool")
コード例 #22
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testConc(self):
     with self.test_session():
         inputs = tf.constant(_rand(10, 20))
         spec = "net = Conc(1, Fs(20), Fs(10))"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [10, 30])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (10, 30))
         self.assertEqual(
             summaries.tf_spec_structure(spec, inputs),
             "_ _ var dot var biasadd sig "
             "<> var dot var biasadd sig concat")
コード例 #23
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testAbbrevPower(self):
     with self.test_session():
         inputs = tf.constant(_rand(1, 64, 64, 5))
         spec = "C3 = Cr([3, 3]); M2 = Mp([2, 2]); net = (C3(5) | M2)**3"
         outputs = specs.create_net(spec, inputs)
         self.assertEqual(outputs.get_shape().as_list(), [1, 8, 8, 5])
         tf.initialize_all_variables().run()
         result = outputs.eval()
         self.assertEqual(tuple(result.shape), (1, 8, 8, 5))
         self.assertEqual(
             summaries.tf_spec_structure(spec, inputs),
             "_ var conv var biasadd relu maxpool var conv var"
             " biasadd relu maxpool var conv var"
             " biasadd relu maxpool")
コード例 #24
0
ファイル: summaries.py プロジェクト: PaullMP/TensorFlowT
def tf_spec_print(spec, inputs=None, input_shape=None, input_type=tf.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 = tf.placeholder(input_type, input_shape)
  outputs = specs.create_net(spec, inputs)
  tf_print(outputs)
コード例 #25
0
ファイル: summaries.py プロジェクト: PaullMP/TensorFlowT
def tf_spec_summary(spec, inputs=None, input_shape=None, input_type=tf.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 = tf.placeholder(input_type, input_shape)
  outputs = specs.create_net(spec, inputs)
  tf_parameter_summary(outputs)
コード例 #26
0
ファイル: specs_test.py プロジェクト: KalraA/tensorflow
 def testKeywordRestriction(self):
   with self.test_session():
     inputs = tf.constant(_rand(10, 20))
     spec = "import re; net = Conc(1, Fs(20), Fs(10))"
     self.assertRaises(ValueError, lambda: specs.create_net(spec, inputs))
コード例 #27
0
ファイル: specs_test.py プロジェクト: PaullMP/TensorFlowT
 def testKeywordRestriction(self):
     with self.test_session():
         inputs = tf.constant(_rand(10, 20))
         spec = "import re; net = Conc(1, Fs(20), Fs(10))"
         self.assertRaises(ValueError,
                           lambda: specs.create_net(spec, inputs))