一. 编译tensorflow静态库
1. 开发环境: ubuntu16.04, 安装Hi3559A交叉编译工具aarch64-himix100-linux-
2. 下载源码: git clone https://github.com/tensorflow/tensorflow
3. 安装curl: apt-get install curl
4. 下载依赖包, 源码根目录执行: ./tensorflow/lite/tools/make/download_dependencies.sh
5. 修改交叉编译工具: tensorflow/lite/tools/make/targets/rpi_makefile.inc
TARGET_TOOLGHAIN_PREFIX := arm-linux-gnueabihf- 改为 TARGET_TOOLGHAIN_PREFIX := aarch64-himix100-linux-
屏蔽对应TARGET_ARCH(如armv7l,默认值)的CXXFLAGS和CCFLAGS中的-march和-mfpu参数,如下
# -march=armv7-a \
# -mfpu=neon-vfpv4 \
6. 编译: ./tensorflow/lite/tools/make/build_rpi_lib.sh
8. 生成静态库路径: tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a
二. 编译tensorflow中的label_image测试用例: tensorflow/lite/examples/label_image
1. vim tensorflow/lite/tools/make/Makefile
76! LABEL_IMAGE_SRCS := \
77! tensorflow/lite/examples/label_image/label_image.cc \
78! tensorflow/lite/examples/label_image/bitmap_helpers.cc
118! $(LABEL_IMAGE_SRCS)
149! $(LABEL_IMAGE_SRCS) \
165! LABEL_IMAGE_BINARY := $(BINDIR)label_image
174! LABEL_IMAGE_OBJS := $(addprefix $(OBJDIR), \
175! $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(LABEL_IMAGE_SRCS))))
193! all: $(LIB_PATH) $(MINIMAL_BINARY) $(BENCHMARK_BINARY) $(LABEL_IMAGE_BINARY)
213! $(LABEL_IMAGE_BINARY): $(LABEL_IMAGE_OBJS) $(LIB_PATH)
214! @mkdir -p $(dir $@)
215! $(CXX) $(CXXFLAGS) $(INCLUDES) \
216! -o $(LABEL_IMAGE_BINARY) $(LABEL_IMAGE_OBJS) \
217! $(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS)
2. 编译: ./tensorflow/lite/tools/make/build_rpi_lib.sh
3. 生成可执行文件路径: tensorflow/lite/tools/make/gen/rpi_armv7l/bin/label_image
4. 测试把生成的执行文件label_image和模型文件mobilenet_v1_1.0_224.tflite以及图片tensorflow/lite/examples/label_image/testdata/grace_hopper.bmp和tensorflow/lite/java/ovic/src/testdata/labels.txt拷贝到开发板,执行: ./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./grace_hopper.bmp -l ./labels.txt