Running vai_q_caffe - 2.0 English

Vitis AI User Guide (UG1414)

Document ID
UG1414
Release Date
2022-01-20
Version
2.0 English
Use the following steps to run vai_q_caffe.
  1. Prepare the Neural Network Model.
    Table 1. vai_q_caffe Input Files
    No. Name Description
    1 float.prototxt Floating-point model for ResNet-50. The data layer in the prototxt should be consistent with the path of the calibration dataset.
    2 float.caffemodel Pre-trained weights file for ResNet-50.
    3 calibration dataset A subset of the training set containing 100 to 1000 images.

    Before running vai_q_caffe, prepare the Caffe model in floating-point format with the calibration data set, including the following:

    • Caffe floating-point network model prototxt file.
    • Pre-trained Caffe floating-point network model caffemodel file.
    • Calibration data set. The calibration set is usually a subset of the training set or actual application images (at least 100 images). Make sure to set the source and root_folder in image_data_param to the actual calibration image list and image folder path. For quantize calibration, calibration data without a label is enough. But due to the implementation, an image list file with two columns is required. Just set the second column to a random value or zero. This is an example of "calibration.txt".
      n01440764_985.JPEG 0
      n01443537_9347.JPEG 0
      n01484850_8799.JPEG 0
      ...
    Figure 1. Sample Caffe Layer for Quantization
    Note: Three mean_value parameters for channels are recommended. If three mean_value parameters are specified, following the order BGR.
  2. Run vai_q_caffe to generate a quantized model:
    vai_q_caffe quantize -model float.prototxt -weights float.caffemodel [options]
    Because there are small differences between hardware platforms, the output formats of vai_q_caffe are also different. If the target hardware platform is DPUCAHX8H, the -keep_fixed_neuron option should be added to the command.
    vai_q_caffe quantize -model float.prototxt -weights float.caffemodel -keep_fixed_neuron[options]
  3. After successful execution of the above command, four files are generated in the output directory (default directory, /quantize_results/). The deploy.prototxt and deploy.caffemodel files are used as input files to the compiler. The quantize_train_test.prototxt and quantize_train_test.caffemodel files are used to test the accuracy on the GPU/CPU, and can be used as input files for quantization aware training.
    Table 2. vai_q_caffe Output Files
    No. Name Description
    1 deploy.prototxt For Vitis AI compiler, quantized network description file.
    2 deploy.caffemodel For Vitis AI compiler, quantized Caffe model parameter file (non-standard Caffe format).
    3 quantize_train_test.prototxt For testing and finetuning, quantized network description file.
    4 quantize_train_test.caffemodel For testing and finetuning, quantized Caffe model parameter file (non-standard Caffe format).
    To evaluate the accuracy of the quantized model, use a command similar to the following, or add an -auto_test in step 2. Refer to the next section for vai_q_caffe argument details.
    vai_q_caffe test -model ./quantize_results/quantize_train_test.prototxt -weights ./quantize_results/quantize_train_test.caffemodel -gpu 0 -test_iter 1000