Getting the Pruned Model - 2.0 English

Vitis AI Optimizer User Guide (UG1333)

Document ID
UG1333
Release Date
2022-01-20
Version
2.0 English

When the iterative pruning is completed, a sparse model is generated which has the same number of parameters as the original model but with many of them now set to zero.

Call get_slim_model() to remove zeroed parameters and from the sparse model and get a truly pruned model:

model.load_weights("model_sparse_0.5")

input_shape = [28, 28, 1]
input_spec = tf.TensorSpec((1, *input_shape), tf.float32)
runner = IterativePruningRunner(model, input_spec)
runner.get_slim_model()

By default, the runner uses the latest pruning specification to generate the slim model. You can see what the latest specification file is with the following command:

$ cat .vai/latest_spec
$ ".vai/mnist_ratio_0.5.spec"

If this file does not match your sparse model, you can explicitly specify the file path to be used:

runner.get_slim_model(".vai/mnist_ratio_0.5.spec")