友善之臂NanoPC-T4 RK3399 配置 安装TensorFlow2 Pytorch

1.简单介绍

官方文档地址:http://wiki.friendlyarm.com/wiki/index.php/NanoPC-T4/zh

用户与密码

普通用户

   用户名: pi
   密码: pi

root用户

   用户名: root
   密码: fa

2.改系统

默认发来是Android系统,板子支持Linux16和18的系统,分别是Lubuntu16.04和友善定制friendlydesktop18.04系统。

-安卓改Linux避坑

  1. AdnroidTools工具配置问题
    第一坑是,下载官方的AdnroidTools工具,按照教程在AdnroidTools工具中配置烧录选项,发现没有rootfs和userdata选项,这两项可以手动添加,可是很麻烦,而且容易出错。实际上,下载来的系统压缩包解压之后的文件夹中包含的有配置好的AdnroidTools,以管理员身份运行可直接烧录,无需额外配置。
  2. 烧写之后显示器黑屏
    按照第二坑是官方文档使用Type-C线刷改系统,首先要在AdnroidTools界面上,选择 “升级固件”,点击界面上的固件按钮,选择固件目录下的文件: MiniLoaderAll.bin,然后点击“擦除Flash”。可是擦出Flash之后,设备变成Maskrom设备,此时再进行线刷,烧录的系统启动后显示器不亮。
    解决方法是换SD卡刷,用官方提供的工具将镜像烧进SD卡,再用卡刷完成改系统,并且卡刷的时候 "low format"选项需要勾上,不然依旧黑屏。

总结一下:建议直接按照官方文档用SD烧写系统,烧写的时候记得勾选"low format"选项。如果线刷后显示器黑屏,要用卡刷旧。

3.换源

RK3399 是基于ARM8架构的芯片,arm linux改源需要用arm linux源。

-备份官方源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bcakup

-换国内源

针对RK3399 Ubuntu18
arm ubuntu 使用的源是 ubuntu-ports,我们用华为的云镜像,https://mirrors.huaweicloud.com/
选择arm类->Ubuntu-Ports
在这里插入图片描述
list文件选择bionic(bionic是ubuntu版本的代号,查见https://blog.csdn.net/zhengmx100/article/details/78352773

那么按照华为云镜像官方的提示,在终端执行:

sudo cp -a /etc/apt/sources.list /etc/apt/sources.list.bak
sudo wget -O /etc/apt/sources.list https://mirrors.huaweicloud.com/repository/conf/Ubuntu-Ports-bionic.list

即可

网上常见更新法

首先允许gedit被访问:

xhost +

然后通过gedit打开sources.list文件

sudo gedit /etc/apt/sources.list

清空文件内的内容,然后选择源添加到文件当中,保存并退出。
这里推荐使用华为源。

–清华源:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-proposed main restricted universe multiverse
–华为源(据说很快):
deb https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-security main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-updates main restricted universe multiverse

deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse
deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-backports main restricted universe multiverse

## Not recommended
# deb https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse
# deb-src https://repo.huaweicloud.com/ubuntu-ports/ bionic-proposed main restricted universe multiverse

-更新软件列表和升级

在终端上执行以下命令更新软件列表,检测出可以更新的软件:

sudo apt-get update #更新源

在终端上执行以下命令进行软件更新:

sudo apt-get upgrade #  更新已安装的包

更新完了记得执行:

sudo apt-get clean && sudo apt-get autoclean #清理无用的包

清楚apt 的缓存

4.文件传输

-U盘传输文件

-通过XFTP传输

确保设备和主机在同一局域网内,首先在系统中启动终端并执行命令:

ifconfig

得到如下
在这里插入图片描述
在wlan0中找到inet 地址,也就是ip地址。此处的inet地址为 172.19.19.5,记住这个地址。

然后打开Xftp软件,新建连接,配置如下:
在这里插入图片描述
其中主机的位置就填写刚刚得到的ip地址(苏州大学未申请静态IP的设备在重启之后可能会被分配新的IP地址,所以连接前注意查看ip地址)。

5.远程连接

远程连接用的是Xshell软件,建立连接的方式类似Xftp,可通过Xshell操作设备的终端。
在这里插入图片描述

6.安装Mini-forge

https://github.com/conda-forge/miniforge/releases下载最新的arm8版本,也就是aarch64版本,此处我下载的是Miniforge-pypy3-Linux-aarch64.sh
这里我最开始安装的是Miniforge-pypy3-4.9.2-0-Linux-aarch64.sh,不过在安装tensorflow lite 的轮子时报错不支持此平台,后安装Miniforge-pypy3-Linux-aarch64.sh问题解决。
在这里插入图片描述

终端cd到 下载文件所在的目录,执行:

sudo bash Miniforge-pypy3-Linux-aarch64.sh

一路enter,然后输入yes之后安装。
安装完成之后执行命令:

sudo gedit ~/.bashrc

在文件最后添加

export PATH=$PATH:/home/pi/miniforge3/bin

注意这里/home/pi/miniforge3/bin是miniforge安装目录下的bin目录位置,安装时观察好安装位置

保存之后执行命令:

source ~/.bashrc

立即生效。

使用命令:

conda init

以初始化conda
重启终端。
即可看到conda基础环境,其他例如新建虚拟环境等操作类似Anaconda。

如果提示conda: command not found,就是 在 export的时候,miniforge安装的位置没填正确,正确修改后即可。

如果遇到 The current user does not have wrote permissions to a required path 错误
cd到conda安装目录的父级目录,执行:

sudo chown -R pi miniforge-pypy3 # pi 是用户名, miniforge-pypy3是安装目录

7.编译安装MNN

环境要求:

  • cmake(建议使用3.10或以上版本)、
  • protobuf(使用3.0或以上版本)
  • gcc(使用4.9或以上版本)

环境检查代码:

cmake --version
protoc --version
gcc --version

首先在终端cd到工作目录,然后执行一下命令下载Mini-forge:

git clone https://https://github.com/alibaba/MNN

下载之后在工作目录下会出现MNN目录。

-编译推理部分

cd /path/to/MNN
./schema/generate.sh
mkdir build && cd build && cmake .. && make -j8

-编译训练部分

保持终端工作目录不变,执行:

cmake .. -DMNN_BUILD_TRAIN=ON && make -j8

编译完成后运行:

./runTrainDemo.out

如果有信息表示编译成功:

Usage: ./runTrainDemo.out CASENAME [ARGS]
Valid Case:
DataLoaderDemo
DataLoaderTest
DistillTrainQuant
ImageDatasetDemo
LinearRegress
MatMulGradTest
MnistInt8Train
MnistTrain
MnistTrainSnapshot
MobilenetV2PostTrain
MobilenetV2Train
MobilenetV2TrainQuant
MobilenetV2Transfer
NNGrad
NNGradV2
NNGradV3
OctaveMnist
PostTrain
PostTrainMobilenet
QuanByMSE
QuanMnist
TestMSE

-编译转换部分

保持终端工作目录不变,执行:

cmake .. -DMNN_BUILD_CONVERTER=true && make -j8

-姿态检测Demo

准备工作:

cd MNN/build
cmake -DMNN_BUILD_DEMO=ON .. && make -j8

下载原始的Tensorflow模型。链接:https://pan.baidu.com/s/1QbEgh1kUjl2Kpi2ouwWfUA提取码: rusy

使用模型转换工具将pb模型转换为 MNN 模型。

cd MNN/build
./MNNConvert -f TF --modelFile model-mobilenet_v1_075.pb --MNNModel donkey.mnn --bizCode biz

将转换之后的donkey.mnn模型复制到MNN/demo/exec文件夹下,执行行姿态检测。

cd MNN/demo/exec
./multiPose.out donkey.mnn input.jpg pose.png

8.安装MNN Python API

首先需要完成以上编译工作,其次需要在python中安装numpy

cd到目录MNN/pymnn/pip_package,执行:

python build_deps.py

完成之后,打开build_manylinux2014.sh,将16行的/opt/python/*/bin改为自己pip所在位置
例如我的pip位置是home/pi/miniforge-pypy3/bin

改完之后保存,执行命令:

bash build_manylinux2014.sh

等待执行完成之后就能得到轮子了。
得到wheel包之后安装一下

9.安装TensorFlow 2.X

在arm8 linux 上安装TF2又需要编译,很麻烦,所以我们用人家编译好的。

环境:

Python3.7或者Python3.5

推荐Python3.7版本,首先到https://github.com/lhelontra/tensorflow-on-arm/releases下载编译好的aarch64版本的.whl文件。本文成功安装tensorflow-2.3.0-cp37-none-linux_aarch64.whl,其他情况未测试。

准备:

1.安装依赖:

sudo apt-get install pkg-config libhdf5-100 libhdf5-dev gfortran libopenblas-dev liblapack-dev

2.安装tensorflow-2.3.0-cp37-none-linux_aarch64.whl:

pip install tensorflow-2.3.0-cp37-none-linux_aarch64.whl

等待安装完成。

10.安装TensorFLow Lite Python API

TensorFLow Lite Python API的安装很简单,只要一行代码。首先来到https://tensorflow.google.cn/lite/guide/python,找到 Python版本快速入门:
在这里插入图片描述
我是miniforge虚拟环境,并且是aarch64,所以执行命令:

pip install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_aarch64.whl

等待安装完成即可。

11.安装Pytorch和Torchvision

在arm上安装Pytorch和Torchvision依旧需要从源码编译,异常的麻烦。所以我们直接用编译好的:
Pytorch 1.1/1.2:https://github.com/nmilosev/pytorch-arm-builds
Pytorch 1.5/1.6:https://github.com/gauravs900/pytorch_arm_aarch64_builds

环境:

python3.7

依赖:

sudo apt install libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools python3-wheel python3-pillow python3-numpy

执行:

cd /pathTo/PytorchWheel
pip install torch-1.6.0a0+8682ac1-cp37-cp37m-linux_aarch64.whl
pip install torchvision-0.7.0a0+6631b74-cp37-cp37m-linux_aarch64.whl
# 我实在conda虚拟环境下安装的,所以执行的是pip install,系统环境请执行pip3 install。
# 安装的文件名根据自己下载的版本而定。

畅通无阻,无痛安装。
爱折腾的朋友可以参考编译树莓派的Pytorch的教程:https://nmilosev.svbtle.com/compling-arm-stuff-without-an-arm-board-build-pytorch-for-the-raspberry-pi

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
NanoPC-T4上使用QT实现DHT11的步骤与在Arduino上实现类似,只需要将传感器连接到NanoPC-T4上,并使用GPIO库读取传感器数据。下面是一个简单的步骤: 1. 首先,你需要在NanoPC-T4安装QT,并在QT中安装GPIO库,这可以通过以下命令来完成: ``` sudo apt-get update sudo apt-get install qtbase5-dev sudo apt-get install qtdeclarative5-dev sudo apt-get install qml-module-qtquick-controls sudo apt-get install qml-module-qtquick-dialogs sudo apt-get install qml-module-qtquick-layouts sudo apt-get install qml-module-qtquick-window2 sudo apt-get install qml-module-qt-labs-settings sudo apt-get install libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5widgets5 libqt5serialport5-dev ``` 2. 将DHT11模块连接到NanoPC-T4上。将DHT11的VCC引脚连接到NanoPC-T4的5V引脚,将GND引脚连接到NanoPC-T4的GND引脚,将DHT11的数据引脚连接到NanoPC-T4上的GPIO引脚上(例如:GPIOA0)。 3. 在QT中创建一个新的项目,并在项目中添加以下代码: ```c++ #include <QCoreApplication> #include <QDebug> #include <wiringPi.h> #include <dht.h> #define DHTPIN 0 // DHT11数据引脚的GPIO引脚 #define DHTTYPE DHT11 // DHT11传感器类型 dht DHT; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); if (wiringPiSetup () == -1) // 初始化wiringPi库 { qDebug() << "Failed to setup wiringPi!"; return -1; } while(1) { int chk = DHT.read11(DHTPIN); // 读取DHT11传感器 qDebug() << "湿度: " << DHT.humidity << "%, " << "温度: " << DHT.temperature << "°C"; delay(1000); // 稍作延迟 } return a.exec(); } ``` 4. 编译并运行代码。你将在QT控制台中看到DHT11传感器的湿度和温度数据。 这就是在NanoPC-T4上使用QT实现DHT11的基本步骤。你可以根据你的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值