Use the following steps to Run
vai_q_caffe.
- Prepare the Neural Network Model
Table 1. vai_q_caffe Input Files No. Name Description 1 float.prototxt Floating-point model for ResNet-50. Thedata 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 label is enough. But due to the
implementation, a 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 QuantizationNote: 3 mean_value parameters for channels are recommended. If 3 mean_value parameters are specified, following the order BGR. - Run vai_q_caffe
Run vai_q_caffe to generate a fixed-point model:
Because there are small differences between hardware platforms, the output formats ofvai_q_caffe quantize -model float.prototxt -weights float.caffemodel [options]
vai_q_caffe
are also different. If the target hardware platform is DPUv3, option "-keep_fixed_neuron
" should be added to the command.vai_q_caffe quantize -model float.prototxt -weights float.caffemodel -keep_fixed_neuron[options]
- Output
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 to quantize finetuning.
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).