Caffe - 1.1 English

Vitis AI User Guide (UG1414)

Document ID
UG1414
Release Date
2020-03-23
Version
1.1 English

For presentation purposes, assume you have a MODEL (model.prototxt), WEIGHT (model.caffemodel), and a QUANT_INFO (i.e., quantization information file). The basic Caffe compiler interface comes with simplified help:

vai_c_caffe -help
**************************************************
 * VITIS_AI Compilation - Xilinx Inc.
 **************************************************
 usage: vai_c_caffe.py [-h] [-p PROTOTXT] [-c CAFFEMODEL] [-a ARCH]
                       [-o OUTPUT_DIR] [-n NET_NAME] [-e OPTIONS]optional arguments:
   -h, --help            show this help message and exit
   -p PROTOTXT, --prototxt PROTOTXT
                         prototxt
   -c CAFFEMODEL, --caffemodel CAFFEMODEL
                         caffe-model
   -a ARCH, --arch ARCH  json file
   -o OUTPUT_DIR, --output_dir OUTPUT_DIR
                         output directory
   -n NET_NAME, --net_name NET_NAME
                         prefix-name for the outputs
   -e OPTIONS, --options OPTIONS
                         extra options

The main goal of this interface is to specify the bare minimum across different designs. The following describes how to run specifically for DPU-V1, starting with the minimum inputs.

vai_c_caffe.py -p MODEL -c WEIGHT -a vai/dpuv1/tools/compile/arch.json -o WORK -n cmd -e OPTIONS

Specify the MODEL, WEIGHT, and where to write output. Specify a name for the code to be generated (i.e., cmd). In turn, this will create four outputs files in the WORK directory.

compiler.json  quantizer.json  weights.h5 meta.json

This is the main contract with the run time. There are three JSON files: one has the information about the instruction to be executed, the other has information about the quantization (i.e., how to scale and shift). The meta.json file is created from the arch.json file and it is basically a dictionary that specifies run time information. At the time of writing this user’s guide, the name cmd is necessary, but it is not used by run time.

The main difference with other versions of DPU, you need to specify the QUANT_INF0 using the options:

-e "{'quant_cfgfile' : '/SOMEWHERE/quantize_info.txt'}"

The option field is a string that represents a python dictionary. In this example, specify the location of the quantization file that has been computed separately and explained in Chapter 4. In context, other DPU versions just build this information in either the model or the weight, therefore, enhanced models are not a vanilla Caffe model and you will need a custom Caffe to run them. The DPU-V1 uses and executes the native Caffe (and the custom Caffe).

Note: Remember that the quantization file must be introduced. The compiler will ask to have one and eventually will crash when it looks for one. A Caffe model to be complete must have both a prototxt and a caffemodel. Postpone the discussion about the arch.json file, but it is necessary. Also this is the unified Caffe interface using a scripting format, there are python interfaces that allow more tailored uses and compilations where an expert can optimize a model much further.