我希望在RPi3上安装TF Lite,以进行实时图像识别。
我关注了:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/g3doc/rpi.md
所有已编译的libtensorflow-lite.a成功构建。
尝试运行初始示例应用程序:
/etc/hosts
我得到:
python label_image.py
我不确定的是:
答案 0 :(得分:1)
对不起,我不了解Stack Overflow的规则。
我修改了评论,但如果评论者不喜欢,请删除它。
可以通过官方pip命令引入的“ Tensorflow v1.11.0”引起了问题。
undefined symbol: _ZN6tflite12tensor_utils39NeonMatrixBatchVectorMultiplyAccumulateEPKaiiS2_PKfiPfi
点子包装似乎已损坏。
Tensorflow Lite的构建过程如下。
1。执行下面的
$ sudo apt update;sudo apt upgrade -y
$ sudo apt-get install -y build-essential openjdk-8-jdk pkg-config
zip g++ zlib1g-dev unzip
2。重启终端。
3。执行以下操作。 (需要运行两次)
$ sudo apt-get install -y openjdk-8-jdk
4.Bazel构建。
$ cd ~
$ mkdir bazel;cd bazel
$ wget https://github.com/bazelbuild/bazel/releases/download/0.17.2/bazel-0.17.2-dist.zip
$ unzip bazel-0.17.2-dist.zip
$ nano bazel/scripts/bootstrap/compile.sh
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}"
↓
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}" -J-Xmx500M
$ sudo bash ./compile.sh
$ sudo cp output/bazel /usr/local/bin
5。为Tensorflow构建做准备。
$ cd ~
$ sudo pip2 uninstall tensorflow
$ sudo pip3 uninstall tensorflow
$ sudo pip3 install keras_applications==1.0.4 --no-deps
$ sudo pip3 install keras_preprocessing==1.0.2 --no-deps
$ sudo pip3 install h5py==2.8.0
$ git clone -b v1.11.0 https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ git checkout v1.11.0
$ ./tensorflow/contrib/lite/tools/make/download_dependencies.sh
$ ./tensorflow/contrib/lite/tools/make/build_rpi_lib.sh
$ sudo bazel build tensorflow/contrib/lite/toco:toco
6-1.Tensorflow的配置。 (Python2.x)
$ ./configure
WARNING: Running Bazel server needs to be killed, because the startup options are different.
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.17.2- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]:
Found possible Python library paths:
/usr/local/lib/python2.7/dist-packages
/usr/local/lib
/usr/lib/python2.7/dist-packages
/opt/movidius/caffe/python
Please input the desired Python library path to use. Default is [/usr/local/lib/python2.7/dist-packages]
Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: n
No jemalloc as malloc support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
No Hadoop File System support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Amazon AWS Platform support? [Y/n]: n
No Amazon AWS Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with Apache Kafka Platform support? [Y/n]: n
No Apache Kafka Platform support will be enabled for TensorFlow.
Do you wish to build TensorFlow with XLA JIT support? [y/N]: n
No XLA JIT support will be enabled for TensorFlow.
Do you wish to build TensorFlow with GDR support? [y/N]: n
No GDR support will be enabled for TensorFlow.
Do you wish to build TensorFlow with VERBS support? [y/N]: n
No VERBS support will be enabled for TensorFlow.
Do you wish to build TensorFlow with nGraph support? [y/N]: n
No nGraph support will be enabled for TensorFlow.
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.
Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.
Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
--config=mkl # Build with MKL support.
--config=monolithic # Config for mostly static monolithic build.
Configuration finished
6-2.Tensorflow的配置。 (Python3.x)
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3
Found possible Python library paths:
/usr/local/lib
/usr/lib/python3/dist-packages
/usr/local/lib/python3.5/dist-packages
Please input the desired Python library path to use. Default is [/usr/local/lib] /usr/local/lib/python3.5/dist-packages
7.Tensorflow的构建。
$ sudo bazel build --config opt --local_resources 1024.0,0.5,0.5 \
--copt=-mfpu=neon-vfpv4 \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--copt=-DRASPBERRY_PI \
--host_copt=-DRASPBERRY_PI \
//tensorflow/tools/pip_package:build_pip_package
8.Tensorflow的安装。
$ sudo ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
$ sudo pip2 install /tmp/tensorflow_pkg/tensorflow-1.11.0-cp27-cp27mu-linux_armv7l.whl
Or
$ sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.11.0-cp35-cp35m-linux_armv7l.whl
9。【必需】重启终端。
10。执行下面的
$ sudo apt install -y python-scipy python3-scipy
$ sudo apt remove openjdk-8-*
$ sudo apt purge openjdk-8-*
如果到目前为止已完成,则该问题应该已经解决。
但是,总共需要27个小时。
如果您不等待27个小时,则可以使用交叉构建或使用建议的滚轮文件大大减少等待时间。
预构建Tensorflow二进制文件(车轮)在下面。
https://github.com/PINTO0309/Tensorflow-bin
答案 1 :(得分:0)
我错过了什么。
要在Raspberry Pi上安装Tensorflow,您可以使用官方的pip包
pip install tensorflow
有关更多详细信息,请访问官方文档页面-
https://www.tensorflow.org/install/pip
或者,如果需要Cross编译的软件包,则可以遵循此官方文档页面-
https://www.tensorflow.org/install/source_rpi
为确保TF使用lite库而不是完整版,我需要做些什么。
您只需要一个经过训练的模型并将其转换为TFLite模型即可。有关完整的详细信息,您可以按照本教程进行操作-
https://medium.com/tensorflow/training-and-serving-a-realtime-mobile-object-detector-in-30-minutes-with-cloud-tpus-b78971cf1193
最后-没人知道Pi上应该实现什么FPS TF lite吗?
我目前正在研究它,但是由于tensorflow当前针对Raspberry pi(https://github.com/tensorflow/tensorflow/issues/23082)的官方构建存在一些问题,因此我无法计算Pi的性能。
答案 2 :(得分:0)
要关注Ishita Shah的评论,我在这里发布我的步骤,以构建/运行在Raspberry Pi 3上运行的TfLite的2个启动应用程序:-)
1,按照https://www.raspberrypi.org/learning/software-guide/quickstart/,将Raspbian安装到Raspberry Pi 3板上。
#sudo apt install build-essential
按照https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/pi_examples安装摄像头。
验证相机是否正常工作
#raspistill -v
2,git clone -b r1.12 https://github.com/huaxiaozhong1/tensorflow.git。 (最好的办法是在Ubuntu 18.04的最新docker容器中完成)。 它将6个静态库克隆到/ tensorflow / tensorflow / contrib / lite / examples / camera / libs中: libjpeg.a librt.a libv4l1.a libv4l2.a libv4l2rds.a libv4lconvert.a。 实际上,它们是从在步骤1中准备的Pi环境中创建的:
3,在主机容器中:
#apt update
#apt upgrade
#apt install crossbuild-essential-armhf
#cd /tensorflow
#./tensorflow/contrib/lite/tools/make/download_dependencies.sh
#apt install -y libjpeg-dev
#apt install libv4l-dev
#./tensorflow/contrib/lite/tools/make/build_rpi_lib.sh
现在,您可以找到./tensorflow/contrib/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a、/tensorflow/tensorflow/contrib/lite/tools/make/gen/rpi_armv7l/bin / label_image和/ tensorflow / tensorflow / contrib / lite / tools / make / gen / rpi_armv7l / bin / camera。
4,将label_image和camera(Linux可执行文件)复制到Raspeberry板上。 从主机容器的/ tensorflow / tensorflow / contrib / lite / examples / label_image / testdata复制grace_hopper.bmp到板上。 从主机容器的/ tensorflow / tensorflow / contrib / lite / java / ovic / src / testdata复制label.txt到开发板上。 从https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/models.md将Mobilenet_v2_1.0_224_quant.tflite下载到开发板。 3个数据文件和2个Linux可执行文件应位于同一文件夹中。
5,一个接一个地运行两个应用程序。
注意:我将2个应用程序添加到的基本分支是r1.12。现在,TfLite已宣布退出竞争。但是,当我在最新的tensorflow / tensorflow:nightly-devel中运行build_rpi_lib.sh时,它没有成功。那么,我现在可以基于r1.12提交拉取请求吗?成功构建libtensorflow-lite.a后,我可以在r1.13 +上添加相同的功能。