jami-docs

Forked version of Jami documentation, see wrycode.com/jami-docs-demo
git clone git://git.wrycode.com/wrycode/jami-docs.git
Log | Files | Refs

tensorflow-plugin.md (4772B)


      1 # Build Tensorflow
      2 
      3 **NOTE: this page describes to build Tensorflow and TensorflowLite C++ API for Linux Android and Windows.**
      4 
      5 ## Tensorflow 2.1.0
      6 
      7 A difficulty for a lot of people working with tensorflow is how to properly build it.
      8 With that in mind we created docker images with cuda and tensorflow libraries available for GNU/Linux builds [here](https://hub.docker.com/repository/docker/sflagsantos/tensorflow-cuda) and for Android builds [here](https://hub.docker.com/repository/docker/sflagsantos/tensorflowlite). These docker can be used to build plugins for Linux and Android, however they cannot handle Windows.
      9 Here we carefully guide you through the proper build of tensorflow LITE Native and Tensorflow C++ API for our three supported platforms.
     10 
     11 You will need:
     12 
     13 * Python 3
     14 * Bazel 0.29.1
     15 * Tensorflow 2.1.0 repository:
     16 
     17 	```bash
     18 	git clone https://github.com/tensorflow/tensorflow.git
     19 	cd tensorflow
     20 	git checkout v2.1.0
     21 	```
     22 We assembled Tensorflow headers needed to build plugins, to access them you only have to extract `libs.tar.gz` file found under `jami-project/plugins/contrib`. However, if you are using another tensorflow version or you want to do it by yourself, you can follow the assemble instructions for Tensorflow LITE Native and C++ API are available under [jami-plugins](https://git.jami.net/savoirfairelinux/jami-plugins) README_ASSEMBLE file.
     23 
     24 #### Linux
     25 Tensorflow LITE does not support desktops GPU. If you want to use them, please consider using C++ API
     26 
     27 If you want to build Tensorflow C++ API with GPU suport, be sure to have a CUDA capable GPU and that you have
     28 followed all installation steps for the Nvidia drivers, CUDA Toolkit, CUDNN, Tensor RT, that their versions
     29 matches and that they are correct for the Tensorflow version you want to build.
     30 
     31 The following links may be very helpfull:
     32 
     33 * https://www.tensorflow.org/install/source
     34 * https://developer.nvidia.com/cuda-gpus
     35 * https://developer.nvidia.com/cuda-toolkit-archive
     36 * https://developer.nvidia.com/cudnn
     37 
     38 Setup your build options with `./configure`.
     39 
     40 * Tensorflow LITE Native
     41 
     42 	```bash
     43 	bazel build //tensorflow/lite:libtensorflowlite.so
     44 	```
     45 * Tensorflow C++ API
     46 
     47 	```bash
     48 	bazel build --config=v1 --define framework_shared_object=false --define=no_tensorflow_py_deps=true //tensorflow:libtensorflow_cc.so
     49 	```
     50 
     51 #### Windows
     52 Tensorflow LITE does not support desktops GPU. If you want to use them, please consider using C++ API
     53 
     54 If you want to build Tensorflow C++ API with GPU suport, be sure to have a CUDA capable GPU and that you have
     55 followed all installation steps for the Nvidia drivers, CUDA Toolkit, CUDNN, Tensor RT, that their versions
     56 matches and that they are correct for the Tensorflow version you want to build.
     57 
     58 The following links may be very helpfull:
     59 
     60 * https://www.tensorflow.org/install/source
     61 * https://developer.nvidia.com/cuda-gpus
     62 * https://developer.nvidia.com/cuda-toolkit-archive
     63 * https://developer.nvidia.com/cudnn
     64 
     65 Setup your build options with `python3 configure.py`.
     66 
     67 * Tensorflow LITE Native
     68 
     69 	```bash
     70 	bazel build //tensorflow/lite:tensorflowlite.dll
     71 	```
     72 * Tensorflow C++ API
     73 
     74 	```bash
     75 	bazel build --config=v1 --define framework_shared_object=false --config=cuda --define=no_tensorflow_py_deps=true //tensorflow:tensorflow_cc.dll
     76 	```
     77 
     78 There may be some missign references while compiling a plugin with
     79 Tensorflow C++ API. If that happens you have to rebuild you tensorflow
     80 and explicitly export the missing symbols. Fortunatelly Tensorflow now
     81 has a easy workaround to do so, you only have to feed
     82 [this](https://github.com/tensorflow/tensorflow/blob/v2.2.0/tensorflow/tools/def_file_filter/def_file_filter.py.tpl)
     83 file with the desired symbols.
     84 
     85 #### Android - Tensorflow LITE Native
     86 For mobile applications Tensorflow LITE is the only option you want to consider and to succesfully build it you will also need:
     87 
     88 * Android NDK 18r
     89 
     90 Setup your build options with:
     91 
     92 ```bash
     93 ./configure
     94 		>> Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
     95 		>> Do you wish to download a fresh release of clang? (Experimental) [y/N]: y
     96 		>> Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: y
     97 		>> Please specify the home path of the Android NDK to use. [Default is /home/<username>/Android/Sdk/ndk-bundle]: put the right path to ndk 18r
     98 ```
     99 And build as desired:
    100 
    101 * armeabi-v7a
    102 
    103 	```bash
    104 	bazel build //tensorflow/lite:libtensorflowlite.so --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt="-std=c++11"
    105 	```
    106 * arm64-v8a
    107 
    108 	```bash
    109 	bazel build //tensorflow/lite:libtensorflowlite.so --crosstool_top=//external:android/crosstool --cpu=arm64-v8a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --cxxopt="-std=c++11"
    110 	```