Example #1
0
def test_parameter_update():
    original_param_values = {}
    original_bn_stat_values = {}

    model = get_model_for_test()

    for layer in model.layers:
        if get_keras_layer_metatype(
                layer) == TFBatchNormalizationLayerMetatype:
            original_bn_stat_values[layer] = deepcopy(
                layer.non_trainable_weights)
            original_param_values[layer] = deepcopy(layer.trainable_weights)
        else:
            original_param_values[layer] = deepcopy(layer.weights)

    config = get_config_for_test()

    bn_adaptation = BatchnormAdaptationAlgorithm(
        **extract_bn_adaptation_init_params(config, "quantization"))
    bn_adaptation.run(model)

    for layer in model.layers:
        if get_keras_layer_metatype(
                layer) == TFBatchNormalizationLayerMetatype:
            compare_params(original_bn_stat_values[layer],
                           layer.non_trainable_weights,
                           equal=False)
            compare_params(original_param_values[layer],
                           layer.trainable_weights)
        else:
            compare_params(original_param_values[layer], layer.weights)
Example #2
0
def test_all_parameter_keep():
    original_all_param_values = {}

    model = get_model_for_test()

    for layer in model.layers:
        original_all_param_values[layer] = deepcopy(layer.weights)

    config = get_config_for_test(num_bn_adaptation_samples=0)

    bn_adaptation = BatchnormAdaptationAlgorithm(
        **extract_bn_adaptation_init_params(config, "quantization"))
    bn_adaptation.run(model)

    for layer in model.layers:
        compare_params(original_all_param_values[layer], layer.weights)
Example #3
0
 def _run_batchnorm_adaptation(self):
     if self._bn_adaptation is None:
         self._bn_adaptation = BatchnormAdaptationAlgorithm(
             **extract_bn_adaptation_init_params(self._config,
                                                 'magnitude_sparsity'))
     self._bn_adaptation.run(self.model)
Example #4
0
 def _run_batchnorm_adaptation(self, model: tf.keras.Model) -> None:
     if self._bn_adaptation is None:
         self._bn_adaptation = BatchnormAdaptationAlgorithm(
             **extract_bn_adaptation_init_params(self.config, self.name))
     self._bn_adaptation.run(model)
Example #5
0
 def _run_batchnorm_adaptation(self):
     if self._bn_adaptation is None:
         self._bn_adaptation = BatchnormAdaptationAlgorithm(
             **extract_bn_adaptation_init_params(self.config,
                                                 'filter_pruning'))
     self._bn_adaptation.run(self.model)
Example #6
0
 def _run_batchnorm_adaptation(self):
     if self._bn_adaptation is None:
         self._bn_adaptation = BatchnormAdaptationAlgorithm(
             **extract_bn_adaptation_init_params(self.qctrl.config,
                                                 "quantization"))
     self._bn_adaptation.run(self.qctrl.model)