Get Resource Utilization information for Keras Models¶
- model_compression_toolkit.core.keras_resource_utilization_data(in_model, representative_data_gen, core_config=CoreConfig(mixed_precision_config=MixedPrecisionQuantizationConfig()), target_platform_capabilities=KERAS_DEFAULT_TPC)¶
Computes resource utilization data that can be used to calculate the desired target resource utilization for mixed-precision quantization. Builds the computation graph from the given model and hw modeling, and uses it to compute the resource utilization data.
- Parameters:
in_model (Model) – Keras model to quantize.
representative_data_gen (Callable) – Dataset used for calibration.
core_config (CoreConfig) – CoreConfig containing parameters for quantization and mixed precision of how the model should be quantized.
target_platform_capabilities (TargetPlatformCapabilities) – TargetPlatformCapabilities to optimize the Keras model according to.
- Returns:
A ResourceUtilization object with total weights parameters sum and max activation tensor.
Examples
Import a Keras model:
>>> from tensorflow.keras.applications.mobilenet import MobileNet >>> model = MobileNet()
Create a random dataset generator:
>>> import numpy as np >>> def repr_datagen(): yield [np.random.random((1, 224, 224, 3))]
Import MCT and call for resource utilization data calculation:
>>> import model_compression_toolkit as mct >>> ru_data = mct.core.keras_resource_utilization_data(model, repr_datagen)
- Return type: