昇腾训练营应用第一课笔记

网友投稿 749 2022-05-29

第一步:购买ECS弹性云服务器

昇腾训练营应用营第一课笔记

计费方式选择按需计费,CPU架构选择:鲲鹏计算,资源选择:ai1s.large.4,操作系统选择Ubuntu 18,硬盘40GB应该是足够了。选择流量的位置,建议选择按流量计费,这样带宽无论选择多少,价格都差不多。

第二步:使用mobax登录到ECS远程服务器

第三步:环境准备

1.修改HwHiAiUser密码

passwd HwHiAiUser

2.将python3.7.5设置为默认python环境

rm -rf /usr/bin/python ln -sf /usr/bin/python3.7.5 /usr/bin/python

说明:需要把原来的连接删除才可以连接新的,接下去我们在使用python命令出来的就是python3.7.5的环境了

3.修改HwHiAiUser默认环境为/bin/bash并且切换

vim /etc/passwd

将文件最后一行HwHiAiUser最后的/bin/sh修改为/bin/bash

4.下载环境包

一共有四个,Ascend驱动,CANN_NNRT.CANN_TOOLKIT,MindStudio

退出ROOT用户,使用HwHiAiUser登录进行操作

打开 https://ascend.huawei.com/#/software/cann/community  找到相关的驱动包-。

mkdir download cd download wget https://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run --no-check-certificate wget https://repo.huaweicloud.com/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run --no-check-certificate wget https://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 wget https://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

切换到ROOT用户修改UBUNTU APT源为华为云镜像站

sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list apt-get update

安装依赖库

apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev libbz2-dev openssl libsqlite3-dev libssl-dev libxslt1-dev libffi-dev unzip pciutils net-tools libblas-dev gfortran libblas3 libopenblas-dev libncursesw5-dev

如果遇到error报错的话重新安装一下python3.7就好

apt-get install python3.7

切换回HwHiAiUser用户安装python库

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 -i https://mirrors.huaweicloud.com/repository/pypi/simple

切换到root用户将所有的安装包增加可执行权限

cd /home/HwHiAiUser/download chmod a+x ./A*

使用root用户安装NPU驱动

./A300-3010-npu-driver_20.2.0_ubuntu18.04-x86_64.run --full

安装完成后重启,使用HwHiAiUser设置环境变量

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

然后继续安装njnrt

./Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run --install

将这一段加入到bashrc文件

export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/nnrt/latest/acllib/lib64:$LD_LIBRARY_PATH export PYTHONPATH=/home/HwHiAiUser/Ascend/nnrt/latest/pyACL/python/site-packages/acl:$PYTHONPATH export ASCEND_AICPU_PATH=/home/HwHiAiUser/Ascend/nnrt/latest

安装Toolkit

./Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run --install

离线、在线、模型转换三种场景对应的环境变量:

Offline infer develop (cannot coexist with other scenes): PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin: LD_LIBRARY_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64: PYTHONPATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages: ASCEND_AICPU_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest: ASCEND_OPP_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp: TOOLCHAIN_HOME includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit: Third party AI framework develop (cannot coexist with other scenes): PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/bin: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin: LD_LIBRARY_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/lib64: PYTHONPATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages: ASCEND_OPP_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp: ASCEND_AICPU_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest: TOOLCHAIN_HOME includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit: Model transformation and operator develop (cannot coexist with other scenes): PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/bin: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin: LD_LIBRARY_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/lib64: PYTHONPATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/python/site-packages: /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages: ASCEND_OPP_PATH includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp: TOOLCHAIN_HOME includes : /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit:

安装MindStudio

# 解压mindstudio tar -xvf MindStudio_2.0.0-beta3_linux.tar.gz # 运行 MindStudio/bin/MindStudio.sh

这一步可能会一段报错,根据报错使用root重新安装了一下库就可以解决了

apt-get -y install xterm firefox xdg-utils fonts-droid-fallback fonts-wqy-zenhei fonts-wqy-microhei fonts-arphic-ukai fonts-arphic-uming gnome-keyring apt-get -y install openjdk-8-jdk #非必须看是否会提示缺这个库

使用HwHiAiUser用户安装pip库

pip3 install --user coverage gnureadline pylint matplotlib pandas absl-py -i https://mirrors.huaweicloud.com/repository/pypi/simple

安装完成后再次启动MindStudio

这一步可以直接OK

看到这个界面就说明成功了

进行到这边的时候在PATH位置选择一下toolkit的目录,然后我们新建一个项目

然后项目名字随便,直接下一步到如下界面

这里选择【Asecend App】然后下一步,跟着图选Resnet50,然后完成

根据https://gitee.com/HuaweiAscend/models/tree/master/computer_vision/classification/resnet50 下载原始模型文件

打开MindStudio的终端输入一下命令下载模型文件

mkdir model cd model wget https://gitee.com/HuaweiAscend/models/blob/master/computer_vision/classification/resnet50/resnet50.prototxt wget https://obs-model-ascend.obs.cn-east-2.myhuaweicloud.com/resnet50/resnet50.caffemodel

如果prototxt文件下载有困难的,直接自己VIM新增一个文件,内容如下

下载完成后,回到MindStudio,选择菜单栏【Ascend】-【Model Conver】进行模型转换,设置如下图

后面直接一路下一步即可

出现这一步就说明成功了,回到界面,选择项目右键【Add Model】

模型文件选择前面模型转换时候输出的文件,基本在modelzoo目录下。

打开MindStudio终端,下载推理所需的图片并且执行图片处理程序:

wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/aclsample/dog1_1024_683.jpg wget https://c7xcode.obs.cn-north-4.myhuaweicloud.com/models/aclsample/dog2_1024_683.jpg python ../script/transferPic.py

运行成功后,执行菜单栏里的【build】-【edit config....】编辑配置

然后直接点【build】开始编译

看到sucessful就说明编译成功了,然后在菜单栏找到【RUN】,然后【edit configure】,然后按如下图设置

然后在菜单栏【run】,点击【run】就可以完成本次作业了

出现图上的LOG信息就说明推理成功了。作业也就完成了

昇腾

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:243_Redis_事务_内存回收_分配算法
下一篇:C# 之 文件的输入与输出
相关文章