MindSporeMindInsight安装UbuntuMindSpore介绍和安装缘由 MindSpore是华为开源自研AI框架,类似于Pytorch和Tensorflow。因为任务需求,需要将代码转换为MindSpore的版本,故学习和使用。由于现在还在发展中,这个框架还存在一些问题。在安装中我就遇到了一些问题,记录下来希望对其他人有所帮助。安装MindSpore 在尝试多种安装方式后,找到了快捷方便的方式。命令如下:pipinstallupgrademindsporegpu 这个会安装最新且为GPU版本的MindSpore 如我的安装后的版本信息:mindsporegpu1。2。0cp38cp38manylinux1x8664。whl 官网给出的其他安装方式,其中pip方式我安装了没有成功,采用上述我提供的方式就会简单很多。 验证是否成功安装 由于官网给的测试代码是为了推自研的人工智能芯片Ascend,所以提供的测试代码需要修改一行,才符合我们一般的使用者。 测试代码如下:importnumpyasnpfrommindsporeimportTensorimportmindspore。opsasopsimportmindspore。contextascontextcontext。setcontext(devicetargetGPU)这里不同,改成GPU了,表示使用GPU。如果是用CPU,这里改成CPU即可xTensor(np。ones(〔1,3,3,4〕)。astype(np。float32))yTensor(np。ones(〔1,3,3,4〕)。astype(np。float32))print(ops。add(x,y)) 结果是值全为2的矩阵,矩阵shape是〔1,3,3,4〕安装MindInsightMindInsight为MindSpore提供了简单易用的调优调试能力。在训练过程中,可以将标量、张量、图像、计算图、模型超参、训练耗时等数据记录到文件中,通过MindInsight可视化页面进行查看及分析。安装MindInsight其实是为了使用MindConverter(为MindInsight的子模块)。MindConverter可以将PyTorch、TensorFlow脚本转换到MindSpore脚本的工具。安装过程中依旧遇到了很多问题,希望我的解决方案能够帮助他人。 官网给出的安装方式。其中pip方式依旧拉垮。可能是我设置不对,反正多种尝试后,均不行。后采用源码编译的方式安装。从代码仓下载源码gitclonehttps:gitee。commindsporemindinsight。git 编译和安装我采用以下方式cdmindinsightpipinstallrrequirements。txtihttps:pypi。tuna。tsinghua。edu。cnsimplepythonsetup。pyinstall 遇到的问题Cmake更新,Cmake版本过低问题pipinstallcmakeupgrade这样就安装到最新版了。npm报错,会有各种报错。经过测试发现就是版本的问题或者npm没有安装。sudoaptgetinstallnpmnpminstallgnpm4。0。0第一行是安装npm,第二行是调整npm的版本。我的MindInsight是1。2版本,经过测试npm是4。0。0就可以顺利解决了。如果依旧报npm的错,那么请调整npm的版本。修改npm4。0。0后面的版本号即可。 验证安装是否成功 执行命令:mindinsightstart 提示如下,说明安装成功:Webaddress:http:127。0。0。1:8080servicestartstate:successMindConverter初体验。 MindConverter是一款用于将PyTorch、TensorFlow脚本转换到MindSpore脚本的工具。为了方便我的代码迁移,想使用提供的工具。由于我的代码是Pytorch,就说一下我的体验和感受。 转换pytorch代码 命令如下,一次只能转换一个py文件。mindconverterinfile。mymodeltrain。pyoutput。outputreport。outputreport 只需要修改infile为你要转换的代码,output文件夹下就会出现转换后的代码。使用起来非常方便。 report用来说明转换中那些是成功那些还不对的。截取我的转换结果如下:line17:0:〔UnConvert〕fromtorch。utils。dataimportDataLoaderdidntconvert。Pleasemanualconvertthecode,alongwiththecodeassociatedwithit。line19:0:〔UnConvert〕fromtorch。autogradimportVariabledidntconvert。Pleasemanualconvertthecode,alongwiththecodeassociatedwithit。line20:0:〔Convert〕importtorch。nn。functionalasFisconvertedtoimportmindspore。ops。operationsasP。line21:0:〔UnConvert〕importtorch。autogradasautograddidntconvert。Pleasemanualconvertthecode,alongwiththecodeassociatedwithit。line22:0:〔UnConvert〕importtorch。utils。dataasdatadidntconvert。Pleasemanualconvertthecode,alongwiththecodeassociatedwithit。 其中UnConvert就是没有转换成功的。这个工具看起来非常方便,但是由于逻辑的不同很多操作还是需要手动去修改。不推荐使用这个工具作为整体的转换推荐使用这个工具转换Net部分(如几层的卷积层),对于这部分转换还是很准确的。转换PyTorch算子的工具。 原文先发布在我个人微信公众号,这里属于转载过来,原文。