How to build TensorFlow - t-kuha/zynq-library GitHub Wiki

Environment

Build

# Get source & extract it
$ wget https://github.com/tensorflow/tensorflow/archive/v1.9.0.tar.gz
$ tar xf v1.9.0.tar.gz
$ cd tensorflow-1.9.0

# Build protoc for host
$ tensorflow/contrib/makefile/download_dependencies.sh
$ tensorflow/contrib/makefile/compile_linux_protobuf.sh

# Build protobuf for Zynq
# Use protoc compiled above
$ PATH=`pwd`/tensorflow/contrib/makefile/gen/protobuf-host/bin:${PATH} \
> tensorflow/contrib/makefile/compile_zynq_protobuf.sh

# Build nsync for host & zynq
$ tensorflow/contrib/makefile/compile_nsync.sh
$ CC_PREFIX=arm-linux-gnueabihf- tensorflow/contrib/makefile/compile_nsync.sh -t zynq 

# Build TensorFlow lib
$ LD_LIBRARY_PATH=`pwd`/tensorflow/contrib/makefile/gen/protobuf-host/lib \
> CC_PREFIX=arm-linux-gnueabihf- \
> TARGET_NSYNC_LIB=tensorflow/contrib/makefile/downloads/nsync/builds/default.zynq.c++11/nsync.a \
> HOST_NSYNC_LIB=tensorflow/contrib/makefile/downloads/nsync/builds/default.linux.c++11/nsync.a \
> make -j`nproc` -f tensorflow/contrib/makefile/Makefile OPTFLAGS="-O3" \
> HOST_CXXFLAGS="--std=c++11" \
> LIBFLAGS="-L`pwd`/tensorflow/contrib/makefile/gen/protobuf-zynq/lib" \
> AR=arm-linux-gnueabihf-ar 

Copy output product

# Binary & library archive
$ cp -R tensorflow/contrib/makefile/gen/bin/benchmark <Destination>
$ cp -R tensorflow/contrib/makefile/gen/lib/libtensorflow-core.a <Destination>
$ cp -R tensorflow/contrib/makefile/downloads/nsync/builds/default.zynq.c++11/libnsync.a <Destination>
$ cp -R gen/protobuf-zynq/lib/libprotobuf.so* <Destination>

# Collect headers (maintain directory structure)
$ export TEMPDIR=`mktemp -d`
$ find . -type f -name "*.h" | xargs -i% cp --parents % $TEMPDIR
$ find tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/ -maxdepth 1 -type f | xargs -i% cp % $TEMPDIR/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/
$ find tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11 -maxdepth 1 -type f | xargs -i% cp % $TEMPDIR/tensorflow/contrib/makefile/downloads/eigen/unsupported/Eigen/CXX11
$ find third_party/eigen3/unsupported/Eigen/CXX11/ -maxdepth 1 -type f | xargs -i% cp --parents % $TEMPDIR
$ find third_party/eigen3/Eigen/ -maxdepth 1 -type f | xargs -i% cp --parents % $TEMPDIR
$ cp -R gen/protobuf-zynq/include/* <Destination>

How to run

$ ./benchmark \
> --graph=tensorflow_inception_graph.pb \
> --input_layer="input:0" \
> --input_layer_shape="1,224,224,3" \
> --input_layer_type="float" \
> --output_layer="output:0"