214 Star 1.1K Fork 951

Ascend/samples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
best_practices
common
cplusplus
docs
growthpath
inference
operator
operator_contrib
python
common
contrib
environment
level1_single_api
level2_simple_inference
0_data_process
1_classification
googlenet_imagenet_dynamic_batch
googlenet_imagenet_multi_batch
googlenet_imagenet_picture
googlenet_mindspore_picture
googlenet_onnx_picture
inceptionv3_picture
lenet_mindspore_picture
resnet50_async_imagenet_classification
resnet50_imagenet_classification
resnet50_imagenet_dynamic_hw
resnet50_mindspore_picture
data
model
src
README.md
README_CN.md
vdec_resnet50_classification
vgg16_cat_dog_picture
vpc_jpeg_resnet50_imagenet_classification
vpc_resnet50_imagenet_classification
README.md
README_CN.md
2_object_detection
3_segmentation
4_recommendation
5_nlp
6_other
n_e2e
n_performance
README.md
README_CN.md
level3_multi_model
README.md
README_CN.md
robot/ascend_car
st
training
.gitignore
CONTRIBUTING_CN.md
CONTRIBUTING_EN.md
LICENSE
NOTICE
OWNERS
README.md
build_run.sh
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

本样例为大家学习昇腾软件栈提供参考,非商业目的!

本README只提供命令行方式运行样例的指导,如需在Mindstudio下运行样例,请参考Mindstudio运行图片样例wiki

resnet50图片分类样例

功能:使用resnet50模型对输入图片进行分类推理。
样例输入:待推理的jpg图片。
样例输出:推理后的jpg图片。

训练过程参考 resnet50 mindspore训练; 在Ascend910环境, 使用本仓库下scripts/convert.py 脚本将训练好的resnet-90_1875.ckpt 转换为resnet-90_1875.air模型文件

前置条件

请检查以下条件要求是否满足,如不满足请按照备注进行相应处理。如果CANN版本升级,请同步检查第三方依赖是否需要重新安装(5.0.4及以上版本第三方依赖和5.0.4以下版本有差异,需要重新安装)。

条件 要求 备注
CANN版本 >=5.0.4 请参考CANN样例仓介绍中的安装步骤完成CANN安装,如果CANN低于要求版本请根据版本说明切换samples仓到对应CANN版本
硬件要求 Atlas200DK/Atlas300(ai1s) 当前已在Atlas200DK和Atlas300测试通过,产品说明请参考硬件平台 ,其他产品可能需要另做适配
第三方依赖 pillow, numpy, python-acllite 请参考第三方依赖安装指导(python样例)选择需要的依赖完成安装

样例准备

  1. 获取源码包。

    可以使用以下两种方式下载,请选择其中一种进行源码准备。

    • 命令行方式下载(下载时间较长,但步骤简单)。
      # 开发环境,非root用户命令行中执行以下命令下载源码仓。    
      cd ${HOME}     
      git clone https://gitee.com/ascend/samples.git
      
      注:如果需要切换到其它tag版本,以v0.5.0为例,可执行以下命令。
      git checkout v0.5.0
      
    • 压缩包方式下载(下载时间较短,但步骤稍微复杂)。
      注:如果需要下载其它版本代码,请先请根据前置条件说明进行samples仓分支切换。
       # 1. samples仓右上角选择 【克隆/下载】 下拉框并选择 【下载ZIP】。    
       # 2. 将ZIP包上传到开发环境中的普通用户家目录中,【例如:${HOME}/ascend-samples-master.zip】。     
       # 3. 开发环境中,执行以下命令,解压zip包。     
       cd ${HOME}    
       unzip ascend-samples-master.zip
      
  2. 获取此应用中所需要的原始网络模型。

    模型名称 模型说明 模型下载路径
    resnet50 图片分类推理模型。是基于MindSpore的resnet50模型。 https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/resnet50_mindspore/resnet-90_1875.air
    # 为了方便下载,在这里直接给出原始模型下载及模型转换命令,可以直接拷贝执行。也可以参照上表在modelzoo中下载并手工转换,以了解更多细节。     
    cd ${HOME}/samples/python/level2_simple_inference/1_classification/resnet50_mindspore_picture/model    
    wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/resnet50_mindspore/resnet-90_1875.air     
    atc --model=./resnet-90_1875.air --framework=1 --output=./resnet50 --soc_version=Ascend310
    
  3. 获取样例需要的测试图片。

    # 执行以下命令,进入样例的data文件夹中,下载对应的测试图片。
    cd ${HOME}/samples/python/level2_simple_inference/1_classification/resnet50_mindspore_picture/data
    wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/data/airplane.jpg
    wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/data/car.jpg
    

样例运行

注:开发环境与运行环境合一部署,请跳过步骤1,直接执行步骤2即可。

  1. 执行以下命令,将开发环境的 resnet50_mindspore_picture 目录上传到运行环境中,例如 /home/HwHiAiUser,并以HwHiAiUser(运行用户)登录运行环境(Host)。

    # 【xxx.xxx.xxx.xxx】为运行环境ip,200DK在USB连接时一般为192.168.1.2,300(ai1s)为对应的公网ip。
    scp -r ${HOME}/samples/python/level2_simple_inference/1_classification/resnet50_mindspore_picture HwHiAiUser@xxx.xxx.xxx.xxx:/home/HwHiAiUser
    ssh HwHiAiUser@xxx.xxx.xxx.xxx
    cd ${HOME}/resnet50_mindspore_picture/src
    
  2. 运行工程。

    python3.6 classify.py ../data
    

查看结果

运行完成后,会在out目录下生成带推理结果的jpg图片。

推理前:

输入图片说明

推理后:

输入图片说明

常见错误

请参考常见问题定位对遇到的错误进行排查。如果wiki中不包含,请在samples仓提issue反馈。

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ascend/samples.git
git@gitee.com:ascend/samples.git
ascend
samples
samples
master

搜索帮助