tf_nndct.IterativePruningRunner - 2.5 English

Vitis AI Optimizer User Guide (UG1333)

Document ID
UG1333
Release Date
2022-06-15
Version
2.5 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.

    model
    A baseline model to prune. The mode should be an instance of keras.Model.
    input_specs
    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.

    eval_fn
    Callable object that takes a keras.Model object as its first argument and returns the evaluation score.
    excludes
    A list of layer name or layer instance to be excluded from pruning.
    forced
    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.

    ratio
    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.
    threshold
    Relative proportion of model performance loss between the baseline model and the pruned model.
    spec_path
    Pruning specification path used to prune the model.
    excludes
    A list of layer name or layer instance to be excluded from pruning.
    mode
    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.

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