本教程搭建集 Tensorflow、Keras、Coffe、PyTorch 等深度学习框架于一身的环境,及jupyter。
本教程使用nvidia-docker启动实例,通过本教程可以从一个全新的Ubuntu系统快速搭建出GPU深度学习环境。
文章目录
- 一、安装依赖环境
- 1. 使用国内镜像加速安装
- 2. 安装 NVIDIA GPU 驱动
- 3. 安装 Docker
- 4. 安装 Nvidia-docker
- 二、拉取镜像并启动
- 1. 拉取镜像
- 2. 启动镜像
- 三、 成功启动
- 四、其他
- 1. import tensorflow时遇到Future Warning解决方案
一、安装依赖环境
1. 使用国内镜像加速安装
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
此处默认环境:ubuntu16.04LTS
1
2
3sudo mv /etc/apt/sources.list /etc/apt/sources.list.old sudo vim /etc/apt/sources.list
然后将下面的内容写入该文件:
需要注意的是:不同版本的ubuntu镜像源不一样,可以在清华镜像源查询
1
2
3
4
5
6
7
8
9
10
11
12
13# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
使镜像源生效
1
2sudo apt-get update
2. 安装 NVIDIA GPU 驱动
1
2
3
4sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get update sudo apt-get install nvidia-384 nvidia-prime
查看是否安装成功
1
2watch nvidia-smi # 该命令可查看GPU使用情况
3. 安装 Docker
https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
以ubuntu16.04LTS为例
1
2
3
4
5
6
7
8curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install docker-ce
查看是否安装成功
1
2docker -v
4. 安装 Nvidia-docker
https://github.com/NVIDIA/nvidia-docker
1
2
3
4
5
6
7
8
9curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-docker2 sudo pkill -SIGHUP dockerd
这里的最后一步会重启docker,并载入nvidia-docker的配置
查看是否安装成功
1
2nvidia-docker -v
二、拉取镜像并启动
1. 拉取镜像
这里我们使用了deepo镜像:https://hub.docker.com/r/ufoym/deepo/
其下的 ufoym/deepo:all-py36-jupyter
,该镜像收集了大部分深度学习框架,运行在GPU环境,以及配有jupyter。
1
2docker pull ufoym/deepo:all-py36-jupyter
2. 启动镜像
默认配置
1
2nvidia-docker run -it -p 8888:8888 ufoym/deepo:all-py36-jupyter jupyter notebook --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --notebook-dir='/root'
外部挂载配置(挂载外部目录,方便移动数据)
1
2
3# 这里使用了-v选项用于挂载外部目录 nvidia-docker run -it -p 8888:8888 --ipc=host -v /data:/data ufoym/deepo:all-jupyter-py36 jupyter notebook --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --notebook-dir='/data'
博主推荐:后台运行并挂载外部目录(需要注意的地方是要把参数-it
改成-i
,否则无法运行在后台)
1
2nohup nvidia-docker run -i -p 8888:8888 --ipc=host -v /data:/data ufoym/deepo:all-jupyter-py36 jupyter notebook --no-browser --ip=0.0.0.0 --allow-root --NotebookApp.token= --notebook-dir='/data' &
参数说明
-v /data:/data
:左边是外部路径,右边是内部路径,例如我的文件放在/home/ubuntu/data
下,需要挂载到docker内部的路径是/data
,则参数配置应该是-v /home/ubuntu/data:/data
--notebook-dir
:jupyter工作目录的默认路径,推荐与上面的docker内部数据路径相同,即/data
-p 8888:8888
:左边是外部端口,右边是docker镜像端口。如果想将jupyter应用挂载在8080端口,只需修改参数-p 8080:8888
即可--NotebookApp.token
:进入jupyter的密码,这里设置的是空
三、 成功启动
四、其他
1. import tensorflow时遇到Future Warning解决方案
错误如下:
1
2
3FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`. from ._conv import register_converters as _register_converters
解决方案:
进入jupyter terminal并输入
1
2
3pip install --upgrade numpy pip install --upgrade h5py
问题解决。
最后
以上就是热心夕阳最近收集整理的关于教你如何用Docker快速搭建深度学习环境的全部内容,更多相关教你如何用Docker快速搭建深度学习环境内容请搜索靠谱客的其他文章。
发表评论 取消回复