Skip to content

Commit b24ea5e

Browse files
committed
new package: python3.12-tflite-runtime
1 parent da2cdde commit b24ea5e

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- a/tensorflow/lite/CMakeLists.txt
2+
+++ b/tensorflow/lite/CMakeLists.txt
3+
@@ -233,7 +233,7 @@
4+
list(APPEND TFLITE_TARGET_PRIVATE_OPTIONS "-Wa,-mbig-obj")
5+
endif()
6+
endif()
7+
-if(CMAKE_SYSTEM_NAME MATCHES "Android")
8+
+if(FALSE)
9+
find_library(ANDROID_LOG_LIB log)
10+
list(APPEND TFLITE_TARGET_DEPENDENCIES
11+
log
12+
@@ -263,7 +263,7 @@
13+
14+
# Handle TFLite logging source.
15+
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*minimal_logging_.*\\.cc$")
16+
-if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
17+
+if(FALSE)
18+
list(APPEND TFLITE_SRCS ${TFLITE_SOURCE_DIR}/minimal_logging_android.cc)
19+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
20+
list(APPEND TFLITE_SRCS ${TFLITE_SOURCE_DIR}/minimal_logging_ios.cc)
21+
--- a/tensorflow/lite/tools/benchmark/CMakeLists.txt
22+
+++ b/tensorflow/lite/tools/benchmark/CMakeLists.txt
23+
@@ -78,7 +78,6 @@
24+
)
25+
endif() # _TFLITE_ENABLE_NNAPI
26+
list(APPEND TFLITE_BENCHMARK_LIBS
27+
- ${ANDROID_LOG_LIB}
28+
absl::strings
29+
)
30+
endif() # Android
31+
--- a/tensorflow/lite/tools/logging.h
32+
+++ b/tensorflow/lite/tools/logging.h
33+
@@ -27,7 +27,7 @@
34+
#undef ERROR
35+
#endif
36+
37+
-#ifdef __ANDROID__
38+
+#if 0
39+
#include <android/log.h>
40+
#endif
41+
42+
@@ -53,7 +53,7 @@
43+
if (should_log_) {
44+
// Also print log to logcat for android, as stderr will be hidden
45+
// in the app use case.
46+
-#ifdef __ANDROID__
47+
+#if 0
48+
switch (severity_) {
49+
case LogSeverity::INFO:
50+
__android_log_print(ANDROID_LOG_INFO, "tflite", "%s",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
TERMUX_PKG_HOMEPAGE=https://www.tensorflow.org/lite
2+
TERMUX_PKG_DESCRIPTION="TensorFlow Lite Python bindings"
3+
TERMUX_PKG_LICENSE="Apache-2.0"
4+
TERMUX_PKG_MAINTAINER="@termux-user-repository"
5+
TERMUX_PKG_VERSION="2.17.0"
6+
TERMUX_PKG_SRCURL=git+https://github.com/tensorflow/tensorflow
7+
TERMUX_PKG_AUTO_UPDATE=true
8+
TERMUX_PKG_DEPENDS="python, python-numpy, python-pip"
9+
TERMUX_PKG_UPDATE_TAG_TYPE="latest-release"
10+
TERMUX_PKG_PYTHON_COMMON_DEPS="setuptools, wheel, pybind11"
11+
12+
TERMUX_PYTHON_VERSION=3.12
13+
TERMUX_PYTHON_HOME=$TERMUX_PREFIX/lib/python${TERMUX_PYTHON_VERSION}
14+
TERMUX_PYTHON_CROSSENV_PREFIX=$TERMUX_PKG_BUILDDIR/python${TERMUX_PYTHON_VERSION/./}-crossenv-prefix-$TERMUX_ARCH
15+
TUR_AUTO_AUDIT_WHEEL=true
16+
TUR_AUDIT_WHEEL_NO_LIBS=true
17+
TUR_AUTO_BUILD_WHEEL=false
18+
TUR_WHEEL_DIR="build-wheel/dist"
19+
20+
source $TERMUX_SCRIPTDIR/common-files/tur_build_wheel.sh
21+
22+
termux_step_pre_configure() {
23+
termux_setup_cmake
24+
termux_setup_ninja
25+
26+
# Copied from tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh
27+
export TENSORFLOW_DIR="$TERMUX_PKG_SRCDIR"
28+
local TENSORFLOW_LITE_DIR="$TENSORFLOW_DIR/tensorflow/lite"
29+
local TENSORFLOW_VERSION=$(grep "_VERSION = " "$TENSORFLOW_DIR/tensorflow/tools/pip_package/setup.py" | cut -d= -f2 | sed "s/[ '-]//g")
30+
export PACKAGE_VERSION="$TENSORFLOW_VERSION"
31+
export PROJECT_NAME="tflite_runtime"
32+
TFLITE_BUILD_DIR="$TERMUX_PKG_BUILDDIR/build-wheel"
33+
local BUILD_DIR="$TFLITE_BUILD_DIR"
34+
local PYTHON="$(command -v python)"
35+
local PYBIND11_INCLUDE=$($PYTHON -c "import pybind11; print (pybind11.get_include())")
36+
CPPFLAGS+=" -I$PYTHON_SITE_PKG/numpy/_core/include"
37+
CPPFLAGS+=" -I$PYBIND11_INCLUDE"
38+
CPPFLAGS+=" -I$TERMUX_PREFIX/include/python$TERMUX_PYTHON_VERSION"
39+
40+
# Build source tree
41+
rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR/tflite_runtime"
42+
cp -r "$TENSORFLOW_LITE_DIR/tools/pip_package/debian" \
43+
"$TENSORFLOW_LITE_DIR/tools/pip_package/MANIFEST.in" \
44+
"$TENSORFLOW_LITE_DIR/python/interpreter_wrapper" \
45+
"$BUILD_DIR"
46+
cp "$TENSORFLOW_LITE_DIR/tools/pip_package/setup_with_binary.py" "$BUILD_DIR/setup.py"
47+
cp "$TENSORFLOW_LITE_DIR/python/interpreter.py" \
48+
"$TENSORFLOW_LITE_DIR/python/metrics/metrics_interface.py" \
49+
"$TENSORFLOW_LITE_DIR/python/metrics/metrics_portable.py" \
50+
"$BUILD_DIR/tflite_runtime"
51+
echo "__version__ = '$PACKAGE_VERSION'" >> "$BUILD_DIR/tflite_runtime/__init__.py"
52+
echo "__git_version__ = '$(git -C "$TENSORFLOW_DIR" describe)'" >> "$BUILD_DIR/tflite_runtime/__init__.py"
53+
54+
TERMUX_PKG_SRCDIR_OLD="$TERMUX_PKG_SRCDIR"
55+
TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR/tensorflow/lite"
56+
}
57+
58+
termux_step_post_configure() {
59+
TERMUX_PKG_SRCDIR="$TERMUX_PKG_SRCDIR_OLD"
60+
}
61+
62+
termux_step_make() {
63+
# Build python interpreter_wrapper
64+
cmake --build . -j $TERMUX_PKG_MAKE_PROCESSES -t _pywrap_tensorflow_interpreter_wrapper
65+
cp "$TERMUX_PKG_BUILDDIR/_pywrap_tensorflow_interpreter_wrapper.so" \
66+
"$TFLITE_BUILD_DIR/tflite_runtime"
67+
68+
# Build python wheel
69+
cd "$TFLITE_BUILD_DIR"
70+
python setup.py bdist_wheel
71+
}
72+
73+
termux_step_make_install() {
74+
local _pyver="${TERMUX_PYTHON_VERSION//./}"
75+
local _wheel="tflite_runtime-${TERMUX_PKG_VERSION}-cp${_pyver}-cp${_pyver}-linux_${TERMUX_ARCH}.whl"
76+
pip install --no-deps --prefix="$TERMUX_PREFIX" "$TFLITE_BUILD_DIR/dist/${_wheel}"
77+
}

0 commit comments

Comments
 (0)