Atlas 500 Docker ATC模型转换镜像搭建
1 Docker 概述
根据百度百科的定义,Docker 是一个开源的跨平台(Linux操作系统、Windows操作系统等)的应用容器引擎,让开发者可以以统一的方式打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何安装了Docker引擎的服务器上,即是一种非常轻量级的虚拟化实现技术。Docker 容器使用沙箱机制,相互之间不会有影响。另外,Docker 相对于其他的虚拟机技术,非常的轻量级,因此资源占用少,启动非常快,可以在几秒进行启动。最后,Docker 不依赖于任何语言、框架。可以很容易地在单台物理机上运行几十个或者上百个Docker容器。正是由于这些特点,Docker被广泛应用于IT领域。
Docker中有镜像image和容器container的概念,其中类比于面向对象编程当中的类和实例。镜像是静态的,可以导入或者导出文件。容器可以由镜像启动,并可以对外提供服务。另外,容器可以保存为镜像。
2 前提条件
这里我们已经安装完成了Ubuntu 18.04的宿主机(是VirtualBox虚拟机),当前虚拟机可以联网。首先确保当前的Ubuntu 18.04的宿主机安装了Docker环境,如果没有,可以在线安装,命令如下:
#切换root
su root
#安装docker
apt install docker.io
#查看版本
docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu5~18.04.3
另外,这里是一个在非昇腾设备上(Ubuntu 18.04 CPU是x86架构)安装CANN 相关软件,并支持ATC模型转换功能,查看当前架构命令如下所示:
uname -m
x86_64
从昇腾官网硬件平台(https://www.hiascend.com/hardware/firmware-drivers?tag=commercial)上下载需要的软件项:
A300-3010-npu-driver_21.0.2_linux-x86_64.run ( arm架构下载 A300-3000-3010-npu-driver_21.0.2_linux-aarch64.run )示意界面如下所示:
注意:非昇腾设备上如果只是搭建ATC模型转换功能,可以不安装此驱动软件。
在昇腾官网 https://www.hiascend.com/software/cann/commercial 软件平台上下载CANN软件,界面如下所示:
注意:下载软件需要提升权限,否则无法下载。可以下载社区版或者联系华为对接人员索取下载链接。
下载的软件清单如下所示:
A300-3010-npu-driver_21.0.2_linux-x86_64.run (驱动,此处不安装)
Ascend-cann-nnrt_5.0.2.1_linux-x86_64.run (推理,安装)
Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run (工具,安装)
Ascend-cann-nnae_5.0.2.1_linux-x86_64.run (训练,此处不安装)
Python-3.7.5.tgz (编译安装,需要一个动态链接库
3 ATC模型转换Docker镜像构建
登录宿主机Ubuntu,切换到root用户,首先用docker pull一个Ubuntu 18.04基础镜像,命令如下所示:
docker pull ubuntu:18.04
拉取成功后,可以用如下命令查看镜像列表,命令如下所示:
docker images
我这里显示界面如下所示:
root@jackpc:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kz-ubuntu-atc 18.04 e64978d6bb98 50 minutes ago 5.91GB
ubuntu 18.04 5a214d77f5d7 7 weeks ago 63.1MB
由此可见,默认拉取的ubuntu:18.04镜像是非常小的,大小为63.1MB 。下面将基于此基础镜像,来构建ATC模型转换的镜像。首先基于ubuntu:18.04镜像启动一个容器,命令如下所示:
docker run -v /home/jack/Downloads:/home/mysoft -it ubuntu:18.04 bash
这里通过 -v 参数挂载宿主机目录/home/jack/Downloads到Docker容器中的/home/mysoft目录,这样便于安装软件的传递。进入容器后,进入bash命令交互界面:
首先,需要检查root用户的umask值。输入命令进行查看:
umask
如果umask不等于0022,执行如下命令,打开.bashrc文件:
vi ~/.bashrc
在文件最后一行后面添加或修改内容:
umask 0022
执行:wq!命令保存文件并退出。用如下界面生效:
source ~/.bashrc
创建HwHiAiUser用户为例:
groupadd HwHiAiUser
useradd -g HwHiAiUser -d /home/HwHiAiUser -m HwHiAiUser -s /bin/bash
设置HwHiAiUser用户密码:
passwd HwHiAiUser
关于CANN软件安装和安装用户的建议,可以参考如下的表格:
为了提高软件下载的速度,这里改为国内的镜像源,操作如下所示:
#更新
apt-get update
#安装vim
apt-get install vim
#备份
cp /etc/apt/sources.list /etc/apt/sources.list.bak
#清空内容
> /etc/apt/sources.list
#编辑
vi /etc/apt/sources.list
填入如下内容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
然后再次支持如下命令,更新源,并安装一些前置的OS依赖项:
apt-get update
apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev openssl libsqlite3-dev libssl-dev libffi-dev unzip pciutils \
net-tools libblas-dev gfortran libblas3 libopenblas-dev libncursesw5-dev
下面需要安装Python环境,这里需要编译安装,命令如下所示:
#wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
tar -zxvf Python-3.7.5.tgz
mv Python-3.7.5 /root
cd /root/Python-3.7.5
./configure --prefix=/usr/local/python3.7.5 --enable-loadable-sqlite-extensions --enable-shared
make
make install
其中--prefix参数用于指定python安装路径,用户根据实际情况进行修改。--enable-shared参数用于编译出libpython3.7m.so.1.0动态库。--enable-loadable-sqlite-extensions参数用于加载libsqlite3-dev依赖。执行配置、编译和安装命令后,安装包在/usr/local/python3.7.5路径,libpython3.7m.so.1.0动态库在/usr/local/python3.7.5/lib/libpython3.7m.so.1.0路径。
可以通过find命令查找文件位置,命令如下所示:
find / -name libpython3.7m.so.1.0
/root/Python-3.7.5/libpython3.7m.so.1.0
/usr/local/python3.7.5/lib/libpython3.7m.so.1.0
当前未配置环境变量,Python相关命令还无法识别,下面配置环境变量:
root@c78f3faab7d6:~# vi ~/.bashrc
#追加如下内容
###################################################
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/python3.7.5/bin:$PATH
###################################################
root@c78f3faab7d6:~# source ~/.bashrc
示意界面如下所示:
下面查看版本信息,命令如下所示:
root@c78f3faab7d6:~# python3 --version
Python 3.7.5
root@c78f3faab7d6:~# pip3 --version
pip 19.2.3 from /usr/local/python3.7.5/lib/python3.7/site-packages/pip (python 3.7)
root@c78f3faab7d6:~#
安装前,建议执行命令pip3 install --upgrade pip进行升级,避免因pip版本过低导致安装失败。命令如下所示:
pip3 install --upgrade pip
pip3 --version
pip 21.3.1 from /usr/local/python3.7.5/lib/python3.7/site-packages/pip (python 3.7)
修改pip源,操作如下所示:
mkdir ~/.pip
cd ~/.pip
vi pip.conf
#######################################################################
[global]
index-url = https://mirrors.huaweicloud.com/repository/pypi/simple
trusted-host = mirrors.huaweicloud.com
timeout = 120
#######################################################################
执行如下命令下载相关依赖性:
pip3 install attrs
pip3 install numpy
pip3 install decorator
pip3 install sympy
pip3 install cffi
pip3 install pyyaml
pip3 install pathlib2
pip3 install psutil
pip3 install protobuf
pip3 install scipy
pip3 install requests
下面开始安装CANN软件:
cd /home/mysoft/
#可执行权限
chmod +x A*.run
#安装NNRT
./Ascend-cann-nnrt_5.0.2.1_linux-x86_64.run --install
输出信息如下所示:
root@c78f3faab7d6:/home/mysoft# ./Ascend-cann-nnrt_5.0.2.1_linux-x86_64.run --install
Verifying archive integrity... 100% SHA256 checksums are OK. All good.
Uncompressing ASCEND_RUN_PACKAGE 100%
[NNRT] [20211124-08:10:16] [INFO] mkdir /usr/local/Ascend/nnrt/5.0.2.1/x86_64-linux
[NNRT] [20211124-08:10:16] [INFO] mkdir /var/log/ascend_seclog/
[NNRT] [20211124-08:10:16] [INFO] touch /var/log/ascend_seclog/ascend_nnrt_install.log
[NNRT] [20211124-08:10:16] [INFO] LogFile:/var/log/ascend_seclog/ascend_nnrt_install.log
[NNRT] [20211124-08:10:16] [INFO] install start
[NNRT] [20211124-08:10:16] [INFO] The install path is /usr/local/Ascend !
[NNRT] [20211124-08:10:16] [WARNING] driver package maybe not installed
[NNRT] [20211124-08:10:16] [WARNING] driver package maybe not installed
[NNRT] [20211124-08:10:16] [INFO] install package Ascend-acllib-1.78.23.34.230-linux.x86_64.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend-acllib-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend-pyACL-5.0.2.1-linux.x86_64.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend-pyACL-5.0.2.1-linux.x86_64.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend310-aicpu_kernels-1.78.23.34.230.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend310-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend710-aicpu_kernels-1.78.23.34.230.run start
[NNRT] [20211124-08:10:19] [INFO] Ascend710-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:19] [INFO] install package Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run start
[NNRT] [20211124-08:10:20] [INFO] Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:20] [INFO] install package Ascend-test-ops-5.0.2.1.run start
[NNRT] [20211124-08:10:20] [INFO] Ascend-test-ops-5.0.2.1.run --full --quiet --nox11 install success
[NNRT] [20211124-08:10:20] [INFO] /etc/Ascend/ascend_cann_install.info generate success
[NNRT] [20211124-08:10:20] [INFO] Please make sure that:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/nnrt/latest/acllib/lib64:
PYTHONPATH includes :
/usr/local/Ascend/nnrt/latest/pyACL/python/site-packages/acl:
ASCEND_AICPU_PATH includes :
/usr/local/Ascend/nnrt/latest:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/nnrt/latest/opp:
[NNRT] [20211124-08:10:20] [INFO] If your service is started using the shell script, you can call the /usr/local/Ascend/nnrt/set_env.sh script to configure environment variables. Note that this script can not be executed mannually.
[NNRT] [20211124-08:10:20] [INFO] Ascend-cann-nnrt_5.0.2.1_linux-x86_64 install success,The install path is /usr/local/Ascend !
root@c78f3faab7d6:/home/mysoft#
其中包含一些环境变量,可以拷贝出来进行配置:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/nnrt/latest/acllib/lib64:
PYTHONPATH includes :
/usr/local/Ascend/nnrt/latest/pyACL/python/site-packages/acl:
ASCEND_AICPU_PATH includes :
/usr/local/Ascend/nnrt/latest:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/nnrt/latest/opp:
下面继续安装toolkit ,命令如下所示:
./Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run --install
输出信息如下所示:
root@c78f3faab7d6:/home/mysoft# ./Ascend-cann-nnrt_5.0.2.1_linux-x86_64.run --install
Verifying archive integrity... 100% SHA256 checksums are OK. All good.
Uncompressing ASCEND_RUN_PACKAGE 100%
[NNRT] [20211124-08:10:16] [INFO] mkdir /usr/local/Ascend/nnrt/5.0.2.1/x86_64-linux
[NNRT] [20211124-08:10:16] [INFO] mkdir /var/log/ascend_seclog/
[NNRT] [20211124-08:10:16] [INFO] touch /var/log/ascend_seclog/ascend_nnrt_install.log
[NNRT] [20211124-08:10:16] [INFO] LogFile:/var/log/ascend_seclog/ascend_nnrt_install.log
[NNRT] [20211124-08:10:16] [INFO] install start
[NNRT] [20211124-08:10:16] [INFO] The install path is /usr/local/Ascend !
[NNRT] [20211124-08:10:16] [WARNING] driver package maybe not installed
[NNRT] [20211124-08:10:16] [WARNING] driver package maybe not installed
[NNRT] [20211124-08:10:16] [INFO] install package Ascend-acllib-1.78.23.34.230-linux.x86_64.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend-acllib-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend-pyACL-5.0.2.1-linux.x86_64.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend-pyACL-5.0.2.1-linux.x86_64.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend310-aicpu_kernels-1.78.23.34.230.run start
[NNRT] [20211124-08:10:18] [INFO] Ascend310-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:18] [INFO] install package Ascend710-aicpu_kernels-1.78.23.34.230.run start
[NNRT] [20211124-08:10:19] [INFO] Ascend710-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:19] [INFO] install package Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run start
[NNRT] [20211124-08:10:20] [INFO] Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run --devel --quiet --nox11 install success
[NNRT] [20211124-08:10:20] [INFO] install package Ascend-test-ops-5.0.2.1.run start
[NNRT] [20211124-08:10:20] [INFO] Ascend-test-ops-5.0.2.1.run --full --quiet --nox11 install success
[NNRT] [20211124-08:10:20] [INFO] /etc/Ascend/ascend_cann_install.info generate success
[NNRT] [20211124-08:10:20] [INFO] Please make sure that:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/nnrt/latest/acllib/lib64:
PYTHONPATH includes :
/usr/local/Ascend/nnrt/latest/pyACL/python/site-packages/acl:
ASCEND_AICPU_PATH includes :
/usr/local/Ascend/nnrt/latest:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/nnrt/latest/opp:
[NNRT] [20211124-08:10:20] [INFO] If your service is started using the shell script, you can call the /usr/local/Ascend/nnrt/set_env.sh script to configure environment variables. Note that this script can not be executed mannually.
[NNRT] [20211124-08:10:20] [INFO] Ascend-cann-nnrt_5.0.2.1_linux-x86_64 install success,The install path is /usr/local/Ascend !
root@c78f3faab7d6:/home/mysoft# ./Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run --install
Verifying archive integrity... 100% SHA256 checksums are OK. All good.
Uncompressing ASCEND_RUN_PACKAGE 100%
[Toolkit] [20211124-08:14:57] [INFO] mkdir /usr/local/Ascend/ascend-toolkit/5.0.2.1/x86_64-linux
[Toolkit] [20211124-08:14:57] [INFO] touch /var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20211124-08:14:57] [INFO] LogFile:/var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20211124-08:14:57] [INFO] install start
[Toolkit] [20211124-08:14:57] [INFO] The install path is /usr/local/Ascend !
[Toolkit] [20211124-08:14:57] [WARNING] driver package maybe not installed
[Toolkit] [20211124-08:14:57] [WARNING] driver package maybe not installed
[Toolkit] [20211124-08:14:57] [INFO] install package Ascend-acllib-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211124-08:14:58] [INFO] Ascend-acllib-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:14:58] [INFO] install package Ascend-pyACL-5.0.2.1-linux.x86_64.run start
[Toolkit] [20211124-08:14:58] [INFO] Ascend-pyACL-5.0.2.1-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:14:58] [INFO] install package Ascend-atc-1.78.23.34.230-linux.x86_64.run start
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[Toolkit] [20211124-08:15:14] [INFO] Ascend-atc-1.78.23.34.230-linux.x86_64.run --devel --pylocal --quiet --nox11 install success
[Toolkit] [20211124-08:15:14] [INFO] install package Ascend-opp-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211124-08:15:27] [INFO] Ascend-opp-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:15:27] [INFO] install package Ascend-toolkit-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211124-08:15:43] [INFO] Ascend-toolkit-1.78.23.34.230-linux.x86_64.run --devel --pylocal --quiet --nox11 install success
[Toolkit] [20211124-08:15:43] [INFO] install package Ascend310-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211124-08:15:44] [INFO] Ascend310-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:15:44] [INFO] install package Ascend910-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211124-08:15:45] [INFO] Ascend910-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:15:45] [INFO] install package Ascend710-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211124-08:15:46] [INFO] Ascend710-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:15:46] [INFO] install package Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run start
[Toolkit] [20211124-08:15:47] [INFO] Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211124-08:15:47] [INFO] install package Ascend-test-ops-5.0.2.1.run start
[Toolkit] [20211124-08:15:47] [INFO] Ascend-test-ops-5.0.2.1.run --full --quiet --nox11 install success
[Toolkit] [20211124-08:15:47] [INFO] Please make sure that:
Offline infer develop (cannot coexist with other scenes):
LD_LIBRARY_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:
PYTHONPATH includes :
/usr/local/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl:
/usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
ASCEND_AICPU_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/opp:
TOOLCHAIN_HOME includes :
/usr/local/Ascend/ascend-toolkit/latest/toolkit:
Third party AI framework develop (cannot coexist with other scenes):
PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin:
/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/bin:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64:
PYTHONPATH includes :
/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages:
/usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/opp:
ASCEND_AICPU_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest:
TOOLCHAIN_HOME includes :
/usr/local/Ascend/ascend-toolkit/latest/toolkit:
Model transformation and operator develop (cannot coexist with other scenes):
PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin:
/usr/local/Ascend/ascend-toolkit/latest/atc/bin:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/lib64:
PYTHONPATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/python/site-packages:
/usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/opp:
TOOLCHAIN_HOME includes :
/usr/local/Ascend/ascend-toolkit/latest/toolkit:
[Toolkit] [20211124-08:15:47] [INFO] If your service is started using the shell script, you can call the /usr/local/Ascend/ascend-toolkit/set_env.sh script to configure environment variables. Note that this script can not be executed mannually.
[Toolkit] [20211124-08:15:47] [INFO] Ascend-cann-toolkit_5.0.2.1_linux-x86_64 install success,The install path is /usr/local/Ascend !
root@c78f3faab7d6:/home/mysoft#
其中包含一些环境变量,这些环境变量是区分场景的,如模型转换的变量如下所示:
Model transformation and operator develop (cannot coexist with other scenes):
PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin:
/usr/local/Ascend/ascend-toolkit/latest/atc/bin:
LD_LIBRARY_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/lib64:
PYTHONPATH includes :
/usr/local/Ascend/ascend-toolkit/latest/atc/python/site-packages:
/usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
ASCEND_OPP_PATH includes :
/usr/local/Ascend/ascend-toolkit/latest/opp:
TOOLCHAIN_HOME includes :
/usr/local/Ascend/ascend-toolkit/latest/toolkit:
下面给出环境变量的配置,命令如下所示:
vi ~/.bashrc
内容发生了变化,内容如下:
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/python3.7.5/bin:$PATH
source /usr/local/Ascend/ascend-toolkit/5.0.2.1/x86_64-linux/opp/bin/setenv.bash
source /usr/local/Ascend/ascend-toolkit/5.0.2.1/x86_64-linux/toolkit/bin/setenv.bash
修改内容如下所示:
export LD_LIBRARY_PATH=/usr/local/Ascend/ascend-toolkit/latest/atc/lib64:/usr/local/Ascend/nnrt/latest/acllib/lib64:/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/Ascend/ascend-toolkit/latest/atc/bin:/usr/local/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin:/usr/local/python3.7.5/bin:$PATH
export PYTHONPATH=/usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:/usr/local/Ascend/ascend-toolkit/latest/atc/python/site-packages:/usr/local/Ascend/nnrt/latest/pyACL/python/site-packages/acl:$PYTHONPATH
export ASCEND_AICPU_PATH=/usr/local/Ascend/nnrt/latest:$ASCEND_AICPU_PATH
export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp
export TOOLCHAIN_HOME=/usr/local/Ascend/ascend-toolkit/latest/toolkit:${TOOLCHAIN_HOME}
执行如下命令,查看模型转换工具ATC是否可以识别:
root@c78f3faab7d6:/home/mysoft# atc
输出界面如下所示:
最后,我们测试一下ATC能否正确转换模型,参考如下网站示例:
执行如下命令:
root@c78f3faab7d6:/home/mysoft# cd ~
root@c78f3faab7d6:~# mkdir model
root@c78f3faab7d6:~# cd model/
root@c78f3faab7d6:~/model# ls
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/facedection/face_detection_fp32.caffemodel
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/facedection/face_detection.prototxt
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/facedection/insert_op.cfg
成功执行后,model目录下的内容如下所示:
root@c78f3faab7d6:~/model# ls
face_detection.prototxt face_detection_fp32.caffemodel insert_op.cfg
执行转换,示例如下:
atc --model=./face_detection.prototxt --weight=./face_detection_fp32.caffemodel --framework=0 --output=./face_detection --soc_version=Ascend310 --insert_op_conf=./insert_op.cfg --log=error
执行过程中比较耗时,稍等片刻,执行成功,界面如下所示:
ATC run success, welcome to the next use.
可以看到目录下生成了转换好的om模型:face_detection.om 。下面我们可以将此文件从Docker中拷贝出来:
docker cp c78f3faab7d6:/root/model/face_detection.om /media/sf_atlas500_proj/
这里我们在容器中配置好了ATC环境,那么如何将其保存到镜像呢,执行如下命令(在宿主机环境中执行):
root@jackpc:~# docker commit c78f3faab7d6 atlas-atc:18.04
至此,我们就构建完成了ATC镜像,下次使用时,可以基于atlas-atc镜像,也可以基于容器,启动容器可以更加容器ID,命令如下所示:
docker ps -a
#####################
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c78f3faab7d6 ubuntu:18.04 "bash" About an hour ago Exited (0) 27 seconds ago upbeat_robinson
#####################
docker start c78f3faab7d6
docker attach c78f3faab7d6
界面如下所示:
- 点赞
- 收藏
- 关注作者
评论(0)