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:
The 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. 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:$ "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}