From 446c379c92e15ad8f24ed0db853dd0fc9c271151 Mon Sep 17 00:00:00 2001 From: Ruomei Yan Date: Mon, 20 Feb 2023 15:32:54 +0000 Subject: Add a CLI component to enable rewrites * Add flags for rewrite (--rewrite, --rewrite-start, --rewrite-end, --rewrite-target) * Refactor CLI interfaces to accept tflite models with optimize for rewrite, keras models with optimize for clustering and pruning * Refactor and move common.py and select.py out of the folder nn/tensorflow/optimizations * Add file nn/rewrite/core/rewrite.py as placeholder * Update/add unit tests * Refactor OptimizeModel in ethos_u/data_collection.py for accepting tflite model case * Extend the logic so that if "--rewrite" is specified, we don't add pruning to also accept TFLite models. * Update README.md Resolves: MLIA-750, MLIA-854, MLIA-865 Signed-off-by: Benjamin Klimczak Change-Id: I67d85f71fa253d2bad4efe304ad8225970b9622c --- README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 725af53..7a879a9 100644 --- a/README.md +++ b/README.md @@ -158,10 +158,11 @@ mlia check --help ## **optimize** -This sub-command applies optimizations to a Keras model (.h5 or SavedModel) and -shows the performance improvements compared to the original unoptimized model. +This sub-command applies optimizations to a Keras model (.h5 or SavedModel) or +a TensorFlow Lite model and shows the performance improvements compared to +the original unoptimized model. -There are currently two optimization techniques available to apply: +There are currently three optimization techniques available to apply: * **pruning**: Sets insignificant model weights to zero until the specified sparsity is reached. @@ -172,9 +173,13 @@ More information about these techniques can be found online in the TensorFlow documentation, e.g. in the [TensorFlow model optimization guides](https://www.tensorflow.org/model_optimization/guide). +* **rewrite**: Replaces certain subgraph/layer of the pre-trained model with + candidates from the rewrite library, with or without training using a + small portion of the training data, to achieve local performance gains. + **Note:** A ***Keras model*** (.h5 or SavedModel) is required as input to -perform the optimizations. Models in the TensorFlow Lite format are **not** -supported. +perform pruning and clustering. A ***TensorFlow Lite model*** is required as input +to perform a rewrite. *Examples:* @@ -189,6 +194,15 @@ mlia optimize ~/models/ds_cnn_l.h5 \ # Get help and further information mlia optimize --help + +# An example for using rewrite +mlia optimize ~/models/ds_cnn_large_fp32.tflite \ + --target-profile ethos-u55-256 \ + --rewrite \ + --dataset input.tfrec \ + --rewrite-target fully_connected \ + --rewrite-start MobileNet/avg_pool/AvgPool \ + --rewrite-end MobileNet/fc1/BiasAdd ``` # Target profiles -- cgit v1.2.1