vai_q_caffe QAT - 2.0 English

Vitis AI User Guide (UG1414)

Document ID
UG1414
Release Date
2022-01-20
Version
2.0 English
Generally, there is a small accuracy loss after quantization, but for some networks such as Mobilenets, the accuracy loss can be large. In such a scenario, QAT can be used to further improve the accuracy of quantized models.

Finetuning is almost the same as model training, which needs the original training dataset and a solver.prototxt. To start finetuning with the quantize_train_test.prototxt and Caffe Model, follow these steps:

  1. Assign the training dataset to the input layer of quantize_train_test.prototxt.
  2. Create a solver.prototxt file for finetuning. An example of a solver.prototxt file is provided below. You can adjust the hyper-parameters to get good results. The most important parameter is base_lr, which is usually much smaller than the one used in training.

  3. Start finetuning by executing the following command.
    ./vai_q_caffe finetune -solver solver.prototxt -weights quantize_results/quantize_train_test.caffemodel -gpu all
  4. Deploy the finetuned model. The finetuned model is generated in the snapshot_prefix settings of the solver.prototxt file, such as ${snapshot_prefix}/finetuned_iter10000.caffemodel. You can use the test command to test its accuracy.
  5. Generate the deploy model (prototxt and caffemodel) for the Vitis AI compiler using the deploy command.
    ./vai_q_caffe deploy -model quantize_results/quantize_train_test.prototxt -weights finetuned_iter10000.caffemodel -gpu 0 -output_dir deploy_output