Atlas 200 DK(Model 3000)安装MindSpore Ascend版本

2024-05-25 22:04

本文主要是介绍Atlas 200 DK(Model 3000)安装MindSpore Ascend版本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、参考资料

mindspore快速安装

二、重要说明

经过博主多次尝试多个版本,Atlas 200 DK(Model 3000)无法安装MindSpore Ascend版本

三、准备工作

1. 测试环境

设备型号:Atlas 200 DK(Model: 3000)
Operating System + Version: Ubuntu 18.04.6 LTS
CPU Type: 8核Cortex-A55
AI CPU number: 2
control CPU number: 6
RAM: 8GB 
miscroSD: 128GB
CANN: 6.0.RC1.alpha005
HwHiAiUser@davinci-mini:~$ npu-smi info -t aicpu-config -i 0 -c 0Current AI CPU number          : 2Current control CPU number     : 6Number of AI CPUs set          : 2Number of control CPUs set     : 6

2. MindSpore与CANN版本对齐

通过 链接 查询MindSpore与Ascend配套软件包的版本配套关系。

在这里插入图片描述

MindSpore与CANN的版本强绑定,如果当前设备无法升级CANN 6.0.1,则无法使用MindSpore 1.10.0

3. 安装mindspore_ascend

详细过程,请参考:pip方式安装MindSpore Ascend 310版本

4. 验证是否安装成功

4.1 方法一

import mindspore as ms# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')
ms.set_context(device_target="Ascend")
ms.set_context(device_id=0)
mindspore.run_check()

如果输出以下结果,则说明mindspore_ascend安装成功。

MindSpore version: 版本号
The result of multiplication calculation is correct, MindSpore has been installed on platform [Ascend] successfully!

4.2 方法二

import numpy as np
import mindspore as ms
import mindspore.ops as opsms.set_context(device_target="Ascend")
x = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
y = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
print(ops.add(x, y))

如果输出以下结果,则说明mindspore_ascend安装成功。

[[[[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]][[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]][[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]]]]

4.3 方法三

ascend310_single_op_sample

这是一个[1, 2, 3, 4][2, 3, 4, 5]相加的简单样例,代码工程目录结构如下:

└─ascend310_single_op_sample├── CMakeLists.txt                    // 编译脚本├── README.md                         // 使用说明├── main.cc                           // 主函数└── tensor_add.mindir                 // MindIR模型文件
unzip ascend310_single_op_sample.zip
cd ascend310_single_op_sample# 编译
cmake . -DMINDSPORE_PATH=`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`
make# 执行
./tensor_add_sample

如果输出以下结果,则说明mindspore_ascend安装成功。

3
5
7
9

四、测试代码

1. 示例一

用MindSpore搭建模型,并进行测试。

"""
MindSpore implementation of `MobileNetV1`.
Refer to MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications.
"""
import timefrom mindspore import nn, Tensor, ops
import mindspore.common.initializer as init
import mindspore as ms
from PIL import Image
from mindcv.data import create_transforms
import numpy as npdef depthwise_separable_conv(inp: int, oup: int, stride: int) -> nn.SequentialCell:return nn.SequentialCell(# dwnn.Conv2d(inp, inp, 3, stride, pad_mode="pad", padding=1, group=inp, has_bias=False),nn.BatchNorm2d(inp),nn.ReLU(),# pwnn.Conv2d(inp, oup, 1, 1, pad_mode="pad", padding=0, has_bias=False),nn.BatchNorm2d(oup),nn.ReLU(),)class MobileNetV1(nn.Cell):r"""MobileNetV1 model class, based on`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_Args:alpha: scale factor of model width. Default: 1.in_channels: number the channels of the input. Default: 3.num_classes: number of classification classes. Default: 1000."""def __init__(self,alpha: float = 1.,in_channels: int = 3,num_classes: int = 1000) -> None:super().__init__()input_channels = int(32 * alpha)# Setting of depth-wise separable conv# c: number of output channel# s: stride of depth-wise convblock_setting = [# c, s[64, 1],[128, 2],[128, 1],[256, 2],[256, 1],[512, 2],[512, 1],[512, 1],[512, 1],[512, 1],[512, 1],[1024, 2],[1024, 1],]features = [nn.Conv2d(in_channels, input_channels, 3, 2, pad_mode="pad", padding=1, has_bias=False),nn.BatchNorm2d(input_channels),nn.ReLU()]for c, s in block_setting:output_channel = int(c * alpha)features.append(depthwise_separable_conv(input_channels, output_channel, s))input_channels = output_channelself.features = nn.SequentialCell(features)# self.pool = GlobalAvgPooling()self.pool = nn.AdaptiveAvgPool2d(output_size=(1, 1))self.classifier = nn.Dense(input_channels, num_classes)self._initialize_weights()def _initialize_weights(self) -> None:"""Initialize weights for cells."""for _, cell in self.cells_and_names():if isinstance(cell, nn.Conv2d):cell.weight.set_data(init.initializer(init.XavierUniform(),cell.weight.shape,cell.weight.dtype))if isinstance(cell, nn.Dense):cell.weight.set_data(init.initializer(init.TruncatedNormal(),cell.weight.shape,cell.weight.dtype))def forward_features(self, x: Tensor) -> Tensor:x = self.features(x)return xdef forward_head(self, x: Tensor) -> Tensor:squeeze = ops.Squeeze(0)x = squeeze(x)x = self.pool(x)squeeze = ops.Squeeze(2)x = squeeze(x)x = x.transpose()x = self.classifier(x)return xdef construct(self, x: Tensor) -> Tensor:x = self.forward_features(x)x = self.forward_head(x)return xdef mobilenet_v1_100_224(pretrained: bool = False, num_classes: int = 1000, in_channels=3, **kwargs) -> MobileNetV1:"""Get MobileNetV1 model without width scaling.Refer to the base class `models.MobileNetV1` for more details."""model = MobileNetV1(alpha=1.0, in_channels=in_channels, num_classes=num_classes, **kwargs)return modelif __name__ == '__main__':# ms.set_context(device_target='GPU')# ms.set_context(device_target='CPU')ms.set_context(device_target="Ascend")ms.set_context(device_id=0)ms.set_seed(1)ms.set_context(mode=ms.PYNATIVE_MODE)img = Image.open("image.jpg").convert("RGB")# create transformtransform_list = create_transforms(dataset_name="imagenet",is_training=False,)transform_list.pop(0)for transform in transform_list:img = transform(img)img = np.expand_dims(img, axis=0)# create modelnetwork = mobilenet_v1_100_224()for i in range(100):# warmupnetwork(ms.Tensor(img))time_begin = time.time()for i in range(1000):# predictnetwork(ms.Tensor(img))time_total = (time.time() - time_begin) * 1000 / 1000print(f"total time is: {time_total}")# print(network)

2. 示例二

调用 mindcv库中的预训练模型进行测试。

"""MindSpore Inference Script
"""import numpy as np
from PIL import Imageimport mindspore as msfrom mindcv.data import create_transforms
from mindcv.models import create_model
import time# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')ms.set_context(device_target='Ascend')
ms.set_context(device_id=0)
ms.set_context(max_device_memory="3.5GB")def main():ms.set_seed(1)ms.set_context(mode=ms.PYNATIVE_MODE)img = Image.open("image.jpg").convert("RGB")# create transformtransform_list = create_transforms(dataset_name="imagenet",is_training=False,)transform_list.pop(0)for transform in transform_list:img = transform(img)img = np.expand_dims(img, axis=0)# create modelnetwork = create_model(model_name="mobilenet_v1_100",  # mobilenet_v1_100_224pretrained=False,)network.set_train(False)for i in range(100):# warmupnetwork(ms.Tensor(img))time_begin = time.time()for i in range(1000):# predictnetwork(ms.Tensor(img))time_total = (time.time() - time_begin) * 1000 / 1000print(f"total time is: {time_total}")if __name__ == "__main__":main()

五、FAQ

Q:RuntimeError: Get acltdt handle failed

File "/home/HwHiAiUser/miniconda3/envs/mindspore19/lib/python3.9/site-packages/mindspore/nn/cell.py", line 120, in __init__init_pipeline()
RuntimeError: Get acltdt handle failed----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------

mindspore_ascend 1.9.0 测试失败。

Q:Load dynamic library libmindspore_ascend failed, returns

[WARNING] ME(22553:281470681698320,MainProcess):2024-05-22-12:56:02.416.603 [mindspore/run_check/_check_version.py:296] MindSpore version 1.10.0 and Ascend AI software package (Ascend Data Center Solution)version 1.83 does not match, the version of software package expect one of ['1.84'], please reference to the match info on: https://www.mindspore.cn/install
[ERROR] ME(22553,fffeffff5010,python):2024-05-22-12:56:02.812.186 [mindspore/ccsrc/runtime/hardware/device_context_manager.cc:46] LoadDynamicLib] Load dynamic library libmindspore_ascend failed, returns [liboptiling.so: cannot open shared object file: No such file or directory].
Traceback (most recent call last):File "/home/HwHiAiUser/Downloads/mindcv_demo.py", line 11, in <module>import mindspore as msFile "/home/HwHiAiUser/miniconda3/envs/mindspore21/lib/python3.9/site-packages/mindspore/__init__.py", line 18, in <module>from mindspore.run_check import run_checkFile "/home/HwHiAiUser/miniconda3/envs/mindspore21/lib/python3.9/site-packages/mindspore/run_check/__init__.py", line 17, in <module>from ._check_version import check_version_and_env_configFile "/home/HwHiAiUser/miniconda3/envs/mindspore21/lib/python3.9/site-packages/mindspore/run_check/_check_version.py", line 474, in <module>check_version_and_env_config()File "/home/HwHiAiUser/miniconda3/envs/mindspore21/lib/python3.9/site-packages/mindspore/run_check/_check_version.py", line 446, in check_version_and_env_configenv_checker.set_env()File "/home/HwHiAiUser/miniconda3/envs/mindspore21/lib/python3.9/site-packages/mindspore/run_check/_check_version.py", line 357, in set_envraise EnvironmentError(
OSError: No such directory: /usr/local/Ascend/ascend-toolkit/latest/opp/built-in/op_impl/ai_core/tbe, Please check if Ascend AI software package (Ascend Data Center Solution) is installed correctly.

mindspore_ascend 1.10.0 测试失败。

这篇关于Atlas 200 DK(Model 3000)安装MindSpore Ascend版本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1002744

相关文章

IDEA如何切换数据库版本mysql5或mysql8

《IDEA如何切换数据库版本mysql5或mysql8》本文介绍了如何将IntelliJIDEA从MySQL5切换到MySQL8的详细步骤,包括下载MySQL8、安装、配置、停止旧服务、启动新服务以及... 目录问题描述解决方案第一步第二步第三步第四步第五步总结问题描述最近想开发一个新应用,想使用mysq

java脚本使用不同版本jdk的说明介绍

《java脚本使用不同版本jdk的说明介绍》本文介绍了在Java中执行JavaScript脚本的几种方式,包括使用ScriptEngine、Nashorn和GraalVM,ScriptEngine适用... 目录Java脚本使用不同版本jdk的说明1.使用ScriptEngine执行javascript2.

龙蜥操作系统Anolis OS-23.x安装配置图解教程(保姆级)

《龙蜥操作系统AnolisOS-23.x安装配置图解教程(保姆级)》:本文主要介绍了安装和配置AnolisOS23.2系统,包括分区、软件选择、设置root密码、网络配置、主机名设置和禁用SELinux的步骤,详细内容请阅读本文,希望能对你有所帮助... ‌AnolisOS‌是由阿里云推出的开源操作系统,旨

Ubuntu系统怎么安装Warp? 新一代AI 终端神器安装使用方法

《Ubuntu系统怎么安装Warp?新一代AI终端神器安装使用方法》Warp是一款使用Rust开发的现代化AI终端工具,该怎么再Ubuntu系统中安装使用呢?下面我们就来看看详细教程... Warp Terminal 是一款使用 Rust 开发的现代化「AI 终端」工具。最初它只支持 MACOS,但在 20

mysql-8.0.30压缩包版安装和配置MySQL环境过程

《mysql-8.0.30压缩包版安装和配置MySQL环境过程》该文章介绍了如何在Windows系统中下载、安装和配置MySQL数据库,包括下载地址、解压文件、创建和配置my.ini文件、设置环境变量... 目录压缩包安装配置下载配置环境变量下载和初始化总结压缩包安装配置下载下载地址:https://d

Debian如何查看系统版本? 7种轻松查看Debian版本信息的实用方法

《Debian如何查看系统版本?7种轻松查看Debian版本信息的实用方法》Debian是一个广泛使用的Linux发行版,用户有时需要查看其版本信息以进行系统管理、故障排除或兼容性检查,在Debia... 作为最受欢迎的 linux 发行版之一,Debian 的版本信息在日常使用和系统维护中起着至关重要的作

LinuxMint怎么安装? Linux Mint22下载安装图文教程

《LinuxMint怎么安装?LinuxMint22下载安装图文教程》LinuxMint22发布以后,有很多新功能,很多朋友想要下载并安装,该怎么操作呢?下面我们就来看看详细安装指南... linux Mint 是一款基于 Ubuntu 的流行发行版,凭借其现代、精致、易于使用的特性,深受小伙伴们所喜爱。对

Linux(Centos7)安装Mysql/Redis/MinIO方式

《Linux(Centos7)安装Mysql/Redis/MinIO方式》文章总结:介绍了如何安装MySQL和Redis,以及如何配置它们为开机自启,还详细讲解了如何安装MinIO,包括配置Syste... 目录安装mysql安装Redis安装MinIO总结安装Mysql安装Redis搜索Red

python安装完成后可以进行的后续步骤和注意事项小结

《python安装完成后可以进行的后续步骤和注意事项小结》本文详细介绍了安装Python3后的后续步骤,包括验证安装、配置环境、安装包、创建和运行脚本,以及使用虚拟环境,还强调了注意事项,如系统更新、... 目录验证安装配置环境(可选)安装python包创建和运行Python脚本虚拟环境(可选)注意事项安装

gradle安装和环境配置全过程

《gradle安装和环境配置全过程》本文介绍了如何安装和配置Gradle环境,包括下载Gradle、配置环境变量、测试Gradle以及在IntelliJIDEA中配置Gradle... 目录gradle安装和环境配置1 下载GRADLE2 环境变量配置3 测试gradle4 设置gradle初始化文件5 i