def testWeightSpecificSparsity(self):
    param_list = ['begin_pruning_step=1', 'pruning_frequency=1', 'end_pruning_step=100', 'target_sparsity=0.5', 'weight_sparsity_map=[layer1:0.6,layer2/weights:0.75,.*kernel:0.6]', 'threshold_decay=0.0']
    test_spec = ','.join(param_list)
    pruning_hparams = pruning.get_pruning_hparams().parse(test_spec)
    with variable_scope.variable_scope('layer1'):
        w1 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='weights')
        _ = pruning.apply_mask(w1)
    with variable_scope.variable_scope('layer2'):
        w2 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='weights')
        _ = pruning.apply_mask(w2)
    with variable_scope.variable_scope('layer3'):
        w3 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='kernel')
        _ = pruning.apply_mask(w3)
    p = pruning.Pruning(pruning_hparams)
    mask_update_op = p.conditional_mask_update_op()
    increment_global_step = state_ops.assign_add(self.global_step, 1)
    with self.cached_session() as session:
        variables.global_variables_initializer().run()
        for _ in range(110):
            session.run(mask_update_op)
            session.run(increment_global_step)
        self.assertAllClose(session.run(pruning.get_weight_sparsity()), [0.6, 0.75, 0.6])
def testWeightSpecificSparsity(self):
    param_list = ['begin_pruning_step=1', 'pruning_frequency=1', 'end_pruning_step=100', 'target_sparsity=0.5', 'weight_sparsity_map=[layer1:0.6,layer2/weights:0.75,.*kernel:0.6]', 'threshold_decay=0.0']
    test_spec = ','.join(param_list)
    pruning_hparams = pruning.get_pruning_hparams().parse(test_spec)
    with variable_scope.variable_scope('layer1'):
        w1 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='weights')
        _ = pruning.apply_mask(w1)
    with variable_scope.variable_scope('layer2'):
        w2 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='weights')
        _ = pruning.apply_mask(w2)
    with variable_scope.variable_scope('layer3'):
        w3 = variables.VariableV1(math_ops.linspace(1.0, 100.0, 100), name='kernel')
        _ = pruning.apply_mask(w3)
    p = pruning.Pruning(pruning_hparams)
    mask_update_op = p.conditional_mask_update_op()
    increment_global_step = state_ops.assign_add(self.global_step, 1)
    with self.cached_session() as session:
        variables.global_variables_initializer().run()
        for _ in range(110):
            session.run(mask_update_op)
            session.run(increment_global_step)
        self.assertAllClose(session.run(pruning.get_weight_sparsity()), [0.6, 0.75, 0.6])