This describes how to summarize an ML model using the MLTK’s commands/APIs.
.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.
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
Keras Model vs Tensorflow-Lite Model Summary¶
Two types of model summaries may be generated:
Keras Model - This provides a summary of the exact model used for training, file extension:
Both these models have similar model layouts, however, the Tensorflow-Lite model is slightly modified to optimize it for embedded execution.
By default, the
summarize command or summarize_model API will generate a summary of the trained
.h5 model in the model archive file.
--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
.h5 model file to summarize a non-MLTK generated model file.
Model summarization from the command-line is done using the
For more details on the available command-line options, issue the command:
mltk summarize --help
Example 1: Summarize Keras model¶
mltk summarize image_classification
Example 2: Summarize Tensorflow-Lite model¶
mltk summarize image_classification --tflite
Example 3: Summarize external Tensorflow-Lite model¶
The given model need not be generated by the MLTK.
External models are also supported by the
mltk summarize ~/workspace/my_model.tflite
Example 4: Summarize model before training¶
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