在早期版本,比如1.12上,按照官方的教程操作,基本可以稳稳编译通过;
(路径改成./tensorflow/contirb/lite/)
本地编译
这已经在Raspberry Pi 3b,Raspbian GNU / Linux 9.1(stretch),gcc版本6.3.0 20170516(Raspbian 6.3.0-18 + rpi1)上进行了测试。 登录Raspberry Pi,安装工具链。
sudo apt-get install build-essential
首先,克隆TensorFlow库。在库的根目录运行:
./tensorflow/lite/tools/make/download_dependencies.sh
请注意,您只需要执行一次此操作。 然后您便能够编译:
./tensorflow/lite/tools/make/build_rpi_lib.sh
这将编译一个静态库,它位于: tensorflow/lite/tools/make/gen/lib/rpi_armv7/libtensorflow-lite.a 。
1) Dowload dependencies时 eigen下载失败
修改tensorflow/worksapce.bzl
"http://mirror.tensorflow.org/bitbucket.org/eigen/eigen/get/a0d250e79c79.tar.gz"
这个链接失效了,把它和另外一个链接调整下位置
tf_http_archive(
name = "eigen_archive",
build_file = clean_dep("//third_party:eigen.BUILD"),
patch_file = clean_dep("//third_party/eigen3:gpu_packet_math.patch"),
sha256 = "0dde8fb87f5dad2e409c9f4ea1bebc54e694cf4f3b633081b0d51a55c00f9c9f",
strip_prefix = "eigen-eigen-a0d250e79c79",
urls = [
"https://bitbucket.org/eigen/eigen/get/a0d250e79c79.tar.gz",
"http://mirror.tensorflow.org/bitbucket.org/eigen/eigen/get/a0d250e79c79.tar.gz",
],
)
2) build_rpi_lib.sh 报错: 找不到
在./tensorflow/lite/tools/make/Makefile的include相关配置的地方加上:
-I$(MAKEFILE_DIR)/downloads/googletest/googletest/include \
-I$(MAKEFILE_DIR)/downloads/googletest/googlemock/include \
3)build_rpi_lib.sh 报错:undefined reference to `flatbuffers::ClassicLocale::instance_'
修改./tensorflow/lite/tools/make/Makefile
- add
$(wildcard tensorflow/lite/tools/make/downloads/flatbuffers/src/util.cpp)
at ther end of CORE_CC_ALL_SRC - change LIB_OBJS and BENCHMARK_OBJS to
$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(TF_LITE_CC_SRCS)))))
and$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(BENCHMARK_SRCS)))))
- add
$(OBJDIR)%.o: %.cpp @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
near other OBJDIR declarations.
#LIB_OBJS := $(addprefix $(OBJDIR), \
#$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(TF_LITE_CC_SRCS))))
LIB_OBJS := $(addprefix $(OBJDIR), \
$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(TF_LITE_CC_SRCS)))))
#BENCHMARK_OBJS := $(addprefix $(OBJDIR), \
#$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(BENCHMARK_SRCS))))
BENCHMARK_OBJS := $(addprefix $(OBJDIR),\
$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(BENCHMARK_SRCS)))))
# For normal manually-created TensorFlow Lite CPP source files.
$(OBJDIR)%.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
4) build_rpi_lib.sh 报错:
arm-linux-gnueabihf-g++ -O3 -DNDEBUG -fPIC --std=c++11 -march=armv7-a -mfpu=neon-vfpv4 -funsafe-math-optimizations -ftree-vectorize -fPIC -I. -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/../../../../../ -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/../../../../../../ -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/ -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/eigen -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/absl -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/gemmlowp -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/neon_2_sse -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/farmhash/src -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/flatbuffers/include -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/googletest/googletest/include -I/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/downloads/googletest/googlemock/include -I -I/usr/local/include \
-o /home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/gen/rpi_armv7l/bin/benchmark_model \
/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/benchmark-lib.a -Wl,--no-export-dynamic -Wl,--exclude-libs,ALL -Wl,--gc-sections -Wl,--as-needed -lstdc++ -lpthread -lm -ldl
/home/pi/Develop/tensorflow-r1.14/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/benchmark-lib.a(test_main.o):在函数‘main’中:
test_main.cc:(.text.startup+0x20):对‘testing::InitGoogleTest(int*, char**)’未定义的引用
test_main.cc:(.text.startup+0x2b4):对‘tflite::SingleOpModel::SetForceUseNnapi(bool)’未定义的引用
test_main.cc:(.text.startup+0x2c0):对‘testing::UnitTest::GetInstance()’未定义的引用
test_main.cc:(.text.startup+0x2c4):对‘testing::UnitTest::Run()’未定义的引用
去掉makefile里面对test_main.cc的编译
在CORE_CC_EXCLUDE_SRCS中加入$(wildcard tensorflow/lite/kernels/test_main.cc)
# Remove any duplicates.
CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS))
CORE_CC_EXCLUDE_SRCS := \
$(wildcard tensorflow/lite/*test.cc) \
$(wildcard tensorflow/lite/*/*test.cc) \
$(wildcard tensorflow/lite/*/*/*test.cc) \
$(wildcard tensorflow/lite/*/*/*/*test.cc) \
$(wildcard tensorflow/lite/kernels/*test_util.cc) \
$(wildcard tensorflow/lite/kernels/test_main.cc) \
$(MINIMAL_SRCS)