下面都在linux主機上操作
安裝交叉編譯工具
sudo apt-get install g++-arm-linux-gnueabihf
sudo apt-get install -y gcc-arm-linux-gnueabihf
下載TensorFlow
https://github.com/tensorflow/tensorflow
我用這個的樹莓派編譯版會報錯NNAPI的錯誤:
/tensorflow/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a(nnapi_delegate.o): In function tflite::NNAPIAllocation::~NNAPIAllocation()': nnapi_delegate.cc:(.text+0x2c): undefined reference to NnApiImplementation()'
/tensorflow/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a(nnapi_delegate.o): In function tflite::NNAPIAllocation::NNAPIAllocation(char const*, tflite::ErrorReporter*)': nnapi_delegate.cc:(.text+0x110): undefined reference to NnApiImplementation()'
/tensorflow/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a(nnapi_delegate.o): In function tflite::NNAPIDelegate::~NNAPIDelegate()': nnapi_delegate.cc:(.text+0x190): undefined reference to NnApiImplementation()'
nnapi_delegate.cc:(.text+0x1b4): undefined reference to NnApiImplementation()' /tensorflow/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a(nnapi_delegate.o): In function tflite::addTensorOperands(tflite::Subgraph*, ANeuralNetworksModel*, unsigned int*, std::vector<long long, std::allocator >*)':
根據(jù)TensorFlow github上的issue: https://github.com/tensorflow/tensorflow/issues/25120 中大家的說法腐碱,把NNAPI屏蔽了就可以工腋,但是我屏蔽了還是不行。。。
于是要出,只好下載了老版本的TensorFlow奄毡,用的v1.12.0: https://github.com/tensorflow/tensorflow/tree/bcdc3cd17aec1e062928cb994d06499f9a62efd5/tensorflow
下載依賴庫
這個文件的位置好像一直在變商蕴。網(wǎng)絡(luò)上參考的位置與我找到的位置不同出革。最新版的位置也與我用的v1.12.0的位置不同造壮。
最新版的位置可以參考:https://tensorflow.google.cn/lite/guide/build_rpi
./tensorflow/contrib/lite/tools/make/download_dependencies.sh
編譯TensorFlow Lite
文件位置與前面依賴庫文件位置一致。
./tensorflow/contrib/lite/tools/make/build_rpi_lib.sh
生成的靜態(tài)庫位置為
./tensorflow/contrib/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a
編譯模型
可以在./tensorflow/contrib/lite/tools/make/gen/rpi_armv7l/bin/
下面生成可執(zhí)行文件label_image
下面都在 LC1860C板子上操作
把生成的label_image
拷貝到板子上蹋盆,
拷貝圖片./tensorflow/examples/label_image/data/grace_hopper.jpg
到板子上
從./tensorflow/contrib/lite/g3doc/models.md
下載模型mobilenet_v1_1.0_224.tflite
拷貝模型mobilenet_v1_1.0_224.tflite
到板子上
下載模型所需文件:
$ 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
拷貝標簽文件./tensorflow/examples/label_image/data/imagenet_slim_labels.txt
到板子上
運行label_image
./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./grace_hopper.jpg-l ./imagenet_slim_labels.txt
報錯:
[root@dtvl3000 ~/TensorFlowLite]#./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./grace_hopper.jpg -l ./imagenet_slim_labels.txt
-sh: ./label_image: not found
經(jīng)過排查是因為編譯器不一致導(dǎo)致的费薄。重定向:
[root@dtvl3000 /lib]#ln -s ld-linux.so.3 ld-linux-armhf.so.3
再次運行報錯:
[root@dtvl3000 ~/TensorFlowLite]#./label_image -v 1 -m ./mobilenet_v1_1.0_224.tflite -i ./grace_hopper.jpg -l ./imagenet_slim_labels.txt
./label_image: /lib/libm.so.6: version `GLIBC_2.27' not found (required by ./label_image)
./label_image: /lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./label_image)
./label_image: /lib/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by ./label_image)
本來后面還要再繼續(xù)更新GLIBC庫的硝全,但是發(fā)現(xiàn)真的是無窮無盡了栖雾。
于是我重新?lián)Q了塊更新的板子,再沒有這個問題了伟众,所以其實移植到LC1860C上是失敗了析藕。。
換了另一塊新的板子后凳厢,又遇到了新的問題账胧,不過這就是下一篇文章的內(nèi)容了。
當然先紫,如果后續(xù)公司還是堅持要在LC1860C上跑治泥,那我只能來繼續(xù)這篇文章了。