Ecto-Trigger 1.0
Loading...
Searching...
No Matches
ModelQuantiser Class Reference

Public Member Functions

 __init__ (self, weights_file, representative_dataset, representative_example_nr)
 
 quantise_model (self, output_path)
 

Public Attributes

 weights_file = weights_file
 
 representative_dataset = representative_dataset
 
 representative_example_nr = representative_example_nr
 
 model = self._load_model()
 
 input_shape = self.model.input_shape[1:]
 
 data_generator
 

Protected Member Functions

 _load_model (self)
 
 _test_quantised_model (self, tflite_quant_model)
 

Detailed Description

A class to handle the quantization of a Keras model to TFLite with INT8 precision.

Attributes:
    model (tf.keras.Model): The model to be quantised.
    representative_dataset (str): Path to the representative dataset for quantization.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
weights_file,
representative_dataset,
representative_example_nr )
Initialize the ModelQuantiser.

Args:
    weights_file (str): Path to the Keras model weights file.
    representative_dataset (str): Directory containing the representative dataset.

Member Function Documentation

◆ _load_model()

_load_model ( self)
protected
Load the Keras model from the weights file.

Returns:
    tf.keras.Model: Loaded model.

◆ _test_quantised_model()

_test_quantised_model ( self,
tflite_quant_model )
protected
Test the quantised TFLite model by loading it into a TFLite interpreter.

Args:
    tflite_quant_model (bytes): The quantised TFLite model.

◆ quantise_model()

quantise_model ( self,
output_path )
Quantise the model to TFLite format with INT8 precision.

Args:
    output_path (str): Path to save the quantised TFLite model.

Member Data Documentation

◆ data_generator

data_generator
Initial value:
= CustomDataGenerator(
data_directory=[self.representative_dataset],
batch_size=1,
input_shape=self.input_shape,
stop_training_flag=False,
shuffle=True
)

◆ input_shape

input_shape = self.model.input_shape[1:]

◆ model

model = self._load_model()

◆ representative_dataset

representative_dataset = representative_dataset

◆ representative_example_nr

representative_example_nr = representative_example_nr

◆ weights_file

weights_file = weights_file

The documentation for this class was generated from the following file: