This describes how to summarize an ML model using the MLTK's commands/APIs.
_Any_ `.tflite` or `.h5` model file will work with the model summary generation.
i.e. The model file does _not_ need to be generated by the MLTK to generate a summary of it.
- Command-line: mltk summarize --help
- Python API: summarize_model
- Python API examples: summarize_model.ipynb
The MLTK's model summary feature generates a text summary of a model containing some or all of the following information:
- Model layout including each layer's name/type/output shape
- Number of trainable parameters
- Number of multiply-accumulate (MAC) operations
- Number of operations
- Any additional model parameters
Two types of model summaries may be generated:
- Keras Model - This provides a summary of the exact model used for training, file extension:
.h5
- Tensorflow-Lite Model - This provides a summary of the converted, quantized model that can execute on an embedded device, file extension:
.tflite
(see Model Quantization)
Both these models have similar model layouts, however, the Tensorflow-Lite model is slightly modified to optimize it for embedded execution.
The Keras Model summary is generated by KerasModel.summary() API,
while the Tensorflow-Lite Model is generated by the TfliteModel.summary() API.
By default, the summarize
command or summarize_model API will generate a summary of the trained .h5
model in the model archive file.
Specify the --tflite
option to summarize the trained .tflite
model in model archive file.
Alternatively, provide the --build
option to summarize the model without training first.
Alternatively, provide the path to a .tflite
or .h5
model file to summarize a non-MLTK generated model file.
Model summarization from the command-line is done using the summarize
operation.
For more details on the available command-line options, issue the command:
mltk summarize --help
In this example, we generate a summary of the trained .h5
model file in the
image_classification model's model archive.
mltk summarize image_classification
In this example, we generate a summary of the trained .tflite
model file in the
image_classification model's model archive.
mltk summarize image_classification --tflite
The given model need not be generated by the MLTK.
External models are also supported by the summarize
command:
mltk summarize ~/workspace/my_model.tflite
Training a model can be very time-consuming, and it is useful to know basic information
about a model before investing time and energy into training it.
For this reason, the MLTK summarize
command features a --build
flag to build a model
and summarize it before the model is fully trained.
In this example, the image_classification model is built at command-execution-time and a summarize is generated. Note that only the model specification script is required, it does not need to be trained first.
mltk summarize image_classification --tflite --build
Model summarization is accessible via the summarize_model API.
Examples using this API may be found in summarize_model.ipynb