Skip to content

Commit

Permalink
r2.15
Browse files Browse the repository at this point in the history
  • Loading branch information
PINTO0309 committed Dec 11, 2023
1 parent 687f5f1 commit 5297951
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

TFVER=2.15.0
curl -OL https://github.com/PINTO0309/TensorflowLite-bin/releases/download/v${TFVER}/tflite_runtime-${TFVER/-/}-cp310-none-linux_aarch64.whl

echo Download finished.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

TFVER=2.15.0
curl -OL https://github.com/PINTO0309/TensorflowLite-bin/releases/download/v${TFVER}/tflite_runtime-${TFVER/-/}-cp310-none-linux_armv7l.whl

echo Download finished.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

TFVER=2.15.0
curl -OL https://github.com/PINTO0309/TensorflowLite-bin/releases/download/v${TFVER}/tflite_runtime-${TFVER/-/}-cp311-none-linux_aarch64.whl

echo Download finished.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

TFVER=2.15.0
curl -OL https://github.com/PINTO0309/TensorflowLite-bin/releases/download/v${TFVER}/tflite_runtime-${TFVER/-/}-cp311-none-linux_armv7l.whl

echo Download finished.
159 changes: 42 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,40 @@ A repository that shares tuning results of trained models generated by Tensorflo
|RaspberryPi3/4|Ubuntu 21.04/Debian/RaspberryPiOS|Hirsute/Bullseye|aarch64 / armv8|3.9|64bit|
|RaspberryPi3/4|Ubuntu 22.04|Jammy|armhf / armv7l|3.10|32bit|
|RaspberryPi3/4|Ubuntu 22.04|Jammy|aarch64 / armv8|3.10|64bit|
|RaspberryPi3/4|Debian|Bookworm|armhf / armv7l|3.11|32bit|
|RaspberryPi3/4|Debian|Bookworm|aarch64 / armv8|3.11|64bit|
|RaspberryPi3/4/5|RaspberryPiOS/Debian|Bookworm|armhf / armv7l|3.11|32bit|
|RaspberryPi3/4/5|RaspberryPiOS/Debian|Bookworm|aarch64 / armv8|3.11|64bit|

## Usage
```bash
$ sudo apt install -y \
swig libjpeg-dev zlib1g-dev python3-dev \
unzip wget python3-pip curl git cmake make
$ sudo pip3 install numpy==1.24.3

$ TFVER=2.12.0

$ PYVER=39
or
$ PYVER=38
sudo apt-get update && \
sudo apt install -y \
swig \
libjpeg-dev \
zlib1g-dev \
python3-dev \
python-is-python3 \
unzip \
wget \
python3-pip \
curl \
git \
cmake \
make

pip install -U pip
pip install numpy

TFVER=2.15.0.post1

PYVER=310
or
$ PYVER=310
or
$ PYVER=311
PYVER=311

$ ARCH=aarch64
ARCH=aarch64
or
$ ARCH=armhf
ARCH=armhf

$ sudo -H pip3 install \
pip install \
--no-cache-dir \
https://github.com/PINTO0309/TensorflowLite-bin/releases/download/v${TFVER}/tflite_runtime-${TFVER/-/}-cp${PYVER}-none-linux_${ARCH}.whl
```
Expand All @@ -83,105 +92,21 @@ interpreter = Interpreter(model_path="foo.tflite")
### Tensorflow v2.3.0+
interpreter = Interpreter(model_path="foo.tflite", num_threads=4)
```
## Build parameter
- git clone
```bash
TFVER=2.12.0
git clone -b v${TFVER} --depth 1 https://github.com/tensorflow/tensorflow.git
cd tensorflow
```
- Adjustment of Dockerfile and Header file
```bash
sed -i -e 's/RUN yes/#RUN yes/g' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i -e 's/RUN pip3 install numpy~=1.19.2/RUN pip3 install numpy==1.24.3/g' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i '19a ENV DEBIAN_FRONTEND=noninteractive' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i '20a ENV TZ=Etc/UTC' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i '29a \ tzdata \\' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i -e 's/RUN DEBIAN_FRONTEND=noninteractive/#RUN DEBIAN_FRONTEND=noninteractive/g' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i '50a \ python-is-python3 \\' tensorflow/lite/tools/pip_package/Dockerfile.py3
sed -i '15a #include <assert.h>' tensorflow/tsl/framework/fixedpoint/MatMatProductAVX2.h
```
- Added FlexDelegate and XNNPACK as build options. If you want to keep the binary size as small as possible, change `tflite_pip_with_flex` and `tflite_with_xnnpack` to `false` and build. The `--copt=-fpermissive` option of armhf is deprecated.
```bash
nano tensorflow/lite/tools/pip_package/build_pip_package_with_bazel.sh

# Build python interpreter_wrapper.
cd "${BUILD_DIR}"
case "${TENSORFLOW_TARGET}" in
armhf)
BAZEL_FLAGS="--config=elinux_armhf
--copt=-march=armv7-a --copt=-mfpu=neon-vfpv4
--copt=-O3 --copt=-fno-tree-pre --copt=-fpermissive
--define tensorflow_mkldnn_contraction_kernel=0
--define=raspberry_pi_with_neon=true"
;;
aarch64)
BAZEL_FLAGS="--config=elinux_aarch64
--define tensorflow_mkldnn_contraction_kernel=0
--copt=-O3"
;;
native)
BAZEL_FLAGS="--copt=-O3 --copt=-march=native"
;;
*)
BAZEL_FLAGS="--copt=-O3"
;;
esac


# Build python interpreter_wrapper.
cd "${BUILD_DIR}"
case "${TENSORFLOW_TARGET}" in
armhf)
BAZEL_FLAGS="--config=elinux_armhf
--copt=-march=armv7-a --copt=-mfpu=neon-vfpv4
--copt=-O3 --copt=-fno-tree-pre
--define tensorflow_mkldnn_contraction_kernel=0
--define=raspberry_pi_with_neon=true
--define=tflite_pip_with_flex=true
--define=tflite_with_xnnpack=false
--define=tflite_kernel_use_xnnpack=false
--ui_actions_shown=20"
;;
aarch64)
BAZEL_FLAGS="--config=elinux_aarch64
--define tensorflow_mkldnn_contraction_kernel=0
--define=tflite_pip_with_flex=true
--define=tflite_with_xnnpack=true
--copt=-O3
--ui_actions_shown=20"
;;
native)
BAZEL_FLAGS="--copt=-O3 --copt=-march=native
--define=tflite_pip_with_flex=true
--define=tflite_with_xnnpack=true
--ui_actions_shown=20"
;;
*)
BAZEL_FLAGS="--copt=-O3
--define=tflite_pip_with_flex=true
--define=tflite_with_xnnpack=true
--ui_actions_shown=20"
;;
esac
```
- Build
```bash
cd tensorflow/lite/tools/pip_package

make BASE_IMAGE=ubuntu:20.04 PYTHON=python3 PYTHON_VERSION=3.8 TENSORFLOW_TARGET=aarch64 docker-build
make BASE_IMAGE=debian:bullseye PYTHON=python3 PYTHON_VERSION=3.9 TENSORFLOW_TARGET=aarch64 docker-build
make BASE_IMAGE=ubuntu:22.04 PYTHON=python3 PYTHON_VERSION=3.10 TENSORFLOW_TARGET=aarch64 docker-build
make BASE_IMAGE=debian:bookworm PYTHON=python3 PYTHON_VERSION=3.11 TENSORFLOW_TARGET=aarch64 docker-build

make BASE_IMAGE=ubuntu:20.04 PYTHON=python3 PYTHON_VERSION=3.8 TENSORFLOW_TARGET=armhf docker-build
make BASE_IMAGE=debian:bullseye PYTHON=python3 PYTHON_VERSION=3.9 TENSORFLOW_TARGET=armhf docker-build
make BASE_IMAGE=ubuntu:22.04 PYTHON=python3 PYTHON_VERSION=3.10 TENSORFLOW_TARGET=armhf docker-build
make BASE_IMAGE=debian:bookworm PYTHON=python3 PYTHON_VERSION=3.11 TENSORFLOW_TARGET=armhf docker-build

make BASE_IMAGE=ubuntu:20.04 PYTHON=python3 PYTHON_VERSION=3.8 TENSORFLOW_TARGET=native docker-build
```

## Build
```bash
BRANCH=r2.15-tflite-build
git clone -b ${BRANCH} --depth 1 https://github.com/PINTO0309/tensorflow.git
cd tensorflow/lite/tools/pip_package

make BASE_IMAGE=ubuntu:22.04 PYTHON=python3 PYTHON_VERSION=3.10 TENSORFLOW_TARGET=aarch64 docker-build
make BASE_IMAGE=debian:bookworm PYTHON=python3 PYTHON_VERSION=3.11 TENSORFLOW_TARGET=aarch64 docker-build

make BASE_IMAGE=ubuntu:22.04 PYTHON=python3 PYTHON_VERSION=3.10 TENSORFLOW_TARGET=armhf docker-build
make BASE_IMAGE=debian:bookworm PYTHON=python3 PYTHON_VERSION=3.11 TENSORFLOW_TARGET=armhf docker-build

make BASE_IMAGE=ubuntu:22.04 PYTHON=python3 PYTHON_VERSION=3.10 TENSORFLOW_TARGET=native docker-build
```

## Operation check 【Classification】
**Sample of MultiThread x4 by Tensorflow Lite [MobileNetV1 / 75ms]**
Expand Down

0 comments on commit 5297951

Please sign in to comment.