コード例 #1
0
    def testMultiplyInverse(self):
        with ops.Graph().as_default(), self.test_session() as sess:
            random_seed.set_random_seed(200)
            params = random_ops.random_normal((3, 3, 8, 2))
            inputs = random_ops.random_normal((32, 5, 5, 8))
            outputs = random_ops.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_variables.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 ops.Graph().as_default():
         random_seed.set_random_seed(200)
         params = random_ops.random_normal((3, 3, 8, 2))
         inputs = random_ops.random_normal((32, 5, 5, 8))
         outputs = random_ops.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)