0006 MPTPU(M.2 E):修订间差异

来自Mcuzone Wiki
无编辑摘要
第244行: 第244行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_30.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_30.jpg


=== 5.2 运行代码 ===
模组下载完成后返回 coral/pycoral路径下
模组下载完成后返回 coral/pycoral路径下



2024年7月19日 (五) 15:10的版本

关键词

树莓派5、PCIE、TPU、DTPU、驱动安装、操作演示、AI、google、Coral

一、简介

MPW7/TPU是一款专为树莓派5设计的TPU扩展板,通过PCIE 1x Gen2驱动来自Coral的TPU模组。树莓派系统下使用TPU模块需要安装驱动以及操作环境配置,本文操作演示基于MPW7/TPU扩展板,对于双TPU的驱动安装也适用。

注意:此操作演示需要确保能连通外网(需自备方法),否则许多文件无法下载。

二、硬件资源

关于双TPU的官方描述(本文档所演示的单TPU也可参考此描述):

PRODUCT DETAILS

The Coral M.2 Accelerator with Dual Edge TPU is an M.2 module that brings two Edge TPU coprocessors to existing systems and products with an available M.2 E-key slot.

Features

Performs high-speed ML inferencing: Each Edge TPU coprocessor is capable of performing 4 trillion operations per second (4 TOPS), using 2 watts of power. For example, it can execute state-of-the-art mobile vision models such as MobileNet v2 at almost 400 FPS, in a power-efficient manner. With the two Edge TPUs in this module, you can double the inferences per second (8 TOPS) in several ways, such as by running two models in parallel or pipelining one model across both Edge TPUs.

Works with Debian Linux and Windows: Integrates with Debian-based Linux or Windows 10 systems with a compatible card module slot.

Supports TensorFlow Lite: No need to build models from the ground up. TensorFlow Lite models can be compiled to run on the Edge TPU.

Supports AutoML Vision Edge: Easily build and deploy fast, high-accuracy custom image classification models to your device with AutoML Vision Edge.

Description

The Coral M.2 Accelerator with Dual Edge TPU is an M.2 module (E-key) that includes two Edge TPU ML accelerators, each with their own PCIe Gen2 x1 interface.

The Edge TPU is a small ASIC designed by Google that accelerates TensorFlow Lite models in a power efficient manner: each one is capable of performing 4 trillion operations per second (4 TOPS), using 2 watts of power—that's 2 TOPS per watt. For example, one Edge TPU can execute state-of-the-art mobile vision models such as MobileNet v2 at almost 400 frames per second. This on-device ML processing reduces latency, increases data privacy, and removes the need for a constant internet connection.

With the two Edge TPUs in this module, you can double the inferences per second (8 TOPS) in several ways, such as by running two models in parallel or pipelining one model across both Edge TPUs.

三、系统烧写

3.1 本文档使用的镜像为2024-07-04-raspios-bookworm-arm64-full.img.xz(树莓派OS,Raspberry Pi OS with desktop and recommended software)。

树莓派OS下载地址:

https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit

3.2 系统烧写在SD(TF)卡上,点击直达烧写方法说明

四、驱动安装与配置

4.1 配置config.txt

系统启动后打开树莓派终端输入命令:

sudo nano /boot/firmware/config.txt

在文件最下方添加以下代码:

dtparam=pciex1

kernel=kernel8.img

dtoverlay=pineboards-hat-ai

0006_MPW7_TPU_01.jpg

0006_MPW7_TPU_02.jpg

代码添加成功后,保存并重启系统:

sudo reboot

4.2 确认软件环境

系统重启后打开打开树莓派终端输入命令:

uname -r

确保内核版本大于4.18后输入:

lsmod | grep apex

确保没有输出则可以开始安装TPU驱动。

0006_MPW7_TPU_03.jpg

4.3 安装必要软件

确保网络能连通外网(需自备方法)后,添加Google TPU软件库:

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

0006_MPW7_TPU_04.jpg

添加完成后更新软件列表:

sudo apt-get update

0006_MPW7_TPU_06.jpg

更新完成后安装必要的软件:

sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms

0006_MPW7_TPU_07.jpg

0006_MPW7_TPU_08.jpg

4.4 安装Gasket Driver

依次输入以下命令安装Gasket Driver:

git clone https://github.com/google/gasket-driver.git

cd gasket-driver

sudo debuild -us -uc -tc -b

cd ..

sudo dpkg -i gasket-dkms_1.0-18_all.deb

0006_MPW7_TPU_09.jpg

0006_MPW7_TPU_10.jpg

0006_MPW7_TPU_11.jpg

安装完成后输入以下命令确保驱动以及软件安装成功:

sudo apt-get install gasket-dkms libedgetpu1-std

0006_MPW7_TPU_12.jpg

接下来添加udev rule去获得设备操作权限:

sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"

添加用户到apex:

sudo groupadd apex

sudo adduser $USER apex

0006_MPW7_TPU_13.jpg

设置完成后重启系统:

sudo reboot

4.5 验证模块检测以及驱动安装

系统启动后验证模块检测以及驱动安装:

lspci -nn | grep 089a

ls /dev/apex_0

0006_MPW7_TPU_14.jpg

这里板载单TPU,因此可以看到一个TPU模块。

输入sudo lspci -v可以看到驱动加载:

0006_MPW7_TPU_15.jpg

4.6 代码运行环境配置

Google TPU模块代码运行需要在Python3.6-3.9之间,而树莓派最新系统的Python版本为3.11,因此我们需要使用Pyenv来下载老版本Python。

首先进行依赖安装:

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl

0006_MPW7_TPU_17.jpg

0006_MPW7_TPU_18.jpg

依赖安装完成后进行pyenv的安装:

curl https://pyenv.run | bash

0006_MPW7_TPU_19.jpg

输入sudo nano ~/.bashrc,在文件最下面添加以下代码:

export PYENV_ROOT="$HOME/.pyenv"

[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init -)"

0006_MPW7_TPU_20.jpg

0006_MPW7_TPU_21.jpg

添加完成后保存退出并重新加载shell:

exec "$SHELL"

0006_MPW7_TPU_22.jpg

接下来我们可以利用pyenv安装老系统版本Python:

pyenv install -v 3.8.8

0006_MPW7_TPU_23.jpg

0006_MPW7_TPU_24.jpg

等待安装成功后我们将系统Python版本更改为3.8.8:

pyenv global 3.8.8

更改成功后可以查看当前Python使用版本为3.8.8:

pyenv versions

python3 -V

0006_MPW7_TPU_25.jpg

五、下载和运行演示代码

5.1 下载代码和运行模组

依次输入以下命令进行下载:

mkdir coral && cd coral

git clone https://github.com/google-coral/pycoral.git

cd pycoral

cd test_data

git clone https://github.com/google-coral/test_data.git

0006_MPW7_TPU_26.jpg

0006_MPW7_TPU_27.jpg

接下来下载代码运行模组

pip3 install numpy

0006_MPW7_TPU_28.jpg

pip3 install Pillow

0006_MPW7_TPU_29.jpg

pip3 install --extra-index-url https://google-coral.github.io/py-repo/ pycoral

0006_MPW7_TPU_30.jpg

5.2 运行代码

模组下载完成后返回 coral/pycoral路径下

cd ..

输入以下代码进行代码运行

python3 examples/classify_image.py \

--model test_data/test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \

--labels test_data/test_data/inat_bird_labels.txt \

--input test_data/test_data/parrot.jpg

0006_MPW7_TPU_31.jpg

联系我们

4f7e81daf8791971.jpg 79c020da7ad0af9b.jpg 2851e01a0549e6f7.gif 0003_bb.jpg 0005_qq.jpg QQ:8204136

邮件:mcuzone@vip.qq.com

电话:13957118045

如本页面有任何疏漏、错误或者侵权,请通过上述途径联系我们,谢谢!

Copyright 2004-2024 野芯科技