Skip to content

Commit

Permalink
Update to tensorflow 2.1 for amd64, handle basic scores tflite model
Browse files Browse the repository at this point in the history
  • Loading branch information
snowzach committed Dec 13, 2019
1 parent 7360478 commit 99f5768
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 97 deletions.
6 changes: 3 additions & 3 deletions Dockerfile.base.aarch64
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM debian:buster as builder
RUN dpkg --add-architecture arm64 && \
apt-get update && apt-get install -y --no-install-recommends \
pkg-config zip zlib1g-dev unzip wget bash-completion git curl \
build-essential patch g++ python python-future python3 \
build-essential patch g++ python python-future python-numpy python-six python3 \
cmake ca-certificates \
libc6-dev:arm64 libstdc++6:arm64 libusb-1.0-0:arm64

Expand All @@ -20,7 +20,7 @@ RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24
rm bazel_0.24.1-linux-x86_64.deb

# Download tensorflow sources
ARG TF_VERSION="r1.15"
ARG TF_VERSION="v1.15.0"
ENV TF_VERSION $TF_VERSION
RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch

Expand All @@ -37,7 +37,7 @@ ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_N
RUN cd /opt/tensorflow && yes '' | ./configure

# Tensorflow build flags for rpi
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv8-a+crc+simd --copt=-mtune=cortex-a53 --copt=-O3 --copt=-flax-vector-conversions --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nogcp --config=nohdfs --config=nokafka --config=noignite --define tensorflow_mkldnn_contraction_kernel=0"
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv8-a+crc+simd --copt=-mtune=cortex-a53 --copt=-O3 --copt=-flax-vector-conversions --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0"
ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=//tools/local_arm_compiler:toolchain"

# Compile and build tensorflow lite
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile.base.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM debian:buster as builder
# Install reqs with cross compile support
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config zip zlib1g-dev unzip wget bash-completion git curl \
build-essential patch g++ python python-future python3 \
build-essential patch g++ python python-future python-numpy python-six python3 \
cmake ca-certificates \
libc6-dev libstdc++6 libusb-1.0-0

Expand All @@ -14,12 +14,12 @@ RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/pr
rm protoc-3.9.1-linux-x86_64.zip

# Install bazel
RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24.1-linux-x86_64.deb && \
dpkg -i bazel_0.24.1-linux-x86_64.deb && \
rm bazel_0.24.1-linux-x86_64.deb
RUN wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel_0.27.1-linux-x86_64.deb && \
dpkg -i bazel_0.27.1-linux-x86_64.deb && \
rm bazel_0.27.1-linux-x86_64.deb

# Download tensorflow sources
ARG TF_VERSION="r1.15"
ARG TF_VERSION="v2.1.0-rc1"
ENV TF_VERSION $TF_VERSION
RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch

Expand All @@ -28,7 +28,7 @@ ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_N
RUN cd /opt/tensorflow && yes '' | ./configure

# Tensorflow build flags for rpi
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --config monolithic --copt=-O3 --copt=-fomit-frame-pointer --copt=-mfpmath=both --copt=-mavx --copt=-msse4.2 --incompatible_no_support_tools_in_action_inputs=false --config=noaws --config=nogcp --config=nohdfs --config=nokafka --config=noignite"
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --config monolithic --copt=-O3 --copt=-fomit-frame-pointer --copt=-mfpmath=both --copt=-mavx --copt=-msse4.2 --incompatible_no_support_tools_in_action_inputs=false --config=noaws --config=nohdfs"
ENV BAZEL_EXTRA_FLAGS=""

# Compile and build tensorflow lite
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile.base.noavx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM debian:buster as builder
# Install reqs with cross compile support
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config zip zlib1g-dev unzip wget bash-completion git curl \
build-essential patch g++ python python-future python3 \
build-essential patch g++ python python-future python-numpy python-six python3 \
cmake ca-certificates \
libc6-dev libstdc++6 libusb-1.0-0

Expand All @@ -14,12 +14,12 @@ RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/pr
rm protoc-3.9.1-linux-x86_64.zip

# Install bazel
RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24.1-linux-x86_64.deb && \
dpkg -i bazel_0.24.1-linux-x86_64.deb && \
rm bazel_0.24.1-linux-x86_64.deb
RUN wget https://github.com/bazelbuild/bazel/releases/download/0.27.1/bazel_0.27.1-linux-x86_64.deb && \
dpkg -i bazel_0.27.1-linux-x86_64.deb && \
rm bazel_0.27.1-linux-x86_64.deb

# Download tensorflow sources
ARG TF_VERSION="r1.15"
ARG TF_VERSION="v2.1.0-rc1"
ENV TF_VERSION $TF_VERSION
RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch

Expand All @@ -28,7 +28,7 @@ ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_N
RUN cd /opt/tensorflow && yes '' | ./configure

# Tensorflow build flags for rpi
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --config monolithic --copt=-O3 --copt=-fomit-frame-pointer --config=noaws --config=nogcp --config=nohdfs --config=nokafka --config=noignite"
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --config monolithic --copt=-O3 --copt=-fomit-frame-pointer --config=noaws --config=nohdfs"
ENV BAZEL_EXTRA_FLAGS=""

# Compile and build tensorflow lite
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.base.rpi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM debian:buster as builder
RUN dpkg --add-architecture armhf && \
apt-get update && apt-get install -y --no-install-recommends \
pkg-config zip zlib1g-dev unzip wget bash-completion git curl \
build-essential patch g++ python python-future python3 \
build-essential patch g++ python python-future python-numpy python-six python3 \
cmake ca-certificates \
libc6-dev:armhf libstdc++6:armhf libusb-1.0-0:armhf

Expand All @@ -20,7 +20,7 @@ RUN wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel_0.24
rm bazel_0.24.1-linux-x86_64.deb

# Download tensorflow sources
ARG TF_VERSION="r1.15"
ARG TF_VERSION="v1.15.0"
ENV TF_VERSION $TF_VERSION
RUN cd /opt && git clone https://github.com/tensorflow/tensorflow.git --branch $TF_VERSION --single-branch

Expand All @@ -37,7 +37,7 @@ ENV TF_NEED_GDR=0 TF_NEED_AWS=0 TF_NEED_GCP=0 TF_NEED_CUDA=0 TF_NEED_HDFS=0 TF_N
RUN cd /opt/tensorflow && yes '' | ./configure

# Tensorflow build flags for rpi
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv7-a --copt=-mfpu=neon-vfpv4 --copt=-mfloat-abi=hard --copt=-O3 --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nogcp --config=nohdfs --config=nokafka --config=noignite --define tensorflow_mkldnn_contraction_kernel=0"
ENV BAZEL_COPT_FLAGS="--local_resources 16000,16,1 --copt=-march=armv7-a --copt=-mfpu=neon-vfpv4 --copt=-mfloat-abi=hard --copt=-O3 --copt=-std=c++11 --copt=-DS_IREAD=S_IRUSR --copt=-DS_IWRITE=S_IWUSR --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 --copt=-U__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 --config=monolithic --copt=-funsafe-math-optimizations --copt=-ftree-vectorize --copt=-fomit-frame-pointer --copt=-DRASPBERRY_PI --config=noaws --config=nohdfs --define tensorflow_mkldnn_contraction_kernel=0"
ENV BAZEL_EXTRA_FLAGS="--cpu=armeabi --crosstool_top=//tools/local_arm_compiler:toolchain"

# Compile and build tensorflow lite
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Example: `docker run -it --device /dev/bus/usb -p 8080:8080 snowzach/doods:lates
## Misc
Special thanks to https://github.com/mattn/go-tflite as I would have never been able to figure out all the CGO stuff. I really wanted to write this in Go but I'm not good enough at C++/CGO to do it. Most of the tflite code is taken from that repo and customized for this tool.

And special thanks to @marianopeck and @PINTO0309 for help in building tensorflow and binaries for bazel on the arm.
And special thanks to @lhelontra, @marianopeck and @PINTO0309 for help in building tensorflow and binaries for bazel on the arm.

## Docker Images
There are several published Docker images that you can use
Expand Down
Loading

0 comments on commit 99f5768

Please sign in to comment.