当前位置:网站首页>[raspberry pie 4B deep learning garbage classification] Chap.1 configure the raspberry pie with keras+tensorflow [deep learning moves]

[raspberry pie 4B deep learning garbage classification] Chap.1 configure the raspberry pie with keras+tensorflow [deep learning moves]

2022-06-09 06:29:00 Jie_ MSD

System environment :2020-08-20-raspios-buster-armhf-full
Engineering requirements :Tensorflow 1.14.0 + Keras 2.2.4 + Python 3.7
Explain the video :https://www.bilibili.com/video/BV1ab4y117jV?spm_id_from=333.999.0.0
Package image file : Please talk about me in private , Free to share ~

1. Good configuration ssh and vnc after , Source change :

First step , Back up the source file first

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak

The second step , Edit system source files

sudo nano /etc/apt/sources.list

The third step , Use the initial source # Comment out , Add the following two lines of image source .Ctrl+O ++ Ctrl+X
【 Be careful 】 The raspberry pie system here is Raspbian-buster System , When writing system source links, you should pay attention to buster, Many online tutorials are before stretch edition , It's easy to make mistakes !

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi

Step four , Save and execute the following command sudo apt-get update, Complete the update package index of the source .

sudo apt-get update&&upgrade

Step five , You also need to change the system source

sudo nano /etc/apt/sources.list.d/raspi.list

use # Comment out the contents of the original document , Replace... With the following : use # Comment out the contents of the original document , Replace... With the following :

deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

Step six , Configure the source change script , change pip Source
New folder :

mkdir ~/.pip
sudo nano ~/.pip/pip.conf

stay pip.conf Enter the following in the file :

timeout=100
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url= http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=
        pypi.tuna.tsinghua.edu.cn
        mirrors.aliyun.com

2.python Virtual environment configuration

First, update the system software package

sudo apt-get update 
sudo apt-get upgrade
sudo rpi-update

Then update your own pip, because Raspbian Self contained pip3 by 9.0.1 edition , Rather old , We use the following command to update pip3:

python3 -m pip install --upgrade pip  

Try after the update pip3 after , Enter command :

pip3 list

Create a new folder ( For virtual environment )

cd Desktop
mkdir tf_pi
cd tf_pi

Install the virtual environment

python3 -m pip install virtualenv

Add environment variables , So that the good thing can be used

sudo chmod -R 777 /root/.bashrc
sudo nano ~/.bashrc

hold

export PATH=/home/pi/.local/bin/:$PATH  

To the end , Add environment variables

source ~/.bashrc

After success : Entire virtual environment

virtualenv env
source env/bin/activate

 Insert picture description here )

3. install tensorflow1.14.0

Download it from your computer :( link )python3.7 Version can only be installed 1.14.0-Buster Version of TensorFlow
link
 Insert picture description here
use U Copy this file to raspberry pie , To build a bag Folder storage
 Insert picture description here

Install dependency packages :

sudo apt install libatlas-base-dev

Install some environment

sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev
python3 -m pip install keras_applications==1.0.8 --no-deps
python3 -m pip install keras_preprocessing==1.1.0 --no-deps
python3 -m pip install h5py==2.9.0
sudo apt-get install -y openmpi-bin libopenmpi-dev
sudo apt-get install -y libatlas-base-dev
python3 -m pip install -U six wheel mock

install tensorflow

cd env
cd bag
pip3 install tensorflow-1.14.0-cp37-none-linux_armv7l.whl

 Insert picture description here

It will take 20 minutes to install here ... If something goes wrong, just do it again ..
Test for success and view the version :

python
import tensorflow as tf
tf.__version__

 Insert picture description here

4. install keras

Install some dependencies

sudo apt-get install libhdf5-serial-dev
pip3 install h5py
sudo apt-get install gfortran
sudo apt install libopenblas-dev
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ pillow
sudo pip3 install pybind11

First download numpy: The first time I found that the installation was successful but the call failed , I think it is numpy The version is too high, resulting in an error
download keras still tensorflow Will automatically download when numpy( It existed before , It will uninstall and then install a higher version of numpy, It didn't exist before , It will directly install the higher version numpy), So download keras, And then unload numpy, Then install the lower version numpy
Take a look numpy edition , It's too high
 Insert picture description here
reinstall

pip3 uninstall numpy
pip3 install numpy==1.16.0

Second download scipy【 direct pip Ninety nine percent of the installations are likely to fail . So download first and then install ... First download this link and copy it to raspberry pie , Then extract it to the specified folder /home/pi/Desktop/tf_pi/env/lib/python3.7/site-packages Next 】
link

 Insert picture description here

cd /home/pi/Desktop/tf_pi/env/bag
tar -zxvf scipy-1.5.4.tar.gz -C /home/pi/Desktop/tf_pi/env/lib/python3.7/site-packages

Then go to this folder to open the installation :【 Various fancy code configurations , It will be installed for about 30 minutes 】

cd /home/pi/Desktop/tf_pi/env/lib/python3.7/site-packages/scipy-1.5.4
python setup.py install

 Insert picture description here

pip3 list Have a look :【 Too six , It's a success 】
 Insert picture description here

Then use this command to install keras:

pip3 install keras\=\=2.2.4

Please note that ; Because in virtualenv Inside , Be sure to avoid sudo pip3 install, Otherwise, it will be installed in the default path ! Find out keras The installation to _ Default The environment , So the call was unsuccessful ,pip list No,

 Insert picture description here
 Insert picture description here

Solution reinstall

<font color=red>pip3 install keras\=\=2.2.4</font>

 Insert picture description here

Remember... After installation reboot Restart for a while .

5. Start testing ;import keras Add in front import os You can ignore the prompt .

because keras It can work with many frameworks , We use tf So there will be backend A hint of
Enter the virtual environment :

cd ~/Desktop/tf_pi
source env/bin/activate
python
import tensorflow as tf
tf.__version__
import keras
print(keras.__version__)

 Insert picture description here

Problems encountered since work ,64 Bit base system installation tensorflow No success , I think the problem is as follows :
①tensorflow And 64 position linux System
②python Language and arm7 And onboard hardware cpu broadcom BCM2711 Problems corresponding to version
③ Various dependencies and arm Hardware correspondence

原网站

版权声明
本文为[Jie_ MSD]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021424522724.html