Tensorflowlite移植ARM平臺iMX6

1、LINUX環境下操做:html

    1.安裝交叉編譯SDK (僅針對該型號:i.MX6,不一樣芯片須要對應的交叉編譯SDK)python

            編譯方法參考:手動編譯用於i.MX6系列的交叉編譯SDKlinux

     2.下載Tensorflowios

       git clone https://github.com/tensorflow/tensorflow.gitc++

       cd tensorflowgit

       git checkout r1.10github

      Tensorflow與Bazel編譯器(及CUDA,CUDNN)之間須要對應,不然會有兼容性問題。shell

          tensorflowr1.10     python 2.7,3.6   Bazel:0.18.0-0.19.2api

          tensorflowr1.12     python 2.7,3.6   Bazel:0.18.0-0.19.2bash

          tensorflowr1.14     python 2.7,3.6   Bazel:0.24.0 - 0.25.2

      三、下載並安裝編譯工具Bazel

          安裝依賴包:

                sudo apt-get install pkg-config zip g++ zilb1g-dev unzip

          下載Bazel包:

                wget https://github.com/bazelbuild/bazel/releases/download/0.18.1/bazel-0.181-installer-linux-86_64.sh

          安裝Bazel:

                 chmod +x bazel-0.18.1-installer-linux-86_64.sh

                 ./bazel-0.18.1-installer-linux-86_64.sh --user

          設置環境變量:

                 sudo vi ~/.bashrc,在文件最後添加:export PATH=$PATH":~/bin"

                 source ~/.bashrc

    (若是僅僅是測試DEMO在ARM板上使用,可直接跳過4,5,6,7,8步,直接進行第9步)

    四、編譯配置:

          在Tensorflow源碼根目錄運行:

             ./configure     (編譯LINUX平臺時使用默認設置:-march=native,編譯ARM平臺時需設置成相應值:-march=armv7-a)

     五、編譯pip:

          bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

     七、編譯包:

          ./bazel-bin/tensorflow/tools/pip__package/build_pip_package /tmp/tensorflow_pkg

     八、安裝包:

          pip install /tmp/tensorflow_pkg/tensorflow-version-tags.whl

     九、下載依賴庫:

         ./tensorflow/contrib/lite/tools/make/download_dependencies.sh(不一樣版本,位置略有不一樣,本文路徑爲r1.10版本)

     十、編譯Tensorflow Lite:

         方法1:(參考網上的,但我調試了幾天,並未生成該庫,可行性待驗證!)

                目前Tensorflow僅支持樹莓派: ./tensorflow/contrib/lite/tools/make/build_rpi_lib.sh,該腳本的目標編譯平臺是ARMv7,即便目標平臺是ARMv8,也不要更改。由於設置編譯平臺爲ARMv7能夠優化編譯,提升運行速度。

                因此,須要針對iMX6,製做一份build_imx6_lib.sh

1 set -e 2 
3 SCRIPT_DIR="$(cd "$(dirname "$(BASH_SOURCE[0]}")" && pwd)"
4 cd "$SCRIPT_DIR/../../.."
5 
6 CC_PREFIX=arm-poky-linux-gnueabi- make -j 3 -f tensorflow/contrib/lite/Makefile TARGET-imx6 TARGET_ARCH=armv7-a
View Code

                生成靜態庫位置爲:

               ./tensorflow/contrib/lite/toos/make/gen/rpi_arm7l/lib/libtensorflow-lite.a靜態庫。

         方法2:(使用ARM(iMX6)交叉編譯包,編譯出來的包能夠用於iMX6平臺)

                1.打開Tensorflow/contrib/lite/kernels/internal/BUILD

 1 config_setting(  2        name = "armv7a",  3        values = {"cpu":"armv7a",},  4 )  5 
 6 "armv7a":[  7     "-O3",  8     "-mfpu=vfpv3",  9     "-mfloat-abi=hard", 10 ], 11 
12 add code above to NEON_FLAGS_IF_APPLICABLE 13 
14 
15 ":armv6":[ 16 
17     ":neon_tensor_utils", 18  ], 19 ":armv7a":[ 20     ":neon_tensor_utils", 21 ], 22 
23 add code above to cc_library  tensor_utils select options
View Code

                2.在根目錄下建立一個文件:build_armv7_tflite.sh

 1 #!/bin/bash
 2 
 3 bazel build --copt="-fPIC" --copt="-march=armv6" \  4      --copt="-mfloat-abi=hard" \  5      --copt="-mfpu=vfpv3" \  6     --copt="-funsafe-math-optimizations" \  7      --copt="-Wno-unused-function" \  8      --copt="-Wno-sign-compare" \  9      --copt="-ftree-vectorize" \ 10      --copt="-fomit-frame-pointer" \ 11      --cxxopt='--std=c++11' \ 12      --cxxopt="-Wno-maybe-uninitialized" \ 13      --cxxopt="-Wno-narrowing" \ 14      --cxxopt="-Wno-unused" \ 15      --cxxopt="-Wno-comment" \ 16      --cxxopt="-Wno-unused-function" \ 17      --cxxopt="-Wno-sign-compare" \ 18      --cxxopt="-funsafe-math-optimizations" \ 19      --linkopt="-lstdc++" \ 20      --linkopt="-mfloat-abi=hard" \ 21      --linkopt="-mfpu=vfpv3" \ 22      --linkopt="-funsafe-math-optimizations" \ 23      --verbose_failures \ 24      --strip=always \ 25      --crosstool_top=//armv6-compiler:toolchain --cpu=armv7 --config=opt \ 26 33     tensorflow/contrib/lite/examples/label_image
View Code

                3.編譯該文件build_armv7_tflite.sh,會碰到一個錯誤:.../.../read-ld:unrecognized options : --icf=all

                   解決方法:找到文件./build_def.bzl ,打開,去除全部--icf=all標識的信息便可。

                   編譯後,會在bazel_bin下生成指定的文件label_image。

                4.生成頭和庫文件:      

                    libbuiltin_ops.a libframework.a libneon_tensor_utils.a libquantization_util.a libtensor_utils.a

                    libcontext.a libfarmhash.a libgemm_support.a libportable_tensor_utils.a  libstring_util.a

     十一、編譯模型:

          默認狀況下label_image並未編譯進去,須要修改Makefile,可參考minimal APK,主要修改如下三部份內容:

            LABELIMAGE_SRCS

            LABELIMAGE_BINARY

            LABEL_OBJS

 1 # Find where we're running from, so we can store generated files here.
 2 ifeq ($(origin MAKEFILE_DIR), undefined)  3     MAKEFILE_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))  4 endif  5 
 6 # Try to figure out the host system
 7 HOST_OS :=
 8 ifeq ($(OS),Windows_NT)  9     HOST_OS = WINDOWS  10 else
 11     UNAME_S := $(shell uname -s)  12  ifeq ($(UNAME_S),Linux)  13             HOST_OS := LINUX  14  endif  15  ifeq ($(UNAME_S),Darwin)  16         HOST_OS := OSX  17  endif  18 endif  19 
 20 #HOST_ARCH := $(shell if [[ $(shell uname -m) =~ i[345678]86 ]]; then echo x86_32; else echo $(shell uname -m); fi)
 21 
 22 # Self-hosting
 23 TARGET_ARCH := ${HOST_ARCH}  24 CROSS := imx6  25 $(warning "CROSS :$(CROSS) HOST_ARCH:$(HOST_ARCH) TARGET_ARCH:$(TARGET_ARCH) TARGET_TOOLCHAIN_PREFIX:$(TARGET_TOOLCHAIN_PREFIX)")  26 # Cross compiling
 27 ifeq ($(CROSS),imx6)  28   TARGET_ARCH := armv7-a  29   TARGET_TOOLCHAIN_PREFIX := arm-poky-linux-gnueabi-
 30 endif  31 
 32 ifeq ($(CROSS),rpi)  33   TARGET_ARCH := armv7l  34   TARGET_TOOLCHAIN_PREFIX := arm-linux-gnueabihf-
 35 endif  36 
 37 ifeq ($(CROSS),riscv)  38   TARGET_ARCH := riscv  39   TARGET_TOOLCHAIN_PREFIX := riscv32-unknown-elf-
 40 endif  41 ifeq ($(CROSS),stm32f7)  42   TARGET_ARCH := armf7  43   TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
 44 endif  45 ifeq ($(CROSS),stm32f1)  46   TARGET_ARCH := armm1  47   TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
 48 endif  49 
 50 # Where compiled objects are stored.
 51 OBJDIR := $(MAKEFILE_DIR)/gen/obj/
 52 BINDIR := $(MAKEFILE_DIR)/gen/bin/
 53 LIBDIR := $(MAKEFILE_DIR)/gen/lib/
 54 GENDIR := $(MAKEFILE_DIR)/gen/obj/
 55 
 56 LIBS :=
 57 ifeq ($(TARGET_ARCH),x86_64)  58         CXXFLAGS += -fPIC -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK -pthread # -msse4.2
 59 endif  60 
 61 
 62 ifeq ($(TARGET_ARCH),armv7-a)  63         CXXFLAGS += -pthread -fPIC  64     LIBS += -ldl  65 endif  66 
 67 ifeq ($(TARGET_ARCH),armv7l)  68         CXXFLAGS += -mfpu=neon -pthread -fPIC  69     LIBS += -ldl  70 endif  71 
 72 ifeq ($(TARGET_ARCH),riscv)  73 # CXXFLAGS += -march=gap8
 74         CXXFLAGS += -DTFLITE_MCU  75     LIBS += -ldl  76     BUILD_TYPE := micro  77 endif  78 
 79 ifeq ($(TARGET_ARCH),armf7)  80         CXXFLAGS += -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK -DTFLITE_MCU  81         CXXFLAGS += -fno-rtti -fmessage-length=0 -fno-exceptions -fno-builtin -ffunction-sections -fdata-sections  82         CXXFLAGS += -funsigned-char -MMD  83         CXXFLAGS += -mcpu=cortex-m7 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=softfp  84         CXXFLAGS += '-std=gnu++11' '-fno-rtti' '-Wvla' '-c' '-Wall' '-Wextra' '-Wno-unused-parameter' '-Wno-missing-field-initializers' '-fmessage-length=0' '-fno-exceptions' '-fno-builtin' '-ffunction-sections' '-fdata-sections' '-funsigned-char' '-MMD' '-fno-delete-null-pointer-checks' '-fomit-frame-pointer' '-Os'
 85     LIBS += -ldl  86     BUILD_TYPE := micro  87 endif  88 ifeq ($(TARGET_ARCH),armm1)  89         CXXFLAGS += -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK -mcpu=cortex-m1 -mthumb -DTFLITE_MCU  90         CXXFLAGS += -fno-rtti -fmessage-length=0 -fno-exceptions -fno-builtin -ffunction-sections -fdata-sections  91         CXXFLAGS += -funsigned-char -MMD  92     LIBS += -ldl  93 endif  94 
 95 # Settings for the host compiler.
 96 #CXX := $(CC_PREFIX) ${TARGET_TOOLCHAIN_PREFIX}g++
 97 #CXX := ${TARGET_TOOLCHAIN_PREFIX}g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi 
 98 CXXFLAGS += -O3 -DNDEBUG  99 CCFLAGS := ${CXXFLAGS} 100 #CXXFLAGS += --std=c++11
101 CXXFLAGS += --std=c++0x     #wly
102 #CC := ${TARGET_TOOLCHAIN_PREFIX}gcc
103 #AR := ${TARGET_TOOLCHAIN_PREFIX}ar
104 CFLAGS :=
105 LDOPTS :=
106 LDOPTS += -L/usr/local/lib 107 ARFLAGS := -r 108 
109 INCLUDES := \ 110 -I. \ 111 -I$(MAKEFILE_DIR)/../../../ \ 112 -I$(MAKEFILE_DIR)/downloads/ \ 113 -I$(MAKEFILE_DIR)/downloads/eigen \ 114 -I$(MAKEFILE_DIR)/downloads/gemmlowp \ 115 -I$(MAKEFILE_DIR)/downloads/neon_2_sse \ 116 -I$(MAKEFILE_DIR)/downloads/farmhash/src \ 117 -I$(MAKEFILE_DIR)/downloads/flatbuffers/include \ 118 -I$(GENDIR) 119 # This is at the end so any globally-installed frameworks like protobuf don't
120 # override local versions in the source tree.
121 #INCLUDES += -I/usr/local/include
122 INCLUDES += -I/usr/include 123 LIBS += \ 124 -lstdc++ \ 125 -lpthread \ 126 -lm \ 127 -lz 128 
129 # If we're on Linux, also link in the dl library.
130 ifeq ($(HOST_OS),LINUX) 131     LIBS += -ldl 132 endif 133 
134 include $(MAKEFILE_DIR)/ios_makefile.inc 135 ifeq ($(CROSS),rpi) 136 #include $(MAKEFILE_DIR)/rpi_makefile.inc
137 endif 138 ifeq ($(CROSS),imx6) 139 include $(MAKEFILE_DIR)/imx6_makefile.inc 140 endif 141 # This library is the main target for this makefile. It will contain a minimal
142 # runtime that can be linked in to other programs.
143 LIB_NAME := libtensorflow-lite.a 144 LIB_PATH := $(LIBDIR)$(LIB_NAME) 145 
146 # A small example program that shows how to link against the library.
147 MINIMAL_PATH := $(BINDIR)minimal 148 LABEL_IMAGE_PATH :=$(BINDIR)label_image 149 
150 MINIMAL_SRCS := \ 151 tensorflow/contrib/lite/examples/minimal/minimal.cc 152 MINIMAL_OBJS := $(addprefix $(OBJDIR), \ 153 $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(MINIMAL_SRCS)))) 154 
155 
156 LABEL_IMAGE_SRCS := \ 157 tensorflow/contrib/lite/examples/label_image/label_image.cc \ 158 tensorflow/contrib/lite/examples/label_image/bitmap_helpers.cc 159 LABEL_IMAGE_OBJS := $(addprefix $(OBJDIR), \ 160 $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(LABEL_IMAGE_SRCS)))) 161 
162 # What sources we want to compile, must be kept in sync with the main Bazel
163 # build files.
164 
165 PROFILER_SRCS := \ 166     tensorflow/contrib/lite/profiling/time.cc 167 PROFILE_SUMMARIZER_SRCS := \ 168     tensorflow/contrib/lite/profiling/profile_summarizer.cc \ 169     tensorflow/core/util/stats_calculator.cc 170 
171 CORE_CC_ALL_SRCS := \ 172 $(wildcard tensorflow/contrib/lite/*.cc) \ 173 $(wildcard tensorflow/contrib/lite/*.c) 174 ifneq ($(BUILD_TYPE),micro) 175 CORE_CC_ALL_SRCS += \ 176 $(wildcard tensorflow/contrib/lite/kernels/*.cc) \ 177 $(wildcard tensorflow/contrib/lite/kernels/internal/*.cc) \ 178 $(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.cc) \ 179 $(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.cc) \ 180 $(PROFILER_SRCS) \ 181 $(wildcard tensorflow/contrib/lite/kernels/*.c) \ 182 $(wildcard tensorflow/contrib/lite/kernels/internal/*.c) \ 183 $(wildcard tensorflow/contrib/lite/kernels/internal/optimized/*.c) \ 184 $(wildcard tensorflow/contrib/lite/kernels/internal/reference/*.c) \ 185 $(wildcard tensorflow/contrib/lite/downloads/farmhash/src/farmhash.cc) \ 186 $(wildcard tensorflow/contrib/lite/downloads/fft2d/fftsg.c) 187 endif 188 # Remove any duplicates.
189 CORE_CC_ALL_SRCS := $(sort $(CORE_CC_ALL_SRCS)) 190 CORE_CC_EXCLUDE_SRCS := \ 191 $(wildcard tensorflow/contrib/lite/*test.cc) \ 192 $(wildcard tensorflow/contrib/lite/*/*test.cc) \ 193 $(wildcard tensorflow/contrib/lite/*/*/*test.cc) \ 194 $(wildcard tensorflow/contrib/lite/*/*/*/*test.cc) \ 195 $(wildcard tensorflow/contrib/lite/kernels/test_util.cc) \ 196 $(MINIMAL_SRCS) \ 197 $(LABEL_IMAGE_SRCS) 198 ifeq ($(BUILD_TYPE),micro) 199 CORE_CC_EXCLUDE_SRCS += \ 200 tensorflow/contrib/lite/model.cc \ 201 tensorflow/contrib/lite/nnapi_delegate.cc 202 endif 203 # Filter out all the excluded files.
204 TF_LITE_CC_SRCS := $(filter-out $(CORE_CC_EXCLUDE_SRCS), $(CORE_CC_ALL_SRCS)) 205 # File names of the intermediate files target compilation generates.
206 TF_LITE_CC_OBJS := $(addprefix $(OBJDIR), \ 207 $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(TF_LITE_CC_SRCS)))) 208 LIB_OBJS := $(TF_LITE_CC_OBJS) 209 
210 # Benchmark sources
211 BENCHMARK_SRCS_DIR := tensorflow/contrib/lite/tools/benchmark 212 BENCHMARK_ALL_SRCS := $(TFLITE_CC_SRCS) \ 213     $(wildcard $(BENCHMARK_SRCS_DIR)/*.cc) \ 214  $(PROFILE_SUMMARIZER_SRCS) 215 
216 BENCHMARK_SRCS := $(filter-out \ 217     $(wildcard $(BENCHMARK_SRCS_DIR)/*_test.cc), \ 218  $(BENCHMARK_ALL_SRCS)) 219 
220 BENCHMARK_OBJS := $(addprefix $(OBJDIR), \ 221 $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(BENCHMARK_SRCS)))) 222 
223 # For normal manually-created TensorFlow C++ source files.
224 $(OBJDIR)%.o: %.cc 225     @mkdir -p $(dir $@) 226     $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ 227 # For normal manually-created TensorFlow C++ source files.
228 $(OBJDIR)%.o: %.c 229     @mkdir -p $(dir $@) 230     $(CC) $(CCFLAGS) $(INCLUDES) -c $< -o $@ 231 
232 # The target that's compiled if there's no command-line arguments.
233 all: $(LIB_PATH) $(MINIMAL_PATH) $(LABEL_IMAGE_PATH) $(BENCHMARK_BINARY) 234 
235 # The target that's compiled for micro-controllers
236 micro: $(LIB_PATH) 237 
238 # Gathers together all the objects we've compiled into a single '.a' archive.
239 $(LIB_PATH): $(LIB_OBJS) 240     @mkdir -p $(dir $@) 241  $(AR) $(ARFLAGS) $(LIB_PATH) $(LIB_OBJS) 242 
243 $(MINIMAL_PATH): $(MINIMAL_OBJS) $(LIB_PATH) 244     @mkdir -p $(dir $@) 245  $(CXX) $(CXXFLAGS) $(INCLUDES) \ 246     -o $(MINIMAL_PATH) $(MINIMAL_OBJS) \ 247  $(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS) 248 
249 # $(LABEL_IMAGE_PATH): $(LABEL_IMAGE_OBJS) $(LIBS)
250 
251 $(LABEL_IMAGE_PATH) : $(LABEL_IMAGE_OBJS) $(LIB_PATH) 252     @mkdir -p $(dir $@) 253  $(CXX) $(CXXFLAGS) $(INCLUDES) \ 254     -o $(LABEL_IMAGE_PATH) $(LABEL_IMAGE_OBJS)\ 255  $(LIBFLAGS) $(LIB_PATH) $(LDFLAGS) $(LIBS) 256 
257 
258 $(BENCHMARK_LIB) : $(LIB_PATH) $(BENCHMARK_OBJS) 259     @mkdir -p $(dir $@) 260  $(AR) $(ARFLAGS) $(BENCHMARK_LIB) $(LIB_OBJS) $(BENCHMARK_OBJS) 261 
262 benchmark_lib: $(BENCHMARK_LIB) 263 $(info $(BENCHMARK_BINARY)) 264 $(BENCHMARK_BINARY) : $(BENCHMARK_LIB) 265     @mkdir -p $(dir $@) 266  $(CXX) $(CXXFLAGS) $(INCLUDES) \ 267     -o $(BENCHMARK_BINARY) \ 268  $(LIBFLAGS) $(BENCHMARK_LIB) $(LDFLAGS) $(LIBS) 269 
270 benchmark: $(BENCHMARK_BINARY) 271 
272 # Gets rid of all generated files.
273 clean: 274     rm -rf $(MAKEFILE_DIR)/gen 275 
276 # Gets rid of target files only, leaving the host alone. Also leaves the lib
277 # directory untouched deliberately, so we can persist multiple architectures
278 # across builds for iOS and Android.
279 cleantarget: 280     rm -rf $(OBJDIR) 281     rm -rf $(BINDIR) 282 
283 $(DEPDIR)/%.d: ; 284 .PRECIOUS: $(DEPDIR)/%.d 285 
286 -include $(patsubst %,$(DEPDIR)/%.d,$(basename $(TF_CC_SRCS)))
View Code

          執行: ./tensorflow/contrib/lite/tools/make/build_imx6_lib.sh

          編譯過程當中可能會出現一些問題,依次解決便可!

          編譯完成後,在./tensorflow/contrib/lite/tools/make/gen/rpi_arm7l/bin  目錄下生成可執行文件label_img

          附上本身碰到的一些問題:

             一、a/tensorflow/contrib/lite/tools/benchmark/benchmark_params.h

 1 diff --git a/tensorflow/contrib/lite/profiling/profile_summarizer.cc b/tensorflow/contrib/lite/profiling/profile_summarizer.cc  2 old mode 100644
 3 new mode 100755
 4 index c37a096..590cd21  5 --- a/tensorflow/contrib/lite/profiling/profile_summarizer.cc  6 +++ b/tensorflow/contrib/lite/profiling/profile_summarizer.cc  7 @@ -83,7 +83,8 @@ OperatorDetails GetOperatorDetails(const tflite::Interpreter& interpreter,  8  OperatorDetails details;  9    details.name = op_name; 10    if (profiling_string) { 11 -    details.name += ":" + string(profiling_string); 12 +    //wly 13 +    details.name += ":" + std::string(profiling_string); 14  } 15    details.inputs = GetTensorNames(interpreter, inputs); 16    details.outputs = GetTensorNames(interpreter, outputs);
View Code

             二、./tensorflow/contrib/lite/profiling/profile_summarizer.cc

 1 diff --git a/tensorflow/contrib/lite/tools/benchmark/benchmark_params.h b/tensorflow/contrib/lite/tools/benchmark/benchmark_params.h  2 old mode 100644
 3 new mode 100755
 4 index 33448dd..e7f63ff  5 --- a/tensorflow/contrib/lite/tools/benchmark/benchmark_params.h  6 +++ b/tensorflow/contrib/lite/tools/benchmark/benchmark_params.h  7 @@ -47,7 +47,8 @@ class BenchmarkParam {  8    virtual ~BenchmarkParam() {}  9  BenchmarkParam(ParamType type) : type_(type) {} 10  
11 - private: 12 + //private: 13 + public:        //wly 14  static void AssertHasSameType(ParamType a, ParamType b); 15    template <typename T>
16    static ParamType GetValueType();
View Code

             三、./tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h

 1 diff --git a/tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h b/tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h  2 old mode 100644
 3 new mode 100755
 4 index 2d40f17..43c54dc  5 --- a/tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h  6 +++ b/tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h  7 @@ -24,8 +24,9 @@ limitations under the License.  8  #include <type_traits>
 9  
10 - #include "third_party/eigen3/Eigen/Core"
11 +//#include "third_party/eigen3/Eigen/Core"" 
12  #include "tensorflow/contrib/lite/kernels/internal/common.h"
13  #include "tensorflow/contrib/lite/kernels/internal/quantization_util.h"
14  #include "tensorflow/contrib/lite/kernels/internal/round.h"
View Code

             四、須要下載包:protobuf

             五、將c++11  改成c++0x

     十二、在PC上測試label_image

          ./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./grace_hopper.jpg -l ./imagenet_slim_labels.txt

          報錯信息: bash ./label_image: cannot execute binary file:Exec format error

          緣由有兩個:   

              一是GCC編譯時多加了一個-C,生成了二進制文件;

                     解決方法:找到GCC編譯處,去除-C選項。

              二就是編譯環境不一樣(平臺芯片不一致)致使

                     解決方法:須要在對應平臺編譯。

                            在tensorflow根目錄執行:bazel build tensorflow/examples/label_image:label_image

                            若是是第一次編譯,時間較久;

                            編譯完成後,生成可執行文件:bazel_bin/tensorflow/examples/label_image/label_image

              本地測試該文件:

                      拷貝label_image和libtensorflow_framework.so到tensorflow/examples/label_image下

                      (第一次測試時,未拷貝libtensorflow_framework.so,直接提示:error while loading shared libraryies:libtensorflow_framework.so:cannot open shared object file:No such file or directory)

                      再次運行./tensorflow/examples/label_image/label_image

                       顯示結果:military uniform(653):0.834306

                                         mortarboard(668):0.0218695

                                         academic gown(401):0.0103581

                                         pickelhaube(716):0.00800814

                                         bulletproof vest(466):0.00535084

                        說明測試OK!

      

如下操做在ARM板子上:

      一、拷貝生成的label_image到板子上(bazel_bin/tensorflow/contrib/lite/examples/label_image/)(1.7M)

            拷貝生成的label_image到板子上(bazel_bin/tensorflow/examples/label_image)(52.2M)

      二、拷貝圖片./tensorflow/examples/label_image/data/grace_hopper.jpg到板子上  

      三、下載模型mobilenet_quant_v1_224.tflite

          (若是下載其它模型,可參考該文件:/tensorflow/contrib/lite/g3doc/models.md)

      四、下載模型所需文件:

             curl -L "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz" | tar -C tensorflow/examples/label_image/data -xz

      五、拷貝libtensorflow_framework.so到板子上,文件位於目錄bazel_bin/tensorflow/下(14M)

      四、運行label_image

        確保以下所需文件都已完成:

      (拷貝文件1:label_image)

      (拷貝文件2:grace_hopper.jpg)

      (拷貝文件3:mobilenet_quant_v1_224.tflite)

      (拷貝文件4:imagenet_slim_labels.txt)

      (拷貝文件5:libtensorflow_framework.so)

        ARM板上經常使用操做:

        mount /dev/sba1 /mnt/usb

        ls /mnt/usb

        cp /mnt/usb/   .

        執行腳本:

            ./label_image

           若是出現-sh: ./label_image: not found,多是編譯器不一致致使。

           嘗試方法1:重定向:ln -s ld-linux.so.3 ld-linux-armhf.so.3

               新報錯:./label_image:/lib/libm.so.6: version 'GLIBC_2.27' not found (required by ./label_image)

           出現如下信息,說明已經OK,恭喜你!

      

相關文章
相關標籤/搜索