本文主要是介绍昇腾CANN应用的运行环境部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
昇腾CANN应用的运行环境部署
整体步骤是:Driver——nnrt——Toolkit——MindStudio
首先我们用Ubuntu 18.04,对CANN的环境进行部署,可以去华为云租,自己有的话也可以使用自己的。
1、准备操作
这里我使用了MobaXterm9进行远程连接。
查看用户:cat /etc/passwd
应该显示这样得。如果是sh结尾,应该改成bash。。。vi /etc/passwd
也可以修改密码:passwd HwHiAiUser
随后输入两遍密码就可以了。
更换镜像
编辑vi etc/apt/sources.list
将里面的内容更换成:
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
输入:apt-get update
进行更新。
2、安装一些源
apt源(依赖)
输入下面这条命令:apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev unzip pciutils net-tools libncursesw5-dev
当有错误发生时输入:apt-get install python3.7
运行完以后再次输入上面的命令即可安装成功!
如图及安装完成。
python源 (依赖)
转到用户HuHiAiUser用户下。su - HuHiAiUser
更改pip源:
创建.pip文件夹:mkdir .pip
进入.pip文件夹后创建pip.conf 文件:vim pip.conf
输入以下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
安装python3.7.5 并设置软连接
wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar -zxvf Python-3.7.5.tgz
mkdir /usr/local/python3
cd Python-3.7.5
./configure --prefix=/usr/local/python3
make && make install
#软连接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
退回HuHiAiUser用户下。
配置环境变量vim .bashrc
将下面内容复制到文件最后:
#用于设置python3.7.5库文件路径
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
#如果用户环境存在多个python3版本,则指定使用python3.7.5版本
export PATH=/usr/local/python3.7.5/bin:$PATH
输入:source .bashrc
使环境变量生效。
安装pip源 在后面加–user
pip3.7.5 install attrs
pip3.7.5 install numpy
pip3.7.5 install decorator
pip3.7.5 install sympy==1.4
pip3.7.5 install cffi==1.12.3
pip3.7.5 install pyyaml
pip3.7.5 install pathlib2
pip3.7.5 install psutil
pip3.7.5 install protobuf
pip3.7.5 install scipy
pip3.7.5 install requests
pip3.7.5 install xlrd==1.2.0
命令:
pip3.7.5 install attrs numpy decorator sympy==1.4 cffi==1.12.3 pyyaml pathlib2 psutil protobuf scipy requests xlrd==1.2.0 --user
安装完成。
3、导入我们下载好的所需要的安装包
导入文件步骤:
建立一个目录:mkdir downloads
进入downloads 后传入我们想要的文件。
需要下载的东西:
1、下载驱动包
wgethttps://obs-9be7.obs.cn-east-2.myhuaweicloud.com/turing/resourcecenter/Software/20.2.0/A300-3010%201.0.9/A300-3010-npu-driver_20.2.0_ubuntu18.04-x86_64.run–no-check-certificate
2、下载nnrt和toolkit包
打开https://ascend.huawei.com/#/software/cann/community
找到相关的驱动包的地址:
https://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run
https://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run
到Xshell中做wget
wgethttps://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run–no-check-certificate
wgethttps://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run–no-check-certificate
3、下载MindStudio
wgethttps://obs-9be7.obs.cn-east-2.myhuaweicloud.com/turing/resource/mindstudio/2.0.0-beta3/MindStudio_2.0.0-beta3_linux.tar.gz–no-check-certificate
安装导入的软件包
drive 驱动要在root用户装。其余的b包在业务用户安装。
首先对三个包增加可执行权限:chmod +x A*
安装第一个:./A300-3010-npu-driver_20.2.0_ubuntu18.04-x86_64.run --full
安装完后需要重启:reboot
安装第二个:./Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run --install
首先进入到:
在进行安装:
需要配置环境变量:vim ~/.bashrc
将这三个:
更改成这样:
使环境生效:sourch ~/.bashrc
第二个安装完成。
安装第三个:./Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run --install
已经完成,将框框内的环境变量保存到一个记事本中。vim env.txt
复制进去保存就好了。
安装MindStudio
解压:tar zxvf MindStudio_2.0.0-beta3_linux.tar.gz
进入:cd MindStudio/
进入:cd bin/
执行:./MindStudio.sh
启动时报错:
按照他给的指令进行安装即可;
apt-get -y install xterm firefox xdg-utils openjdk-8-jdk fonts-droid-fallback fonts-wqy-zenhei fonts-wqy-microhei fonts-arphic-ukai fonts-arphic-uming gnome-keyring
完成再次启动。
再次安装python依赖:/usr/local/python3.7.5/bin/pip3 install --user coverage gnureadline pylint matplotlib pandas absl-py
完成依赖安装,再次启动。
出现错误:
Checking MindStudio environment dependencies...
SuccessChecking Python environment dependencies...
SuccessPlease use Python interpreter parameter [ /usr/local/python3.7.5/bin/python3 ] to configure Python SDK.
MobaXterm X11 proxy: Unsupported authorisation protocol
2021-03-31 17:03:25,974 [ 11] ERROR - llij.ide.plugins.PluginManager - UI initialization failed
com.intellij.ide.plugins.StartupAbortedException: UI initialization failedat com.intellij.idea.StartupUtil.lambda$prepareApp$2(StartupUtil.java:188)at java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:884)at java.util.concurrent.CompletableFuture$UniExceptionally.tryFire(CompletableFuture.java:866)at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)at com.intellij.idea.StartupUtil.lambda$scheduleInitUi$9(StartupUtil.java:372)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.CompletionException: java.awt.AWTError: Can't connect to X11 window server using 'localhos t:10.0' as the value of the DISPLAY variable.at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)at java.util.concurrent.CompletableFuture.biRelay(CompletableFuture.java:1298)at java.util.concurrent.CompletableFuture$BiRelay.tryFire(CompletableFuture.java:1284)... 6 more
Caused by: java.awt.AWTError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variab le.at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)at java.security.AccessController.doPrivileged(Native Method)at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:264)at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:131)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:264)at java.awt.Toolkit$2.run(Toolkit.java:860)at java.awt.Toolkit$2.run(Toolkit.java:855)at java.security.AccessController.doPrivileged(Native Method)at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)at java.awt.Toolkit.getEventQueue(Toolkit.java:1736)at java.awt.EventQueue.invokeLater(EventQueue.java:1294)at com.intellij.idea.StartupUtil.lambda$scheduleInitUi$9(StartupUtil.java:323)... 3 more
2021-03-31 17:03:25,989 [ 26] ERROR - llij.ide.plugins.PluginManager - MindStudio 2.0.0 Build #MS-201.8743.12.4
2021-03-31 17:03:25,991 [ 28] ERROR - llij.ide.plugins.PluginManager - JDK: 1.8.0_282; VM: OpenJDK 64-Bit Server VM; Vendor: Private Build
2021-03-31 17:03:25,992 [ 29] ERROR - llij.ide.plugins.PluginManager - OS: LinuxStart Failed: Failed to initialize graphics environmentjava.awt.AWTError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)at java.security.AccessController.doPrivileged(Native Method)at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:264)at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:131)at java.lang.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:264)at java.awt.Toolkit$2.run(Toolkit.java:860)at java.awt.Toolkit$2.run(Toolkit.java:855)at java.security.AccessController.doPrivileged(Native Method)at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)at java.awt.Toolkit.getEventQueue(Toolkit.java:1736)at java.awt.EventQueue.invokeLater(EventQueue.java:1294)at com.intellij.idea.StartupUtil.lambda$scheduleInitUi$9(StartupUtil.java:323)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)-----
JRE 1.8.0_282-8u282-b08-0ubuntu1~18.04-b08 amd64 by Private Build
/usr/lib/jvm/java-8-openjdk-amd64/jre
正常情况下就就应该启动图形页面,但是启动失败:初始化图形环境失败。
原因:
我在用户下安装的python依赖,而不是在root下,在root启动后既可成功开启:
点OK进入MindStudio,即可!
到此为止,全部安装成功,就可以进行下一步操作
4、使用MindStudio验证resnet样例工程
Finsh继续下一步。
创建一个新的工程:
分别为模型开发,算子开发,应用开发。
我们选择应用开发;
界面如此:
在189行找到网址进去:
在原始数据右击复制链接地址:https://gitee.com/HuaweiAscend/models/raw/master/computer_vision/classification/resnet50/resnet50.prototxt
在studio界面找到Terminal:
下载上面的网址内容:
同样操作,复制以后下载下来。
进行模型转换:
出现此界面:
选择下载好的model:
下一步下一步完成即可:
下载图片:
在data里面下载:
添加模型到工程,右击MyApp;
编译:
输入:python3.7.5 ../script/transferPic.py
对图片进行预处理
运行完毕。
全部完成!
这篇关于昇腾CANN应用的运行环境部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!