介绍
本页将领导您在Raspberry Pi 4 64位操作系统Bullseye 上装置 TensorFlow 2.10.0 或更早版本。
TensorFlow是一个专门为深度学习开发的大型软件库。它耗费大量资源。你能够在Raspberry Pi 4上执行TensorFlow,但不要指望奇观。它能够运行您的模型,如果不是太简单,但它将无奈训练新模型。它也不能执行所谓的迁徙学习。除了运行事后构建的深度学习模型外,您还能够应用该库将所谓的解冻 TensorFlow 模型转换为 TensorFlow Lite 立体缓冲区模型。
如果你只是想对深度学习有一些印象,请思考装置TensorFlow Lite。它的速度要快得多,应用的资源要少得多,因为它是为Raspberry Pi等小型计算机设计的。您能够应用许多现成的生成模型。在此处查看咱们的 64 位 Raspberry 装置指南。
路线图
TensorFlow持续增长。每个新版本都须要更多的资源、支持软件和库。它越来越多地给你的树莓派带来了惨重的累赘。它解释了为什么最新版本在具备“过期”操作系统的“旧”Raspberry Pis上不能很好地运行。
另一方面,不倡议在最新的Bullseye上装置十分旧的TensorFlow版本。您将被迫降级某些零碎库,这将阻止其他软件运行。这里最好遵循:“顺其自然”。
以下是概述。绿色复选标记示意有版本可用。空的绿色盒子意味着没有版本,但依然能够装置。灰色框指定不容许“失常”装置的硬件或软件限度。

提醒

通常,咱们会收到一个问题,如果咱们有一个带有预装框架和深度学习示例的 Raspberry Pi 4 的 SD 图像。
咱们很乐意恪守这一要求。请在咱们的GitHub页面上找到一个残缺的Raspberry Pi 4,专门用于深度学习。 从咱们的GDrive网站下载zip文件,解压缩并在16 GB SD卡上刷新图像,而后开始吧!
咱们探讨了两个装置,一个用于 Python 3,一个用于 API 库C++。 可怜的是,没有官网的 aarch64 pip3 轮可用于 2.7、2.6 或 2.5 版本。然而,为了您的不便,咱们应用 Bazel 创立了咱们的轮子并将它们放在 GitHub 上。本指南的最初一部分探讨了Keras的装置。
筹备
Numpy
Tensorflow在最新版本的numpy中遇到了问题。将 TensorFlow 移植到 numpy 1.20 变得十分艰难。当初,随着TensorFlow版本2.8.0的呈现,它终于胜利了。最初,装置TensorFlow时不再有numpy版本抵触。
然而,TensorFlow 2.7.0依然报告了一些问题。为了平安起见,请应用 numpy 版本 1.19.5为了TF 2.7.0 以确保一切正常。
libclang 9.0.1
TensorFlow 2.7.0 依赖于 libclang 9.0.1。没有实用于 Debian 10 的发行版。这就是为什么只有TensorFlow 2.7装置在Debian11Bullseye上,。你能够从头开始在Buster RPi上装置libclang 9.0.1,这样你就能够装置TensorFlow了。请留神,clang构建须要大量资源,超过5 GB。最好切换到Bullseye,并在半小时内启动并运行TensorFlow
Protobuffer 4.21
最新版本的Protobuffer 4.21.0与以前的版本3.20.1相比有一些重大改良。然而,TensorFlow尚不反对这些更改。为了使 TensorFlow 失常工作,如果您装置了4.21 ,则须要将 Protobuf 降级到 3.20版本。

无关如何降级的更多信息,请拜访咱们的 GitHub 页面。
Tensorflow-io-gcs-filesystem
所有依赖项都能够只用一个命令装置,除了 tensorflow-io-gcs 文件系统。因为没有 aarch64 机器的发行版,咱们必须从头开始构建 tensorflow-io-gcs 文件系统。整个过程能够在上面找到,应该在装置TensorFlow自身之前实现。如果让TensorFlow装置io-gcs,它将抉择谬误的版本并且不起作用。# get a fresh start

$ sudo apt-get update$ sudo apt-get upgrade# install pip3$ sudo apt-get install git python3-pip# install correct version protobuf$ sudo -H pip3 install --upgrade protobuf==3.20.0Method 1# download tensorflow io$ git clone -b v0.23.1 --depth=1 --recursive https://github.com/tensorflow/io.git$ cd io$ python3 setup.py -q bdist_wheel --project tensorflow_io_gcs_filesystem$ cd dist$ sudo -H pip3 install tensorflow_io_gcs_filesystem-0.23.1-cp39-cp39-linux_aarch64.whl$ cd ~Method 2# or download wheel$ git clone https://github.com/Qengineering/Tensorflow-io.git$ cd Tensorflow-io$ sudo -H pip3 install tensorflow_io_gcs_filesystem-0.23.1-cp39-cp39-linux_aarch64.whl$ cd ~

Python 3.9 的 TensorFlow wheels
TensorFlow由一个名为Bazel的Google软件安装程序装置。最初,Bazel生成一个轮子来装置TensorFlow Python版本,或者在装置C++版本时生成一个压缩包。这两种办法都是树莓派用户所熟知的。咱们曾经在GitHub页面上公布了Bazel的后果。随便应用这些轮子。整个 TensorFlow 装置过程从头到尾须要很多小时(Python ±64,C++库±1)。实现所有繁琐的工作后,只需几分钟即可在Raspberry 64位Bullseye上装置TensorFlow。对于很难实现的局部,本手册稍后将介绍残缺的程序。
整个快捷方式过程如下。wheels太大,无奈存储在GitHub上,因而应用Google驱动器代替。
TensorFlow 2.10.0

# install gdown to download from Google drive$ sudo -H pip3 install gdown# download the wheel$ gdown https://drive.google.com/uc?id=1G2P-FaHAXJ-UuQAQn_0SYjNwBu0aShpd# install TensorFlow 2.10.0$ sudo -H pip3 install tensorflow-2.10.0-cp39-cp39-linux_aarch64.whl

TensorFlow 2.9.1

# install gdown to download from Google drive$ sudo -H pip3 install gdown# download the wheel$ gdown https://drive.google.com/uc?id=1xP6ErBK85SMFnQamUh4ro3jRmdCV_qDU# install TensorFlow 2.9.1$ sudo -H pip3 install tensorflow-2.9.1-cp39-cp39-linux_aarch64.whl

TensorFlow 2.8.0

# install gdown to download from Google drive$ sudo -H pip3 install gdown# download the wheel$ gdown https://drive.google.com/uc?id=1YpxNubmEL_4EgTrVMu-kYyzAbtyLis29# install TensorFlow 2.8.0$ sudo -H pip3 install tensorflow-2.8.0-cp39-cp39-linux_aarch64.whl

TensorFlow 2.7.0

# utmost important: use only numpy version 1.19.5# check the version first$ pip3 list | grep numpy# if not version 1.19.5, update!$ sudo -H pip3 install numpy==1.19.5# (re)install termcolor at the correct location$ python3 -m pip install termcolor# install gdown to download from Google drive$ sudo -H pip3 install gdown# download the wheel$ gdown https://drive.google.com/uc?id=1FdVZ1kX5QZgWk2SSgq31C2-CF95QhT58# install TensorFlow 2.7.0$ sudo -H pip3 install tensorflow-2.7.0-cp39-cp39-linux_aarch64.whl

装置胜利后,应取得以下屏幕输入。

TensorFlow 2.8.0 C++ API
如果你打算用C++编程,你将须要TensorFlow的C++API版本,而不是Python版本。应用咱们 GitHub 页面中的预构建压缩包装置 C++ 库能够为您节俭大量工夫。 请依照以下步骤操作。
TensorFlow 2.10.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# remove old versions (if found)$ sudo rm -r /usr/local/lib/libtensorflow*$ sudo rm -r /usr/local/include/tensorflow# the dependencies$ sudo apt-get install wget curl libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatomic1 libatlas-base-dev zip unzip# install gdown to download from Google drive (if not already done)$ sudo -H pip3 install gdown# download the tarball$ gdown https://drive.google.com/uc?id=1GOC5CiT5Ws2NpiBem4K3g3FRqmGDRcL7# unpack the ball$ sudo tar -C /usr/local -xzf libtensorflow_cp39_64OS_2_10_0.tar.gz

TensorFlow 2.9.1

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# remove old versions (if found)$ sudo rm -r /usr/local/lib/libtensorflow*$ sudo rm -r /usr/local/include/tensorflow# the dependencies$ sudo apt-get install wget curl libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatomic1 libatlas-base-dev zip unzip# install gdown to download from Google drive (if not already done)$ sudo -H pip3 install gdown# download the tarball$ gdown https://drive.google.com/uc?id=1Z83_RQTvCb2jL2BO1Zdez3x4Qx-XheRk# unpack the ball$ sudo tar -C /usr/local -xzf libtensorflow_cp39_64OS_2_9_1.tar.gz

TensorFlow 2.8.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# remove old versions (if found)$ sudo rm -r /usr/local/lib/libtensorflow*$ sudo rm -r /usr/local/include/tensorflow# the dependencies$ sudo apt-get install wget curl libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatomic1 libatlas-base-dev zip unzip# install gdown to download from Google drive (if not already done)$ sudo -H pip3 install gdown# download the tarball$ gdown https://drive.google.com/uc?id=1dmJKIk8lUi_XCzlVnRgL-UvfVFriRmCG# unpack the ball$ sudo tar -C /usr/local -xzf libtensorflow_cp39_64OS_2_8_0.tar.gz

TensorFlow 2.7.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# remove old versions (if found)$ sudo rm -r /usr/local/lib/libtensorflow*$ sudo rm -r /usr/local/include/tensorflow# the dependencies$ sudo apt-get install wget curl libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatomic1 libatlas-base-dev zip unzip# install gdown to download from Google drive (if not already done)$ sudo -H pip3 install gdown# download the tarball$ gdown https://drive.google.com/uc?id=1kScCKyj0pr265XbCgYmXqXs77xJFe6p1# unpack the ball$ sudo tar -C /usr/local -xzf libtensorflow_cp39_64OS_2_7_0.tar.gz

你最终应该将 TensorFlow 库装置在 /usr/local/lib 地位,并将头文件装置在文件夹 usr/local/include/tensorflow/c 中。


从头开始装置
内存替换大小
构建残缺的 TensorFlow 2.8 包须要超过 6 GB 的 RAM。如果您有具备8 GB RAM的Raspberry Pi 4,那么您就很分明了。否则,请确保减少替换大小以满足此需要。板载 4 GB RAM,zram 能够提供额定的 2 GB。有了 2 GB 的 RAM,您就不能再依附 zram 来压缩超过 2 倍。在这种状况下,他们必须重新安装dphys-swapfile能力从SD卡中获取额定的空间。如果您必须装置 dphys-swapfile,请依照以下命令操作。在 Bullseye 操作系统上设置替换空间时,实现重启须要相当长的工夫。# install dphys-swapfile

$ sudo apt-get install dphys-swapfile# give the required memory size$ sudo nano /etc/dphys-swapfile# reboot afterwards$ sudo reboot


如果一切顺利,你应该有这样的货色。

作为记录,显示的数字是dphys-swapfile和zram调配的替换空间总量。请不要遗记在实现后删除dphys-swapfile。留神:如果在同时启用 zram 和 dphys-swapfile 的状况下重新启动 Raspberry Pi,zram 将在启动期间禁用 dphys-swapfile。您必须手动从新激活此服务。

# reactivate dphys-swapfile after a reboot# (when zram and dphys-swapfile are both enabled)$ sudo /etc/init.d/dphys-swapfile stop$ sudo /etc/init.d/dphys-swapfile start

Bazel
Bazel是Google的收费软件工具,用于主动构建和测试软件包。你能够将它与OpenCV应用的CMake进行比拟,但后者只构建软件,没有测试工具。Bazel是用Java编写的,Java是一种独立于平台的语言,在语法方面次要基于C++。要编译 Bazel,咱们必须首先应用以下命令装置 Java 和其余一些依赖项。# get a fresh start

$ sudo apt-get update$ sudo apt-get upgrade# install pip and pip3$ sudo apt-get install python3-pip# install some tools$ sudo apt-get install zip unzip curl# install Java$ sudo apt-get install openjdk-11-jdk

接下来,咱们能够下载并解压缩 Bazel 软件。咱们须要 TensorFlow 2.1.0 的 Bazel 版本 5.1.1,因而请确保装置正确的版本。

$ wget https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-dist.zip$ unzip -d bazel bazel-5.1.1-dist.zip$ cd bazel

在装置过程中,Bazel 应用预约义的可用工作内存比率。因为树莓派的 RAM 大小无限,这个比例太小了。为避免解体,咱们必须将此内存的大小定义为最大板载 RAM 的 40%。例如,800 MB用于2 GByte RAM Raspberry Pi。这是通过在脚本文件 compile.sh 中增加一些额定信息来实现的。您能够将文本 -J-Xmx800M 增加到以 run 结尾的行中。 (第 144 行左右)。请参阅上面的屏幕。应用家喻户晓的<Ctrl + X>、<Y>、<Enter>保留更改(请参阅下面的幻灯片放映)。
$ nano scripts/bootstrap/compile.sh -c


一旦 Bazel 的 Java 环境最大化,您就能够应用下一个命令开始构建 Bazel 软件。实现后,将二进制文件复制到 /usr/local/bin 地位,以便 bash 能够在任何中央找到可执行文件。最初一个操作是删除 zip 文件。整个构建大概须要 33 分钟。# start the build

$ env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh# copy the binary$ sudo cp output/bazel /usr/local/bin/bazel# clean up$ cd ~$ rm bazel-5.1.1-dist.zip# if you have a copied bazel to /usr/local/bin you may also# delete the whole bazel directory, freeing another 500 MByte$ sudo rm -rf bazel


装置 TensorFlow for Python 3
随着Bazel的启动和运行,咱们能够开始在64位Raspberry Pi for Python 3上构建TensorFlow 2.10.0。这简直正在成为规范做法。首先,装置一些依赖项,而后从 GitHub 下载 zip,最初解压缩软件。您还必须装置 tensorflow_io_gcs 文件系统。它是通过应用咱们的 GitHub 存储库中的预编译轮来实现的。
TensorFlow 2.10.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# the dependencies$ sudo apt-get install zip unzip$ sudo -H pip3 install keras_applications --no-deps$ sudo -H pip3 install keras_preprocessing --no-deps# install correct version protobuf$ sudo -H pip3 install --upgrade protobuf==3.20.0# download tensorflow io$ git clone https://github.com/Qengineering/Tensorflow-io.git$ cd Tensorflow-io$ sudo -H pip3 install tensorflow_io_gcs_filesystem-0.23.1-cp39-cp39-linux_aarch64.whl$ cd ~# download TensorFlow 2.10.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.10.0.zip$ unzip tensorflow.zip$ cd tensorflow-2.10.0$ ./configure

TensorFlow 2.9.1

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# the dependencies$ sudo apt-get install zip unzip$ sudo -H pip3 install keras_applications --no-deps$ sudo -H pip3 install keras_preprocessing --no-deps# install correct version protobuf$ sudo -H pip3 install --upgrade protobuf==3.20.0# download tensorflow io$ git clone https://github.com/Qengineering/Tensorflow-io.git$ cd Tensorflow-io$ sudo -H pip3 install tensorflow_io_gcs_filesystem-0.23.1-cp39-cp39-linux_aarch64.whl$ cd ~# download TensorFlow 2.9.1$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.9.1.zip$ unzip tensorflow.zip$ cd tensorflow-2.9.1$ ./configure

TensorFlow 2.8.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# the dependencies$ sudo apt-get install zip unzip$ sudo -H pip3 install keras_applications --no-deps$ sudo -H pip3 install keras_preprocessing --no-deps# install correct version protobuf$ sudo -H pip3 install --upgrade protobuf==3.20.0$ cd ~# download TensorFlow 2.8.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.8.0.zip$ unzip tensorflow.zip$ cd tensorflow-2.8.0$ ./configure

TensorFlow 2.7.0

# get a fresh start$ sudo apt-get update$ sudo apt-get upgrade# the dependencies$ sudo apt-get install zip unzip$ sudo -H pip3 install keras_applications --no-deps$ sudo -H pip3 install keras_preprocessing --no-deps# download TensorFlow 2.7.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.7.0.zip$ unzip tensorflow.zip$ cd tensorflow-2.7.0$ ./configure

构建 Python 3 装置轮之前的最初一步是应用一些环境变量配置构建。这是由 ./configure 脚本文件实现的。将 Python 3 定义为默认的 Python 版本,对所有其余问题定义为“否”。

pi@raspberrypi:~/tensorflow-2.10.0 $ ./configureYou have bazel 5.1.1- (@non-git) installed.Please specify the location of python. [Default is /usr/bin/python3]: <enter>Found possible Python library paths: /usr/lib/python3/dist-packages /usr/local/lib/python3.9/dist-packagesPlease input the desired Python library path to use.  Default is [/usr/lib/python3/dist-packages] <enter>Do you wish to build TensorFlow with ROCm support? [y/N]: nNo ROCm support will be enabled for TensorFlow.Do you wish to build TensorFlow with CUDA support? [y/N]: nNo CUDA support will be enabled for TensorFlow.Do you wish to download a fresh release of clang? (Experimental) [y/N]: nClang will not be downloaded.Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -Wno-sign-compare]: <enter>Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: nNot 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 .bazelrc for more details.--config=mkl          # Build with MKL support.--config=mkl_aarch64 # Build with oneDNN and Compute Library for the Arm Architecture (ACL).--config=monolithic   # Config for mostly static monolithic build.--config=numa         # Build with NUMA support.--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.--config=v2           # Build TensorFlow 2.x instead of 1.x.Preconfigured Bazel build configs to DISABLE default on features:--config=noaws        # Disable AWS S3 filesystem support.--config=nogcp        # Disable GCP support.--config=nohdfs       # Disable HDFS support.--config=nonccl       # Disable NVIDIA NCCL support.Configuration finished

脚本文件现已全副设置结束,能够应用以下命令开始大规模构建。-Xmx1624m 设置运行 Bazel 的 Java 环境的内存大小。给它尽可能多的空间。咱们倡议 80% 的树莓派内存大小。在咱们的例子中,咱们有 2 GB 板载,所以 1624 MB 为除 Bazel 之外的其余线程留下了足够的空间。
另一点是Basel 应用的内核数量。最好应用一个内核。运行慢一点比解体好一点(总是在最初)并从新开始。
在生成过程中敞开所有其余应用程序。运行的其余过程越少,编译速度就越快。

$ sudo bazel clean$ sudo bazel --host_jvm_args=-Xmx1624m build \             --config=opt \             --config=noaws \             --config=nogcp \             --config=nohdfs \             --config=nonccl \             --config=monolithic \             --config=v2 \             --local_cpu_resources=1 \             --define=tflite_pip_with_flex=true \             --copt=-ftree-vectorize \             --copt=-funsafe-math-optimizations \             --copt=-ftree-loop-vectorize \             --copt=-fomit-frame-pointer \             //tensorflow/tools/pip_package:build_pip_package

通过 41 小时(或更长时间!)编译后,您将看到以下屏幕。

当初咱们必须生成wheel并装置它。这是通过以下命令实现的。装置大概只需几分钟。
TensorFlow 2.10.0

# synthesize the wheel$ sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg$ cd ~# go to the folder where the wheel is located and install tensorflow$ cd /tmp/tensorflow_pkg$ sudo -H pip3 install tensorflow-2.10.0-cp39-cp39-linux_aarch64.whl

TensorFlow 2.9.1

# synthesize the wheel$ sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg$ cd ~# go to the folder where the wheel is located and install tensorflow$ cd /tmp/tensorflow_pkg$ sudo -H pip3 install tensorflow-2.9.1-cp39-cp39-linux_aarch64.whl

TensorFlow 2.8.0

# synthesize the wheel$ sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg$ cd ~# go to the folder where the wheel is located and install tensorflow$ cd /tmp/tensorflow_pkg$ sudo -H pip3 install tensorflow-2.8.0-cp39-cp39-linux_aarch64.whl

TensorFlow 2.7.0

# synthesize the wheel$ sudo bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg$ cd ~# go to the folder where the wheel is located and install tensorflow$ cd /tmp/tensorflow_pkg$ sudo -H pip3 install tensorflow-2.7.0-cp39-cp39-linux_aarch64.whl

装置 TensorFlow C++ API
如前所述,您能够应用 GitHub 页面上的压缩包十分疾速地装置 TensorFlow C++ API;不须要通过漫长的装置过程。 对于那些想要本人构建 API 的人,当初遵循装置指南。首先,如果尚未装置 Bazel。该过程也在下面形容。一旦 Bazel 开始工作,你能够装置依赖项并下载 TensorFlow,如果之前还没有为 Python 3 装置实现的话。
TensorFlow 2.10.0

# the dependencies$ sudo apt-get install build-essential make cmake wget zip unzip$ sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatlas-base-dev# download TensorFlow 2.10.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.10.0.zip# unpack the folder$ unzip tensorflow.zip$ cd tensorflow-2.10.0$ ./configure

TensorFlow 2.9.1

# the dependencies$ sudo apt-get install build-essential make cmake wget zip unzip$ sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatlas-base-dev# download TensorFlow 2.10.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.10.0.zip# unpack the folder$ unzip tensorflow.zip$ cd tensorflow-2.10.0$ ./configure

TensorFlow 2.8.0

# the dependencies$ sudo apt-get install build-essential make cmake wget zip unzip$ sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatlas-base-dev# download TensorFlow 2.8.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.8.0.zip# unpack the folder$ unzip tensorflow.zip$ cd tensorflow-2.8.0$ ./configure

TensorFlow 2.7.0

# the dependencies$ sudo apt-get install build-essential make cmake wget zip unzip$ sudo apt-get install libhdf5-dev libc-ares-dev libeigen3-dev$ sudo apt-get install libatlas-base-dev# download TensorFlow 2.7.0$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.7.0.zip# unpack the folder$ unzip tensorflow.zip$ cd tensorflow-2.7.0$ ./configure

同样,咱们须要在理论构建开始之前配置 Bazel。只管咱们要构建一个C++ API,但Bazel脚本文件须要设置为Python 3作为默认Python版本,而所有其余问题则须要设置为“否”。 答复脚本文件的所有问题后,您最终会失去与上所示雷同的输入屏幕。
最初一步是命令行及其选项。同样,与之前应用的简直雷同。这里最重要的是 --config=monolithic 标记。没有这个方向,TensorFlow将无奈与OpenCV一起应用,反之亦然。就像pip编译一样,Java环境(-Xmx1624m)的内存必须最大化到Raspberry Pi板载内存的80%。 最初一行示意压缩包库构建,而不是pip wheel。

$ sudo bazel --host_jvm_args=-Xmx1624m build \             --config=opt \             --config=noaws \             --config=nogcp \             --config=nohdfs \             --config=nonccl \             --config=monolithic \             --config=v2 \             --local_cpu_resources=1 \             --copt=-ftree-vectorize \             --copt=-funsafe-math-optimizations \             --copt=-ftree-loop-vectorize \             --copt=-fomit-frame-pointer \             //tensorflow/tools/lib_package:libtensorflow

通过漫长的 12 个小时期待,您将看到以下屏幕。

最初一步是装置压缩包。这是通过以下命令实现的。

$ sudo tar -C /usr/local -xzf bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz

装置后,您必须具备雷同的文件夹(/usr/local/lib 和 usr/local/include/tensorflow/c),如本页结尾所示。
革除
胜利装置后,不再须要许多文件。bazel 生成的两头对象文件占用大概 6 GB 的磁盘。删除不会造成任何挫伤。

# clean up the whole bazel cache$ sudo rm -rf ~/.cache/bazel

如果您必须重新安装 dphys-swapfile,是时候再次卸载它了。这样,您将缩短SD卡的使用寿命。

# remove the dphys-swapfile (if installed)$ sudo /etc/init.d/dphys-swapfile stop$ sudo apt-get remove --purge dphys-swapfile

转载来自:rpideveloper.com/topic/18
https://www.edatec.cn/cn/WX:上海晶珩电子