tf_nndct.IterativePruningRunner - 2.0 English

Vitis AI Optimizer User Guide (UG1333)

Document ID
Release Date
2.0 English

Runner for structured pruning of Keras model in an iterative way. This API has the following methods:

  • __init__(model, input_specs)

    Creates a new IterativePruningRunner object.

    A baseline model to prune. The mode should be an instance of keras.Model.
    A single or a list of tf.TensorSpec used to represent model input specifications.
  • ana(eval_fn, excludes=None, forced=False)

    Performs model analysis. The analysis result will be saved in '.vai' directory and this cached result will be used directly in subsequent calls unlessforced is set to True.

    Callable object that takes a keras.Model object as its first argument and returns the evaluation score.
    A list of layer name or layer instance to be excluded from pruning.
    When set to True, run model analysis is run instead of using the cached analysis result.
  • prune(ratio=None, threshold=None, spec_path=None, excludes=None, mode='sparse')

    Prune the baseline model and returns a sparse model. The degree of model reduction can be specified in three ways: ratio, threshold, or pruning specification. The first method is the preferred method; the latter two are more suitable for experiments with manual tuning.

    The expected percentage of MACs reduction of baseline model. This is a guidance value and the actual MACs reduction may not strictly be equal to this value.
    Relative proportion of model performance loss between the baseline model and the pruned model.
    Pruning specification path used to prune the model.
    A list of layer name or layer instance to be excluded from pruning.
    The mode in which the baseline model is pruned to return a sparse model.
  • get_slim_model(spec_path=None)

    Get a slim model from a sparse model. Use the latest pruning specification to do this transformation by default. If the sparse model was not generated from the latest specification, a specification path can be provided explicitly.

    Path of pruning specification used to transform a sparse model to a slim model.