AR# 72804


How to Quantize, Compile, and test the TensorFlow ResNet-50 example on a ZCU102 board


The TensorFlow ResNet-50 Convolutional Neural Network (CNN) is provided with the Xilinx Deep Neural Network Development Kit (DNNDK) v3.1.

The model can be found in the in the folder below:


How can I test this example on hardware?


The CNN Resnet50 developed with TensorFlow can be tested on hardware by completing the following steps:

  1. Install Anaconda and create a dedicated virtual environment, following the steps in the TensorFlow version: installing with Anaconda section in (UG1327).
    This installs the TensorFlow DNNDK on the host.
  2. Install CUDA and cuDNN on the host
  3. Flash the SD Card according to the steps in (UG1327)
  4. Complete the Quantization process and Compilation on the Host
  5. Build the model on the Target

This Answer Record provides additional help on some of these steps.

Model origin

It is important to know how the model was trained: the same image pre-processing sequence must be used during quantization and the hardware test.

The Resnet50 CNN in the example comes from the Model Zoo (

The CNN has been pre-trained with images coming from the ImageNet set, with the following characteristics:

  1. data channel order: RGB(0~255)
  2. resize: resize short side to 256 and keep the aspect ratio.
  3. center crop: 224 * 224
  4. input = input - [123.68, 116.78, 103.94]

Scaling the images to 0-1 during quantization, or reversing the order to BGR, or forgetting the average value subtraction are very common errors that will cause unexpected results in hardware.


The Quantization process requires some images for calibration, but they are not provided with the model. 

The user should download 100 to 1000 images of ImageNet data set from or

Note that the TensorFlow Calibration does not require the label value, so you will need to slightly modify the and skip the label information.

You might also need to edit line 21 and 22 that set the path to the calibration folder.

Notes on the

Remember that the image for training was in RGB format. The preprocesses the images using two functions:

  • cv2.imread (which converts the image to a BGR NumPy array)
  • The mean_image_subtraction (which brings the order back to RGB).


The Deep Neural Network Compiler (DNNC) generates one .elf file.

The kernel names are resnet_v1_50_0 (DPUKernel) and resnet_v1_50_1 (CPUKernel)

The same kernel names must be used in the file and Makefile.


Build on Target

The TensorFlow model needs a dedicated file which is different from the Caffe model.

In particular, the Kernel name, input/output names, images extensions, and some other cosmetic changes have been edited in the attached file.

Also the Makefile which comes with DNNDK 3.1 should be fixed due to a typo in the .elf model name.


Associated Attachments

Name File Size File Type 1 KB PY
Makefile 3 KB NA 7 KB CC
AR# 72804
Date 08/07/2020
Status Active
Type General Article
People Also Viewed