1.写作背景
Tensorflow官方在2018年宣布,正式发布支持树莓派版本的Tensorflow,编者开始直接用:
1
|
pip install tensorflow |
进行安装,在安装成功后使用import进行验证时:
1
|
import tensorflow as tf |
出现了如下所示报错:
E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
在花费了大量时间查询资料后,最终得到的解决,故做一个记录。
2.开始前的系统环境与设备
设备:树莓派4B一枚
系统:Raspberry PI OS 2020-5-27版
3.安装过程
Python 3.x + Tensorflow v1 系列
(1)安装必要的依赖项
1
2
3
|
$ sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev gcc gfortran python-dev libgfortran5 \ libatlas3-base libatlas-base-dev libopenblas-dev libopenblas-base libblas-dev \ liblapack-dev cython openmpi-bin libopenmpi-dev libatlas-base-dev python3-dev |
(2) 安装相关python包
1
2
3
4
5
|
$ sudo pip install keras_applications==1.0.8 --no-deps $ sudo pip install keras_preprocessing==1.1.0 --no-deps $ sudo pip install h5py==2.9.0 $ sudo pip install pybind11 $ pip install -U --user six wheel mock |
(3)如果之前安装过tensorflow,卸载
1
|
$ sudo pip3 uninstall tensorflow |
(4)下载Tensorflow
传送门2Tensorflow-bin
选择你要的版本,我选择传送门2的tensorflow-1.15.0-cp37-cp37m-linux_armv7l.whl
1
|
$ wget https: //github .com /PINTO0309/Tensorflow-bin/raw/master/tensorflow-1 .15.0-cp37-cp37m-linux_armv7l.whl |
1
|
$ sudo pip install tensorflow-1.15.0-cp37-cp37m-linux_armv7l.whl |
(4)验证安装是否成功
安装成功后重启终端,运行Python后输入
1
2
|
>> import tensorflow as tf >>tf.__version__ |
应该没有报错且正常输出版本信息。
Python 3.x + Tensorflow v2 系列
Tensorflow2系列的安装过程与1系列类似,不再赘述,直接上过程:
1
2
3
4
5
6
7
8
9
10
11
12
|
$ sudo apt - get install - y libhdf5 - dev libc - ares - dev libeigen3 - dev gcc gfortran python - dev libgfortran5 \ libatlas3 - base libatlas - base - dev libopenblas - dev libopenblas - base libblas - dev \ liblapack - dev cython libatlas - base - dev openmpi - bin libopenmpi - dev python3 - dev $ sudo pip3 install keras_applications = = 1.0 . 8 - - no - deps $ sudo pip3 install keras_preprocessing = = 1.1 . 0 - - no - deps $ sudo pip3 install h5py = = 2.9 . 0 $ sudo pip3 install pybind11 $ pip3 install - U - - user six wheel mock $ wget "https://raw.githubusercontent.com/PINTO0309/Tensorflow-bin/master/tensorflow-2.2.0-cp37-cp37m-linux_armv7l_download.sh" $ . / tensorflow - 2.2 . 0 - cp37 - cp37m - linux_armv7l_download.sh $ sudo pip3 uninstall tensorflow $ sudo - H pip3 install tensorflow - 2.2 . 0 - cp37 - cp37m - linux_armv7l.whl |
4.参考资料
Error installing Tensorflow (cannot find libhdfs.so)
Install Tensorflow 2 on a Raspberry Pi 4
到此这篇关于树莓派4B安装Tensorflow的方法步骤的文章就介绍到这了,更多相关树莓派4B安装Tensorflow内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/qq_44166805/article/details/107344488