vai_q_caffe takes a floating-point model as an input model and uses a calibration dataset
to generate a quantized model. Use the following steps to create and quantize Resnet50
floating-point model.
- Prepare a floating-point model for Resnet-50. You can download one from the internet or from Xilinx modelzoo (https://github.com/Xilinx/Vitis-AI/tree/master/AI-Model-Zoo).
- Prepare the calibration dataset used by vai_q_caffe. You can download 100 to
1000 images of ImageNet dataset from http://academictorrents.com/collection/imagenet-2012
or http://www.image-net.org/download.php and then change the
source
androot_folder
ofimage_data_param
in ResNet-50 prototxt accordingly. For example, the ImageData layer in prototxt looks like the following:
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".layer { name: "data" type: "ImageData" top: "data" top: "label" include { phase: TRAIN } transform_param { mirror: false crop_size: 224 mean_value: 104 mean_value: 107 mean_value: 123 } image_data_param { source: "/path/calibration.txt" root_folder: "/path/calibration_images/" batch_size: 20 shuffle: false } }
n01440764_985.JPEG 0 n01443537_9347.JPEG 0 n01484850_8799.JPEG 0
- Activate the caffe running
environment:
conda activate vitis-ai-caffe
- Start
quantization:
If your targeting hardware platform is DPUCAHX8H, another option "vai_q_caffe quantize -model float.prototxt -weights float.caffemodel
-keep_fixed_neuron
" should be added to the command. Refer to Chapter 4 for details.vai_q_caffe quantize -model float.prototxt -weights float.caffemodel -keep_fixed_neuron
This invokes the vai_q_caffe tool to perform quantization with the appropriate parameters. The running time of this command varies from a few seconds to several minutes, depending on hardware and the size of the neural network. Four files are generated in the output directory, including deploy.prototxt and deploy.caffemodel, which could be fed to VAI compiler for the following compilation process.