diff --git a/tensorflow/lite/python/interpreter.py b/tensorflow/lite/python/interpreter.py index 63e54b5fef7..23a654e3035 100644 --- a/tensorflow/lite/python/interpreter.py +++ b/tensorflow/lite/python/interpreter.py @@ -40,7 +40,7 @@ try: except ImportError: # When full Tensorflow Python PIP is not available do not use lazy load # and instead of the tflite_runtime path. - from tflite_runtime.lite.python import interpreter_wrapper as _interpreter_wrapper + from tflite_runtime import interpreter_wrapper as _interpreter_wrapper def tf_export_dummy(*x, **kwargs): del x, kwargs diff --git a/tensorflow/lite/tools/make/Makefile b/tensorflow/lite/tools/make/Makefile index 38fb48f9703..393a66255b1 100644 --- a/tensorflow/lite/tools/make/Makefile +++ b/tensorflow/lite/tools/make/Makefile @@ -79,7 +79,7 @@ BENCHMARK_BINARY_NAME := benchmark_model # A small example program that shows how to link against the library. MINIMAL_SRCS := \ -tensorflow/lite/examples/minimal/minimal.cc + tensorflow/lite/examples/minimal/minimal.cc # What sources we want to compile, must be kept in sync with the main Bazel # build files. @@ -91,7 +91,7 @@ PROFILE_SUMMARIZER_SRCS := \ tensorflow/core/util/stats_calculator.cc CMD_LINE_TOOLS_SRCS := \ - tensorflow/lite/tools/command_line_flags.cc + tensorflow/lite/tools/command_line_flags.cc CORE_CC_ALL_SRCS := \ $(wildcard tensorflow/lite/*.cc) \ @@ -99,19 +99,19 @@ $(wildcard tensorflow/lite/*.c) \ $(wildcard tensorflow/lite/c/*.c) \ $(wildcard tensorflow/lite/core/*.cc) \ $(wildcard tensorflow/lite/core/api/*.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/allocator.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/block_map.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/blocking_counter.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/context.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/detect_dotprod.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/kernel.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/pack.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/pmu.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/thread_pool.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/trace.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/trmul.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/tune.cc) \ -$(wildcard tensorflow/lite/experimental/ruy/wait.cc) +tensorflow/lite/experimental/ruy/allocator.cc \ +tensorflow/lite/experimental/ruy/block_map.cc \ +tensorflow/lite/experimental/ruy/blocking_counter.cc \ +tensorflow/lite/experimental/ruy/context.cc \ +tensorflow/lite/experimental/ruy/detect_dotprod.cc \ +tensorflow/lite/experimental/ruy/kernel.cc \ +tensorflow/lite/experimental/ruy/pack.cc \ +tensorflow/lite/experimental/ruy/pmu.cc \ +tensorflow/lite/experimental/ruy/thread_pool.cc \ +tensorflow/lite/experimental/ruy/trace.cc \ +tensorflow/lite/experimental/ruy/trmul.cc \ +tensorflow/lite/experimental/ruy/tune.cc \ +tensorflow/lite/experimental/ruy/wait.cc ifneq ($(BUILD_TYPE),micro) CORE_CC_ALL_SRCS += \ $(wildcard tensorflow/lite/kernels/*.cc) \ @@ -119,13 +119,9 @@ $(wildcard tensorflow/lite/kernels/internal/*.cc) \ $(wildcard tensorflow/lite/kernels/internal/optimized/*.cc) \ $(wildcard tensorflow/lite/kernels/internal/reference/*.cc) \ $(PROFILER_SRCS) \ -$(wildcard tensorflow/lite/kernels/*.c) \ -$(wildcard tensorflow/lite/kernels/internal/*.c) \ -$(wildcard tensorflow/lite/kernels/internal/optimized/*.c) \ -$(wildcard tensorflow/lite/kernels/internal/reference/*.c) \ -$(wildcard tensorflow/lite/tools/make/downloads/farmhash/src/farmhash.cc) \ -$(wildcard tensorflow/lite/tools/make/downloads/fft2d/fftsg.c) \ -$(wildcard tensorflow/lite/tools/make/downloads/flatbuffers/src/util.cpp) +tensorflow/lite/tools/make/downloads/farmhash/src/farmhash.cc \ +tensorflow/lite/tools/make/downloads/fft2d/fftsg.c \ +tensorflow/lite/tools/make/downloads/flatbuffers/src/util.cpp endif # Remove any duplicates. CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS)) @@ -138,7 +134,7 @@ $(wildcard tensorflow/lite/kernels/*test_main.cc) \ $(wildcard tensorflow/lite/kernels/*test_util.cc) \ $(MINIMAL_SRCS) -BUILD_WITH_MMAP=true +BUILD_WITH_MMAP ?= true ifeq ($(BUILD_TYPE),micro) BUILD_WITH_MMAP=false endif @@ -151,7 +147,7 @@ else CORE_CC_EXCLUDE_SRCS += tensorflow/lite/mmap_allocation_disabled.cc endif -BUILD_WITH_NNAPI=true +BUILD_WITH_NNAPI ?= true ifeq ($(BUILD_TYPE),micro) BUILD_WITH_NNAPI=false endif @@ -191,7 +187,7 @@ EVALUATION_UTILS_SRCS := \ BENCHMARK_ALL_SRCS := $(TF_LITE_CC_SRCS) \ $(wildcard $(BENCHMARK_SRCS_DIR)/*.cc) \ $(PROFILE_SUMMARIZER_SRCS) \ - $(CMD_LINE_TOOLS_SRCS) \ + $(CMD_LINE_TOOLS_SRCS) \ $(EVALUATION_UTILS_SRCS) BENCHMARK_SRCS := $(filter-out \ diff --git a/tensorflow/lite/tools/make/build_aarch64_lib.sh b/tensorflow/lite/tools/make/build_aarch64_lib.sh index 054b3daedf8..0ce4089c11c 100755 --- a/tensorflow/lite/tools/make/build_aarch64_lib.sh +++ b/tensorflow/lite/tools/make/build_aarch64_lib.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # Copyright 2017 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,11 @@ # limitations under the License. # ============================================================================== +set -x set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR/../../../.." +TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.." + +make -j 4 TARGET=aarch64 -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile -CC_PREFIX=aarch64-linux-gnu- make -j 3 -f tensorflow/lite/tools/make/Makefile TARGET=aarch64 TARGET_ARCH=armv8-a diff --git a/tensorflow/lite/tools/make/build_lib.sh b/tensorflow/lite/tools/make/build_lib.sh new file mode 100755 index 00000000000..7fdd262ee9c --- /dev/null +++ b/tensorflow/lite/tools/make/build_lib.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Copyright 2017 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +set -x +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.." + +make -j 4 BUILD_WITH_NNAPI=false -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile + diff --git a/tensorflow/lite/tools/make/build_rpi_lib.sh b/tensorflow/lite/tools/make/build_rpi_lib.sh index 1521bb39332..c7edc6755e9 100755 --- a/tensorflow/lite/tools/make/build_rpi_lib.sh +++ b/tensorflow/lite/tools/make/build_rpi_lib.sh @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # Copyright 2017 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,9 +14,11 @@ # limitations under the License. # ============================================================================== +set -x set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR/../../../.." +TENSORFLOW_DIR="${SCRIPT_DIR}/../../../.." + +make -j 4 TARGET=rpi -C "${TENSORFLOW_DIR}" -f tensorflow/lite/tools/make/Makefile -CC_PREFIX=arm-linux-gnueabihf- make -j 3 -f tensorflow/lite/tools/make/Makefile TARGET=rpi TARGET_ARCH=armv7l diff --git a/tensorflow/lite/tools/pip_package/README.md b/tensorflow/lite/tools/pip_package/README.md index 8190782c39f..adab810126a 100644 --- a/tensorflow/lite/tools/pip_package/README.md +++ b/tensorflow/lite/tools/pip_package/README.md @@ -18,8 +18,8 @@ pip install --upgrade Note, unlike tensorflow this will be installed to a tflite_runtime namespace. You can then use the Tensorflow Lite interpreter as. ``` -import tflite_runtime as tflr -interpreter = tflr.lite.Interpreter(model_path="foo.tflite") +from tflite_runtime import interpreter as tflr +interpreter = tflr.Interpreter(model_path="foo.tflite") ``` This currently works to build on Linux machines including Raspberry Pi. In diff --git a/tensorflow/lite/tools/pip_package/build_pip_package.sh b/tensorflow/lite/tools/pip_package/build_pip_package.sh index 2887ce84712..1cb3866af73 100644 --- a/tensorflow/lite/tools/pip_package/build_pip_package.sh +++ b/tensorflow/lite/tools/pip_package/build_pip_package.sh @@ -16,39 +16,36 @@ set -e +PYTHON="${PYTHON:-python}" + # Find where this script lives and then the Tensorflow root. -MY_DIRECTORY=`dirname $0` -export TENSORFLOW_SRC_ROOT=`realpath $MY_DIRECTORY/../../../..` +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -export TENSORFLOW_VERSION=`grep "_VERSION = " $TENSORFLOW_SRC_ROOT/tensorflow/tools/pip_package/setup.py | cut -d'=' -f 2 | sed "s/[ '-]//g"`; +export TENSORFLOW_SRC_ROOT="${SCRIPT_DIR}/../../../.." +export TENSORFLOW_VERSION=`grep "_VERSION = " "${TENSORFLOW_SRC_ROOT}/tensorflow/tools/pip_package/setup.py" | cut -d'=' -f 2 | sed "s/[ '-]//g"`; +TFLITE_ROOT="${TENSORFLOW_SRC_ROOT}/tensorflow/lite" # Build a pip build tree. -BUILD_ROOT=/tmp/tflite_pip -rm -rf $BUILD_ROOT -mkdir -p $BUILD_ROOT/tflite_runtime/lite -mkdir -p $BUILD_ROOT/tflite_runtime/lite/python +BUILD_ROOT="/tmp/tflite_pip/${PYTHON}" +rm -rf "${BUILD_ROOT}" +mkdir -p "${BUILD_ROOT}/tflite_runtime/" -# Build an importable module tree -cat > $BUILD_ROOT/tflite_runtime/__init__.py < $BUILD_ROOT/tflite_runtime/lite/__init__.py < $BUILD_ROOT/tflite_runtime/lite/python/__init__.py <