Preparing the Calibration Dataset and Input Function - 3.5 English

Vitis AI User Guide (UG1414)

Document ID
Release Date
3.5 English

The calibration set is typically a subset of the training, validation dataset, or actual application images (consisting of at least 100 for optimal performance). The input function is a Python importable function that handles data pre-processing. This function loads the calibration dataset and performs the necessary data pre-processing steps. The vai_q_tensorflow quantizer can accept an input_fn for pre-processing, which is not saved in the graph. However, if the pre-processing subgraph is saved into the frozen graph, the input_fn only needs to read the images from the dataset and return a feed_dict.

The input function follows the module_name.input_fn_name format (for example, my_input_fn.calib_input). It accepts an int object representing the calibration step number and returns a dict object with placeholder_name, numpy.Array for each call. The object is fed into the model's placeholder nodes during inference. The placeholder_name always corresponds to the input node of the frozen graph, which serves as the node for receiving input data.
Note: placeholder_name should be replaced with the actual name of the input node receiving the input images. For example, if the input placeholder node is named the_input_node, the placeholder_name should be replaced with the_input_node.
The input_nodes in the vai_q_tensorflow options indicate where the quantization starts in the frozen graph. The placeholder_names and the input_nodes option are sometimes different. When the frozen graph incorporates in-graph pre-processing, the placeholder_name represents the input of the graph. However, setting input_nodes to the last node of the pre-processing steps is advisable. Ensure that the shape of numpy.the array is consistent with the corresponding placeholders. Here's a pseudo-code example for reference:
$ ""
def calib_input(iter):
A function that provides input data for the calibration
    iter: A `int` object, indicating the calibration step number
    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}