树莓派安装Tensorflow2、OpenCV、numpy

本次安装版本为:Tensorflow == 2.2.0, numpy == 1.21.5,OpenCV == 4.5.5,其版本兼容

建议通读全文,再根据需要安装

(本次安装的路径均为:/home/pi/.local/lib/python3.7/site-packages)

(Tensorflow == 2.2.0,Numpy == 1.21.5,OpenCV == 4.5.5的树莓派.img镜像

链接:https://pan.baidu.com/s/17sbbeK59d92LFEA7v2-vDQ

提取码:abrf

无线账号3-124
密码sanjiao124
树莓派账号pi
密名123456
如果系统里没啥重要的环境,建议备份好重要文件,然后格式化,烧写我的镜像。大可不必费劲巴拉的走一遍这个过程【脑壳痛】
更改热点(无线网的账号密码):https://blog.csdn.net/lizhen222222/article/details/122935984(未验证))

先更新和升级软件包:

sudo apt-get update&&sudo apt-get upgrade

接下来正式安装

一,Tensorflow2

1.这些玩意都得安

1.sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev gcc gfortran python-dev libgfortran5 
2.sudo apt-get install -y libatlas3-base libatlas-base-dev libopenblas-dev libopenblas-base libblas-dev 
3.sudo apt-get install -y liblapack-dev cython libatlas-base-dev openmpi-bin libopenmpi-dev python3-dev
4.sudo pip3 install keras_applications==1.0.8 --no-deps
5.sudo pip3 install keras_preprocessing==1.1.0 --no-deps
6.sudo pip3 install h5py==2.9.0
7.sudo pip3 install pybind11
8.pip3 install -U --user six wheel mock
9.wget "https://raw.githubusercontent.com/PINTO0309/Tensorflow-bin/master/tensorflow-2.2.0-cp37-cp37m-linux_armv7l_download.sh"
10../tensorflow-2.2.0-cp37-cp37m-linux_armv7l_download.sh
11.sudo pip3 uninstall tensorflow
12.sudo -H pip3 install tensorflow-2.2.0-cp37-cp37m-linux_armv7l.whl

如果“9.”下载失败了,去下载安装包,注意下载的包要与树莓派对应
下载地址(传送门):github:(https://github.com/lhelontra/tensorflow-on-arm/releases)
(如果下载慢,可用我的另一篇教程加速github加速)
1)查看树莓派位数

getconf LONG_BIT

2)查看树莓派版本

uname -a

在这里插入图片描述
所以我下载的是
在这里插入图片描述
下载好之后拉到树莓派/home/pi/.local/lib/python3.7/site-packages目录下,解压,
终端cd /home/pi/.local/lib/python3.7/site-packages,执行

sudo pip3 install tensorflow-2.2.0-cp37-none-linux_armv7l.whl
(版本号对应修改,即sudo pip3 install+文件名)

2.验证是否安装成功

python3
>>>import tensorflow as tf
>>>tf.__version__

▲PS:查询tensorflow安装路径为:

tf.__path__

二,numpy

pip3 install --target=/home/pi/.local/lib/python3.7/site-packages numpy==1.19.5 -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

2.验证是否安装成功

python3
>>>import numpy
>>>numpy.__version__

或者

pip3 show numpy

三,OpenCV

先扩容,之后重启,在安装

sudo raspi-config

Advanced Options----Expand Filesysterm

1.安装OpenCV相关依赖包

(官方安装步骤:Install OpenCV 4 on your Raspberry Pi(没必要按着官方的做,按接下来的步骤完全可以安装成功))
(安装包下载地址Releases–链接没问题,但同样没必要下载之后再安装)
1)更新和升级软件包:

sudo apt-get update&&sudo apt-get upgrade

2)安装图像I/O包:

sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev

3)安装视频I/O包,方便获取 视频流:

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev

4)为编译 highgui模块,我们需要安装GTK开发库:

sudo apt-get install libfontconfig1-dev libcairo2-dev
sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
sudo apt-get install libgtk2.0-dev libgtk-3-dev

5)安装一些额外项来优化opencv内部操作:

sudo apt-get install libatlas-base-dev gfortran

6)安装适用于HDF5数据集和Qt GUI:

sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5

▲PS:豆瓣安装

pip3 install opencv-python -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

指定安装路径

pip3 install --target=/home/pi/.local/lib/python3.7/site-packages opencv-python

7)所以指定路径下豆瓣安装:

pip3 install --target=/home/pi/.local/lib/python3.7/site-packages opencv-python -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

2.验证是否安装成功

python3
>>>import cv2
>>>cv2.__version__

四,这之后的是安装过程中遇到问题重新安装的步骤,希望你们不会用到

1)a.卸载numpy

sudo pip3 uninstall --target=/home/pi/.local/lib/python3.7/site-packages numpy==1.19.5

b.(这条好用)

pip3 install -U numpy

2)
删除文件夹

sudo rm -rf /

3)用cpu (predict.py)

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"

▲PS.换源

sudo nano /etc/apt/sources.list

#将原有内容用#注释掉

阿里源
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main contrib non-free rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main contrib non-free rpi
清华源
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib rpi
sudo nano /etc/apt/sources.list.d/raspi.list

#将原有内容用#注释掉

阿里源
deb http://mirrors.aliyun.com/raspbian/raspbian/ buster main
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ buster main
清华源
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

Ctrl+X,然后会提示输入Y保存修改、输入N放弃修改

3.更新源、软件

sudo apt-get update&&sudo apt-get upgrade

4.清理垃圾
df -hl 命令可查询当前硬盘使用情况
sudo apt-get autoclean --清理旧版本的软件缓存
sudo apt-get clean–清理所有软件缓存
sudo apt-get autoremove–删除系统不再使用的孤立软件

▲ubuntu安装opencv

sudo apt install cmake
pip install scikit-build

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

安装
pip3 install opencv-python -i https://pypi.douban.com/simple --trust -host=pypi.douban.com

你可能感兴趣的:(tensorflow,树莓派,tensorflow,opencv,numpy)