目录
1.Docker安装
2.拉取到本地的镜像
3.下载并运行MindSpore Lenet代码
1.Docker安装
由于Docker官网部署在国外, 可以采用通过国内的镜像下载. 这里可以使用阿里云的安装镜像.
对于10.10.3以下的用户 推荐使用Docker Toolbox
http://mirrors.aliyun.com/docker-toolbox/mac/docker-toolbox/
对于10.10.3以上的用户 推荐使用Docker for Mac
http://mirrors.aliyun.com/docker-toolbox/mac/docker-for-mac/
查看当前Docker版本信息
docker -version
2.拉取到本地的镜像
安装官方提供的CPU版本:
docker pull mindspore/mindspore-cpu:0.1.0-alpha
查看拉取到本地的镜像:
docker images
docker images显示信息如下:REPOSITORY TAG IMAGE ID CREATED SIZE
mindspore/mindspore-cpu 0.1.0-alpha ef443be923bc 3 months ago 1.05GB信息说明:REPOSITORY: 表示当前镜像的仓库
TAG:镜像标签,一般用版本标识
IMAGE ID:镜像的唯一ID
CREATED: 镜像创建时间
SIZE: 镜像大小
创建并运行容器:
docker run -it mindspore/mindspore-cpu:0.1.0-alpha
查看容器启动情况:
docker ps
3.下载并运行MindSpore Lenet代码
克隆MindSpore Lenet代码
git clone https://github.com/mindspore-ai/docs.git
也可以去gitee上去克隆,克隆成功之后进入目录找到lenet.py文件:
root@6b7fbe26908d:/# git clone https://gitee.com/mindspore/docs.git
Cloning into 'docs'...
remote: Enumerating objects: 2240, done.
remote: Counting objects: 100% (2240/2240), done.
remote: Compressing objects: 100% (210/210), done.
remote: Total 7271 (delta 2118), reused 2059 (delta 2030), pack-reused 5031
Receiving objects: 100% (7271/7271), 21.54 MiB | 525.00 KiB/s, done.
Resolving deltas: 100% (5059/5059), done.
root@6b7fbe26908d:/# ls
bin boot dev docs etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@6b7fbe26908d:/# cd docs/
root@6b7fbe26908d:/docs# ls
CONTRIBUTING_DOC.md CONTRIBUTING_DOC_CN.md LICENSE LICENSE-CC-BY-4.0 NOTICE README.md README_CN.md api docs install resource tutorials
root@6b7fbe26908d:/docs# cd tutorials/
root@6b7fbe26908d:/docs/tutorials# ls
Makefile notebook requirements.txt source_en source_zh_cn tutorial_code
root@6b7fbe26908d:/docs/tutorials# cd tutorial_code/
root@6b7fbe26908d:/docs/tutorials/tutorial_code# ls
distributed_training lenet.py model_safety resnet sample_for_cloud
root@6b7fbe26908d:/docs/tutorials/tutorial_code# vim lenet.py
196行的device_target default = "CPU"就可以跑起来:
if __name__ == "__main__":parser = argparse.ArgumentParser(description='MindSpore LeNet Example')parser.add_argument('--device_target', type=str, default="CPU", choices=['Ascend', 'GPU', 'CPU'],help='device where the code will be implemented (default: CPU)')
运行lenet.py
root@6b7fbe26908d:/docs/tutorials/tutorial_code# python lenet.py
******Downloading the MNIST dataset******
============== Starting Training ==============
epoch: 1 step: 1, loss is 2.3070438
epoch: 1 step: 2, loss is 2.3044722
epoch: 1 step: 3, loss is 2.3040059
epoch: 1 step: 4, loss is 2.3056054
epoch: 1 step: 5, loss is 2.3035357
运行结束之后提示:
epoch: 1 step: 1873, loss is 0.056840077
epoch: 1 step: 1874, loss is 0.3317723
epoch: 1 step: 1875, loss is 0.013712672
============== Starting Testing ==============
============== Accuracy:{'Accuracy': 0.9628405448717948} ==============