0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

用树莓派搞深度学习?TensorFlow启动!

上海晶珩电子科技有限公司 ? 2025-03-25 09:33 ? 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

介绍

本页面将指导您在搭载64位Bullseye操作系统的Raspberry Pi 4上安装TensorFlow

TensorFlow是一个专为深度学习开发的大型软件库,它消耗大量资源。您可以在Raspberry Pi 4上运行TensorFlow,但不要期望有奇迹般的表现。如果模型不太复杂,它可以运行您的模型,但无法训练新模型,也无法执行所谓的迁移学习。除了运行您预先构建的深度学习模型外,您还可以使用该库将所谓的冻结TensorFlow模型转换为TensorFlow Lite平面缓冲区模型。

如果您只想对深度学习有个初步了解,请考虑安装TensorFlow Lite。它速度更快,使用的资源更少,因为它是为Raspberry Pi这样的小型计算机设计的。您可以使用许多现成的模型。有关在64位Raspberry Pi上安装的指南,请参阅此处。

路线图

TensorFlow不断发展壮大。每个新版本都需要更多的资源、支持软件和库。它给您的Raspberry Pi带来了越来越重的负担。这就解释了为什么最新版本在搭载“过时”操作系统的“旧”Raspberry Pi上运行不佳。

另一方面,不建议在最新的Bullseye上安装非常旧的TensorFlow版本。您将不得不降级一些系统库,这将导致其他软件无法正常工作。这里的座右铭是:“随波逐流”。

以下是概览。绿色勾选标记表示有可用的wheel文件。空绿色框表示没有wheel文件,但仍然可以安装。灰色框表示硬件或软件限制,不允许进行“正常”安装。

17a4fff8-0919-11f0-9434-92fbcf53809c.png

提示

17b6b4d2-0919-11f0-9434-92fbcf53809c.png

我们经常收到询问,是否有预装了框架和深度学习示例的Raspberry Pi 4的SD卡镜像。我们很高兴满足这一要求。请在我们的GitHub页面上找到专用于深度学习的完整工作Raspberry Pi 4。从我们的GDrive网站下载zip文件,解压并将镜像刷入32GB的SD卡,然后尽情享受吧!

我们讨论了两种安装,一种是针对Python 3的,另一种是针对C++ API库的。不幸的是,对于2.7、2.6或2.5版本,没有官方的aarch64 pip3 wheel文件可用。但是,我们使用Bazel创建了wheel文件,并将其放在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没有可用的发行版。这就是为什么只有针对Debian 11(Bullseye)的TensorFlow 2.7安装。您可能可以从头开始在您的Buster RPi上安装libclang 9.0.1,然后才能安装TensorFlow。请注意,clang的构建需要巨大的资源,超过5GB。最好切换到Bullseye,并在半小时内让TensorFlow运行起来。

Protobuffer 4.21

Protobuffer的最新版本4.21.0相比之前的版本3.20.1有了一些显著的改进。但是,TensorFlow尚不支持这些更改。为了让TensorFlow正常工作,如果您安装了4.21,则需要将您的Protobuf降级到3.20版本。

17eb843c-0919-11f0-9434-92fbcf53809c.jpg

有关如何降级的更多信息,可以在我们的GitHub页面上找到。

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 ~

TensorFlow Python 3.9的wheel文件

TensorFlow是由名为Bazel的Google软件安装程序安装的。最后,Bazel会生成一个wheel文件来安装TensorFlow的Python版本,或者当涉及到安装C++版本时,会生成一个tarball文件。这两种方法都是Raspberry Pi用户所熟知的。我们已经将Bazel的结果发布在我们的GitHub页面上。请随意使用这些wheel文件。从头到尾整个TensorFlow安装过程需要数小时(Python版约为64小时,C++库版约为1小时)。由于所有繁琐的工作都已经完成,因此在您的Raspberry 64位Bullseye上安装TensorFlow只需要几分钟。对于顽固分子,本手册后面将介绍完整的过程。

整个快捷方式过程如下。由于wheel文件太大,无法存储在GitHub上,因此使用了Google Drive。

TensorFlow 2.14.0

# install TensorFlow 2.14.0$ sudo -H pip3 install --upgrade tensorflow==2.14.0

TensorFlow 2.13.0

# install TensorFlow 2.13.0$ sudo -H pip3 install --upgrade tensorflow==2.13.0

TensorFlow 2.12.0

# install TensorFlow 2.12.0$ sudo -H pip3 install --upgrade tensorflow==2.12.0

TensorFlow 2.11.0

# install TensorFlow 2.11.0$ sudo -H pip3 install --upgrade tensorflow==2.11.0

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.1

# 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: useonly 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

当安装成功时,您应该会看到以下屏幕截图。

180a29f0-0919-11f0-9434-92fbcf53809c.jpg

TensorFlow C++ API.

如果您打算用C++编程,您将需要TensorFlow的C++ API构建版本,而不是Python版本。从我们的GitHub页面使用预构建的tarball文件来安装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文件夹中。

1824f532-0919-11f0-9434-92fbcf53809c.jpg

从零开始的安装

针对TensorFlow 2.14及以上版本

https://qengineering.eu/install-tensorflow-on-raspberry-pi-5.html内存交换空间大小

构建完整的TensorFlow包需要超过6GB的内存。如果你有一台配备8GB内存的Raspberry Pi 4,那么你可以轻松应对。否则,请确保增加交换空间大小以满足这一需求。如果你的设备有4GB内存,zram可以提供额外的2GB空间。而如果只有2GB内存,则无法再依赖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

1856385e-0919-11f0-9434-92fbcf53809c.jpg

18801692-0919-11f0-9434-92fbcf53809c.jpg

18af36ac-0919-11f0-9434-92fbcf53809c.jpg

如果一切顺利,你应该会看到类似下面的内容。

18d8e768-0919-11f0-9434-92fbcf53809c.png

图中所示为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编写的,这是一种与平台无关的语言,在语法上很大程度上基于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.10需要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会使用预定比例的可用工作内存。由于Raspberry Pi的RAM大小有限,这个比例太小。为防止崩溃,我们必须将此内存大小设置为板载RAM的最大40%。例如,对于2GB RAM的Raspberry Pi,应设置为800MB。这可以通过向脚本文件compile.sh添加一些额外信息来实现。你可以在以run..(大约第144行)开头的行中添加文本-J-Xmx800M。见下面的屏幕截图。使用常见的、、保存更改(见上面的幻灯片)。

$nano scripts/bootstrap/compile.sh -c

18e559f8-0919-11f0-9434-92fbcf53809c.jpg

一旦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

1907ad28-0919-11f0-9434-92fbcf53809c.jpg

安装 TensorFlow for Python 3Bazel运行正常后,我们就可以开始在我们的64位Raspberry Pi上为Python 3构建TensorFlow 2.10.0了。这几乎已成为标准做法。首先,安装一些依赖项,然后从GitHub下载zip文件,最后解压软件。你还必须安装tensorflow_io_gcs文件系统。这可以通过使用我们从GitHub存储库中获取的预编译wheel文件来完成。

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安装wheel之前的最后一步是使用一些环境变量配置你的构建。这是通过./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]:
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]
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]:
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 环境的内存大小。尽可能给它分配更多的空间。我们建议分配你 Raspberry Pi 内存大小的 80%。在我们的例子中,板载内存为 2 Gbyte,所以 1624 Mbyte 除了 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 小时(或更长时间!)后,希望您能看到以下屏幕。

192b5a02-0919-11f0-9434-92fbcf53809c.jpg

现在我们需要生成 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 页面上的 tarball 文件来快速安装 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.9.1$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.9.1.zip# unpack the folder$ unzip tensorflow.zip$ cd tensorflow-2.9.1$ ./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%。最后一行指示的是 tarball 库构建,而不是 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 小时等待后,希望你会看到下面的屏幕。

195626ec-0919-11f0-9434-92fbcf53809c.jpg

最后一步是安装 tarball。这可以通过下面的命令来完成。

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

安装完成后,你必须拥有与本页开头所示相同的文件夹(/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 卡的寿命。

#removethedphys-swapfile(ifinstalled)$ sudo /etc/init.d/dphys-swapfile stop$ sudo apt-get remove --purge dphys-swapfile

在 Raspberry Pi 64 操作系统上安装 Keras

安装完 TensorFlow 后,您可以加载 Keras。Keras 是在 TensorFlow 基础上运行的高级外壳。它声称比 TensorFlow 更方便用户使用,提供了一套更直观的抽象概念,可以轻松开发深度学习模型。安装只需一条命令。

$ pip3 install keras

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 树莓派
    +关注

    关注

    122

    文章

    2031

    浏览量

    107666
  • 深度学习
    +关注

    关注

    73

    文章

    5564

    浏览量

    122940
  • tensorflow
    +关注

    关注

    13

    文章

    330

    浏览量

    61235
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    树莓如何安装和启动

    `树莓如何安装和启动呢。安装树莓必须的装备:1.2G以上安装了树莓派系统的SD卡(安装系统参
    发表于 06-30 23:18

    深度学习框架TensorFlow&TensorFlow-GPU详解

    TensorFlow&TensorFlow-GPU:深度学习框架TensorFlow&TensorFlo
    发表于 12-25 17:21

    基于树莓采集网关

    使用.net core 基于树莓采集网关1-基础准备罗里吧嗦:  本人之前一直从事的电控工作 就是PLC 触摸屏 变频器这些,后台由于换工作接触到了工业物联网,就是现在很火热的现场设备采集,后来
    发表于 07-02 06:13

    TensorFlow实战之深度学习框架的对比

    Google近日发布了TensorFlow 1.0候选版,这第一个稳定版将是深度学习框架发展中的里程碑的一步。自TensorFlow于2015年底正式开源,距今已有一年多,这期间
    发表于 11-16 11:52 ?4781次阅读
    <b class='flag-5'>TensorFlow</b>实战之<b class='flag-5'>深度</b><b class='flag-5'>学习</b>框架的对比

    树莓什么语言编程_树莓python编程详解

    树莓是一个非常廉价的、只有手掌大小的完全可编程的计算机。虽然树莓的体积小,但是它的潜力无限。你可以像使用常规台式计算机一样在树莓派上创建
    发表于 01-15 17:00 ?3.9w次阅读

    树莓怎么

    连接树莓和电脑.网线直连电脑,不经过路由器。这个方法最大的特点最少的工具玩树莓
    的头像 发表于 11-07 16:21 ?2.4w次阅读

    使用树莓设计智能小车教程之树莓小车启动教程免费下载

    本文档的主要内容详细介绍的是使用树莓设计智能小车教程之树莓小车启动教程免费下载。
    发表于 06-24 08:00 ?33次下载
    使用<b class='flag-5'>树莓</b><b class='flag-5'>派</b>设计智能小车教程之<b class='flag-5'>树莓</b><b class='flag-5'>派</b>小车<b class='flag-5'>启动</b>教程免费下载

    树莓的摄像头应该如何启动详细教程免费下载

    本文档的主要内容详细介绍的是使用树莓设计智能小车的树莓摄像头应该如何启动详细教程免费下载。
    发表于 06-24 08:00 ?9次下载

    使用树莓设计智能小车教程之树莓智能车系统启动的详细资料说明

    本文档的主要内容详细介绍的是使用树莓设计智能小车教程之树莓智能车系统启动的详细资料说明。
    发表于 06-24 08:00 ?18次下载

    树莓学习设计方案合集

    本文档的主要内容详细介绍的是树莓学习设计方案合集免费下载包括了:AMG8833 8x8红外热像仪传感器应用附PCB驱动源码,Arduino与树莓
    发表于 03-11 08:00 ?12次下载
    <b class='flag-5'>树莓</b><b class='flag-5'>派</b>的<b class='flag-5'>学习</b>设计方案合集

    使用TensorFlow建立深度学习和机器学习网络

    教你使用TensorFlow建立深度学习和机器学习网络。
    发表于 03-26 09:44 ?18次下载

    TensorFlow手势识别树莓开源

    电子发烧友网站提供《TensorFlow手势识别树莓开源.zip》资料免费下载
    发表于 11-09 09:27 ?1次下载
    <b class='flag-5'>TensorFlow</b>手势识别<b class='flag-5'>树莓</b><b class='flag-5'>派</b>开源

    树莓4b学习笔记

    ,那时候使用的还是老版的3b。时间一晃,转眼就6年了,在家闲着无事,想着树莓做一些视觉开发的项目(因为便宜、好上手),然而,淘宝一搜,好家伙,这款19年上市的4b价格涨价太多,5b迟迟又不
    的头像 发表于 07-04 11:25 ?7691次阅读
    <b class='flag-5'>树莓</b><b class='flag-5'>派</b>4b<b class='flag-5'>学习</b>笔记

    深度学习框架tensorflow介绍

    深度学习框架tensorflow介绍 深度学习框架TensorFlow简介
    的头像 发表于 08-17 16:11 ?3037次阅读

    树莓分类器:树莓识别不同型号的树莓

    在本教程系列的第一部分中,您将学习如何使用树莓AI摄像头来检测不同的树莓型号。本系列由DavidPlowman创建,他是
    的头像 发表于 06-13 16:39 ?489次阅读
    <b class='flag-5'>树莓</b><b class='flag-5'>派</b>分类器:<b class='flag-5'>用</b><b class='flag-5'>树莓</b><b class='flag-5'>派</b>识别不同型号的<b class='flag-5'>树莓</b><b class='flag-5'>派</b>!