コード例 #1
0
 def testCreateConvWithoutWD(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     ops.conv2d(images, 32, [3, 3], weight_decay=0)
     self.assertEquals(
         tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES), [])
コード例 #2
0
 def testNonReuseVars(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     ops.conv2d(images, 32, [3, 3])
     self.assertEquals(len(variables.get_variables()), 2)
     ops.conv2d(images, 32, [3, 3])
     self.assertEquals(len(variables.get_variables()), 4)
コード例 #3
0
 def testCreateConvCreatesWeightsAndBiasesVars(self):
   height, width = 3, 3
   images = tf.random_uniform((5, height, width, 3), seed=1)
   with self.test_session():
     self.assertFalse(variables.get_variables('conv1/weights'))
     self.assertFalse(variables.get_variables('conv1/biases'))
     ops.conv2d(images, 32, [3, 3], scope='conv1')
     self.assertTrue(variables.get_variables('conv1/weights'))
     self.assertTrue(variables.get_variables('conv1/biases'))
コード例 #4
0
 def testReuseConvWithBatchNorm(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 32), seed=1)
     with scopes.arg_scope([ops.conv2d], batch_norm_params={'decay': 0.9}):
       net = ops.conv2d(images, 32, [3, 3], scope='Conv')
       net = ops.conv2d(net, 32, [3, 3], scope='Conv', reuse=True)
     self.assertEquals(len(variables.get_variables()), 4)
     self.assertEquals(len(variables.get_variables('Conv/BatchNorm')), 3)
     self.assertEquals(len(variables.get_variables('Conv_1/BatchNorm')), 0)
コード例 #5
0
 def testCreateConvWithWD(self):
   height, width = 3, 3
   with self.test_session() as sess:
     images = tf.random_uniform((5, height, width, 3), seed=1)
     ops.conv2d(images, 32, [3, 3], weight_decay=0.01)
     wd = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)[0]
     self.assertEquals(wd.op.name,
                       'Conv/weights/Regularizer/L2Regularizer/value')
     sess.run(tf.global_variables_initializer())
     self.assertTrue(sess.run(wd) <= 0.01)
コード例 #6
0
 def testReuseConvWithWD(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     ops.conv2d(images, 32, [3, 3], weight_decay=0.01, scope='conv1')
     self.assertEquals(len(variables.get_variables()), 2)
     self.assertEquals(
         len(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)), 1)
     ops.conv2d(images, 32, [3, 3], weight_decay=0.01, scope='conv1',
                reuse=True)
     self.assertEquals(len(variables.get_variables()), 2)
     self.assertEquals(
         len(tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)), 1)
コード例 #7
0
 def testCreateFullyConv(self):
   height, width = 6, 6
   with self.test_session():
     images = tf.random_uniform((5, height, width, 32), seed=1)
     output = ops.conv2d(images, 64, images.get_shape()[1:3], padding='VALID')
     self.assertEquals(output.op.name, 'Conv/Relu')
     self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 64])
コード例 #8
0
 def testCreateConvWithTensorShape(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     output = ops.conv2d(images, 32, images.get_shape()[1:3])
     self.assertEquals(output.op.name, 'Conv/Relu')
     self.assertListEqual(output.get_shape().as_list(), [5, height, width, 32])
コード例 #9
0
 def testCreateConvWithStride(self):
   height, width = 6, 6
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     output = ops.conv2d(images, 32, [3, 3], stride=2)
     self.assertEquals(output.op.name, 'Conv/Relu')
     self.assertListEqual(output.get_shape().as_list(),
                          [5, height/2, width/2, 32])
コード例 #10
0
 def testCreateConvWithScope(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     output = ops.conv2d(images, 32, [3, 3], scope='conv1')
     self.assertEquals(output.op.name, 'conv1/Relu')
コード例 #11
0
 def testCreateConvValid(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     output = ops.conv2d(images, 32, [3, 3], padding='VALID')
     self.assertListEqual(output.get_shape().as_list(), [5, 1, 1, 32])
コード例 #12
0
 def testCreateConvWithoutActivation(self):
   height, width = 3, 3
   with self.test_session():
     images = tf.random_uniform((5, height, width, 3), seed=1)
     output = ops.conv2d(images, 32, [3, 3], activation=None)
     self.assertEquals(output.op.name, 'Conv/BiasAdd')