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")
def testMpPower(self): with self.cached_session(): inputs = constant_op.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]) variables.global_variables_initializer().run() result = outputs.eval() self.assertEqual(tuple(result.shape), (1, 8, 8, 5)) self.assertEqual(summaries.tf_spec_structure(spec, inputs), "_ maxpool maxpool maxpool")
def testAdd(self): with self.cached_session(): inputs = constant_op.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]) variables.global_variables_initializer().run() result = outputs.eval() self.assertEqual(tuple(result.shape), (17, 10)) self.assertRegexpMatches( summaries.tf_spec_structure(spec, inputs), "_ variablev2 dot variablev2 biasadd sig " "<> variablev2 dot variablev2 biasadd relu add(v2)?")
def testImport(self): with self.cached_session(): inputs = constant_op.constant(_rand(10, 20)) spec = ("S = Import('from tensorflow.python.ops" + " import math_ops; f = math_ops.sigmoid')") spec += "; net = S | S" outputs = specs.create_net(spec, inputs) self.assertEqual(outputs.get_shape().as_list(), [10, 20]) variables.global_variables_initializer().run() result = outputs.eval() self.assertEqual(tuple(result.shape), (10, 20)) self.assertEqual(summaries.tf_spec_structure(spec, inputs), "_ sig sig")
def testConc(self): with self.cached_session(): inputs = constant_op.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]) variables.global_variables_initializer().run() result = outputs.eval() self.assertEqual(tuple(result.shape), (10, 30)) self.assertEqual( summaries.tf_spec_structure(spec, inputs), "_ variablev2 dot variablev2 biasadd sig " "<> variablev2 dot variablev2 biasadd sig _ concatv2")
def testAbbrevPower(self): with self.cached_session(): inputs = constant_op.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]) variables.global_variables_initializer().run() result = outputs.eval() self.assertEqual(tuple(result.shape), (1, 8, 8, 5)) self.assertEqual( summaries.tf_spec_structure(spec, inputs), "_ variablev2 conv variablev2 biasadd relu maxpool" " variablev2 conv variablev2" " biasadd relu maxpool variablev2 conv variablev2" " biasadd relu maxpool")