树莓派4B安装Tensorflow的方法步骤
1.写作背景
Tensorflow官方在2018年宣布,正式发布支持树莓派版本的Tensorflow,编者开始直接用:
pip install tensorflow
进行安装,在安装成功后使用import进行验证时:
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)安装必要的依赖项
$ 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包
$ 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,卸载
$ sudo pip3 uninstall tensorflow
(4)下载Tensorflow
传送门1tensorflow-on-arm
传送门2Tensorflow-bin
选择你要的版本,我选择传送门2的tensorflow-1.15.0-cp37-cp37m-linux_armv7l.whl
$ wget https://github.com/PINTO0309/Tensorflow-bin/raw/master/tensorflow-1.15.0-cp37-cp37m-linux_armv7l.whl
$ sudo pip install tensorflow-1.15.0-cp37-cp37m-linux_armv7l.whl
(4)验证安装是否成功
安装成功后重启终端,运行Python后输入
import tensorflow as tf tf.__version__
应该没有报错且正常输出版本信息。
Python 3.x + Tensorflow v2 系列
Tensorflow2系列的安装过程与1系列类似,不再赘述,直接上过程:
$ 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
Tensorflow-bin
下一篇:python中plt.imshow与cv2.imshow显示颜色问题