コード例 #1
0
  def testMultiplyInverse(self):
    with tf.Graph().as_default(), self.test_session() as sess:
      tf.set_random_seed(200)
      params = tf.random_normal((3, 3, 8, 2))
      inputs = tf.random_normal((32, 5, 5, 8))
      outputs = tf.random_normal((32, 5, 5, 16))
      layer_collection = lc.LayerCollection()
      block = fb.DepthwiseConvKFCBasicFB(
          layer_collection, params=params, strides=[1, 1, 1, 1], padding='SAME')
      block.register_additional_tower(inputs, outputs)
      grads = outputs**2
      block.instantiate_factors(([grads],), 0.5)
      block._input_factor.instantiate_cov_variables()
      block._output_factor.instantiate_cov_variables()
      block.register_inverse()
      block._input_factor.instantiate_inv_variables()
      block._output_factor.instantiate_inv_variables()

      # Ensure inverse update op doesn't crash.
      sess.run(tf.global_variables_initializer())
      sess.run([
          factor.make_inverse_update_ops()
          for factor in layer_collection.get_factors()
      ])

      # Ensure inverse-vector multiply doesn't crash.
      output = block.multiply_inverse(params)
      sess.run(output)

      # Ensure same shape.
      self.assertAllEqual(output.shape, params.shape)
コード例 #2
0
 def testInstantiateFactors(self):
   with tf.Graph().as_default():
     tf.set_random_seed(200)
     params = tf.random_normal((3, 3, 8, 2))
     inputs = tf.random_normal((32, 5, 5, 8))
     outputs = tf.random_normal((32, 5, 5, 16))
     layer_collection = lc.LayerCollection()
     block = fb.DepthwiseConvKFCBasicFB(
         layer_collection, params=params, strides=[1, 1, 1, 1], padding='SAME')
     block.register_additional_tower(inputs, outputs)
     grads = outputs**2
     block.instantiate_factors(([grads],), 0.5)