TensorFlow Support - DigitalMediaProfessionals/dv-sdk GitHub Wiki

DMP implemented TensorFlow support by registering the DV 700 device as one of the backend. This means that existing TensorFlow applications can run without modification on the AI FPGA module if it is written in Python. Or only need to recompile if it is written in C/C++.

NOTE: The latest TensorFlow release is based on 1.15.0 version. TensorFlow support will be only on ZIA C3 module. There is no plan to support TensorFlow on ZIA C2 module.

Install

TensorFlow release packages (both C-API library and Python package) are put on DMP APT repository. See this page for instructions to setup DMP APT repository.
If one previously installed the tensorflow ALPHA package, please run the following command to uninstall previous installation first:

$ sudo python3 -m pip uninstall tensorflow

Then please use the following command to install the latest release from the DMP APT server:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install zia-libtensorflow zia-python3-tensorflow

These command will update the firmware and driver to version Version 7.21.20191223 or higher, then install tensorflow package.

Run

After TensorFlow is installed, one can try to run networks to get inference results.

To quickly test YOLOv3-tiny, update the DV SDK by following instructions in this page. To run the demo application, use the following commands:

$ cd dv-sdk/application/YOLOv3TF
$ ./YOLOv3TF.py --image-dir ../bin/images_yolo/XPT/

It will process all images inside bin/images_yolo/XPT and put the results in the output folder. (This will take some time to process all images.)

Environment variables

The following environment variable can be set to accelerate TensorFlow inference on ZIA C3 module. This setting will be effective until power-off.

TF_DMPDV_CONST_WEIGHTS

This variable affects if the weights are assumed to be changing or not. If the weights are assumed to be not changing, it can increase TensorFlow performance. The default value is 0.

  • -1 Assume the weights may be changing, then don't check this environment variable anymore.
  • 0 Assume the weights may be changing, but still check this environment variable every run.
  • 1 Assume the weights wont' be changing, but still check this environment variable every run.
  • 2 Assume the weights wont' be changing, then don't check this environment variable anymore.

For example, the demo application will run faster using the following command:

$ export TF_DMPDV_CONST_WEIGHTS=1
$ ./YOLOv3TF.py --image-dir ../bin/images_yolo/XPT/

Limitations in the latest release

  • Training is not supported.
  • Tensors with up to 4 dimensions are supported, higher dimensions might not work.
  • Only layers commonly used in Deep Learning were tested, other mathematical functions like linear algebra might not work, it is possible to use CPU device for unsupported layers by defining them within block with tf.device("/CPU:0"):.