示例#1
0
 def testCreateFCWithoutWD(self):
   height, width = 3, 3
   with self.test_session():
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     ops.fc(inputs, 32, weight_decay=0)
     self.assertEquals(
         tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES), [])
示例#2
0
 def testNonReuseVars(self):
   height, width = 3, 3
   inputs = tf.random_uniform((5, height * width * 3), seed=1)
   with self.test_session():
     ops.fc(inputs, 32)
     self.assertEquals(len(variables.get_variables('FC')), 2)
     ops.fc(inputs, 32)
     self.assertEquals(len(variables.get_variables('FC')), 4)
示例#3
0
 def testReuseVars(self):
   height, width = 3, 3
   inputs = tf.random_uniform((5, height * width * 3), seed=1)
   with self.test_session():
     ops.fc(inputs, 32, scope='fc1')
     self.assertEquals(len(variables.get_variables('fc1')), 2)
     ops.fc(inputs, 32, scope='fc1', reuse=True)
     self.assertEquals(len(variables.get_variables('fc1')), 2)
示例#4
0
 def testReuseFCWithBatchNorm(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height * width * 3), seed=1)
     with scopes.arg_scope([ops.fc], batch_norm_params={'decay': 0.9}):
       net = ops.fc(images, 27, scope='fc1')
       net = ops.fc(net, 27, scope='fc1', reuse=True)
     self.assertEquals(len(variables.get_variables()), 4)
     self.assertEquals(len(variables.get_variables('fc1/BatchNorm')), 3)
示例#5
0
 def testCreateFcCreatesWeightsAndBiasesVars(self):
   height, width = 3, 3
   inputs = tf.random_uniform((5, height * width * 3), seed=1)
   with self.test_session():
     self.assertFalse(variables.get_variables('fc1/weights'))
     self.assertFalse(variables.get_variables('fc1/biases'))
     ops.fc(inputs, 32, scope='fc1')
     self.assertTrue(variables.get_variables('fc1/weights'))
     self.assertTrue(variables.get_variables('fc1/biases'))
示例#6
0
 def testFCWithBatchNorm(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height * width * 3), seed=1)
     with scopes.arg_scope([ops.fc], batch_norm_params={}):
       net = ops.fc(images, 27)
       net = ops.fc(net, 27)
     self.assertEquals(len(variables.get_variables()), 8)
     self.assertEquals(len(variables.get_variables('FC/BatchNorm')), 3)
     self.assertEquals(len(variables.get_variables('FC_1/BatchNorm')), 3)
示例#7
0
 def testCreateFCWithWD(self):
   height, width = 3, 3
   with self.test_session() as sess:
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     ops.fc(inputs, 32, weight_decay=0.01)
     wd = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)[0]
     self.assertEquals(wd.op.name,
                       'FC/weights/Regularizer/L2Regularizer/value')
     sess.run(tf.global_variables_initializer())
     self.assertTrue(sess.run(wd) <= 0.01)
示例#8
0
 def testReuseFCWithWD(self):
   height, width = 3, 3
   with self.test_session():
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     ops.fc(inputs, 32, weight_decay=0.01, scope='fc')
     self.assertEquals(len(variables.get_variables()), 2)
     self.assertEquals(
         len(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)), 1)
     ops.fc(inputs, 32, weight_decay=0.01, scope='fc', reuse=True)
     self.assertEquals(len(variables.get_variables()), 2)
     self.assertEquals(
         len(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)), 1)
示例#9
0
 def testCreateFC(self):
   height, width = 3, 3
   with self.test_session():
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     output = ops.fc(inputs, 32)
     self.assertEquals(output.op.name, 'FC/Relu')
     self.assertListEqual(output.get_shape().as_list(), [5, 32])
示例#10
0
 def testCreateFCWithoutActivation(self):
   height, width = 3, 3
   with self.test_session():
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     output = ops.fc(inputs, 32, activation=None)
     self.assertEquals(output.op.name, 'FC/xw_plus_b')
示例#11
0
 def testCreateFCWithScope(self):
   height, width = 3, 3
   with self.test_session():
     inputs = tf.random_uniform((5, height * width * 3), seed=1)
     output = ops.fc(inputs, 32, scope='fc1')
     self.assertEquals(output.op.name, 'fc1/Relu')