Preparing the Calibration Dataset and Input Function - 2.0 English

Vitis AI User Guide (UG1414)

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

The calibration set is usually a subset of the training/validation dataset or actual application images (at least 100 images for performance). The input function is a Python importable function to load the calibration dataset and perform data preprocessing. The vai_q_tensorflow quantizer can accept an input_fn to do the preprocessing, which is not saved in the graph. If the pre-processing subgraph is saved into the frozen graph, the input_fn only needs to read the images from dataset and return a feed_dict.

The format of input function is module_name.input_fn_name, (for example, my_input_fn.calib_input). The input_fn takes an int object as input, indicating the calibration step number, and returns a dict("placeholder_name, numpy.Array") object for each call, which is fed into the placeholder nodes of the model when running inference. The placeholder_name is always the input node of frozen graph, that is to say, the node receiving input data. The input_nodes, in the vai_q_tensorflow options, indicates where quantization starts in the frozen graph. Note that the placeholder_names and the input_nodes option are sometimes different. For example, when the frozen graph includes in-graph preprocessing, the placeholder_name is the input of the graph though it is recommended that input_nodes be set to the last node of preprocessing. The shape of numpy.array must be consistent with the placeholders. See the following pseudo code example:

$ “my_input_fn.py”
def calib_input(iter):
"""
A function that provides input data for the calibration
  Args:
    iter: A `int` object, indicating the calibration step number
  Returns:
    dict( placeholder_name, numpy.array): a `dict` object, which will be fed into the model
"""
  image = load_image(iter)
  preprocessed_image = do_preprocess(image)
  return {"placeholder_name": preprocessed_images}