code: def testQuantizesWeights_KerasLayers(
      self, layer_type, input_shape, kwargs
  ):
      self.weights = None
  
      def _get_random_weights(
          shape, dtype
      ):  # pylint: disable=unused-argument
          self.weights = np.random.rand(*shape)
          return self.weights
  
      def _get_quantized_weights(
          shape, dtype
      ):  # pylint: disable=unused-argument
          assert tuple(shape) == self.weights.shape
  
          # Default values used in DefaultRegistry.
          return tf.quantization.fake_quant_with_min_max_vars(
              self.weights, -6.0, 6.0, num_bits=8, narrow_range=True
          )
  
      layer = layer_type(
          kernel_initializer=_get_random_weights, **kwargs
      )
      quantized_model = keras.Sequential(
          [
              QuantizeWrapper(
                  layer=layer,
                  quantize_config=self.quantize_registry.get_quantize_config(
                      layer
                  ),
                  input_shape=input_shape,
              )
          ]
      )
      # `model` gets constructed with same parameters as `quantized_model`. The
      # weights used are a quantized version of weights used in `quantized_model`.
      # This ensures the results of both the models should be the same since
      # quantization has been applied externally to `model`.
      model = keras.Sequential(
          [
              layer_type(
                  input_shape=input_shape,
                  kernel_initializer=_get_quantized_weights,
                  **kwargs,
              )
          ]
      )
  
      inputs = np.random.rand(1, *input_shape)
      # `quantized_model` should apply FakeQuant. Explicitly applying to the
      # results of `model` to verify QuantizeWrapper works as expected.
      expected_output = tf.quantization.fake_quant_with_min_max_vars(
          model.predict(inputs),
          -6.0,
          6.0,
          num_bits=8,
          narrow_range=False,
      )
      self.assertAllClose(
          expected_output, quantized_model.predict(inputs)
      )
  
file_path: model-optimization/tensorflow_model_optimization/python/core/quantization/keras/quantize_wrapper_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.quantization.keras import quantize_aware_activation
  from tensorflow_model_optimization.python.core.quantization.keras import quantize_wrapper
  from tensorflow_model_optimization.python.core.quantization.keras.default_8bit import default_8bit_quantize_registry
label_desc: Use image node_id 3 for calling the QuantizeWrapperTest obj's underlying member method code with example usage: obj.testQuantizesWeights_KerasLayers(layer_type, input_shape, kwargs) and returns: self, tf