惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
IT之家
IT之家
博客园 - 聂微东
The Cloudflare Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
H
Help Net Security
博客园 - 叶小钗
V
V2EX
WordPress大学
WordPress大学
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
C
Check Point Blog
B
Blog
D
DataBreaches.Net
美团技术团队
罗磊的独立博客

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群
使用 Docker 运行 Tensorflow
微信公众号 · 2020-03-05 · via 陈少文的网站

前面写过一篇文档,如何在 CentOS 安装 GPU 驱动 ,这篇就来看看怎么利用 Docker 运行 Tensorflow 。

1. 检查当前 CPU 支持的 Tensorflow 版本

在不支持 AVX 指令的 CPU 上,运行 Tensorflow > 1.15 版本时,会报错,Illegal instruction (core dumped)

执行检测命令:

1
2
3
cat /proc/cpuinfo | grep avx

flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm constant_tsc rep_good nopl xtopology eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat

如果有查询结果,说明支持。常见的 CPU 体系结构 SandyBridge, IvyBridge, Haswell, Broadwell, Skylake, CasecadeLake 都支持 AVX 指令,除了 Westmere 。

2. GPU\CPU 模式运行

使用如下脚本查看运行环境中的设备:

1
2
from tensorflow.python.client import device_lib
device_lib.list_local_devices()

分别起两个版本的 Jupyter 。

  • GPU
1
2
mkdir ~/notebooks
docker run --name tf-gpu -d --runtime=nvidia --rm -it -v $(realpath ~/notebooks):/tf/notebooks -p 8881:8888 tensorflow/tensorflow:latest-gpu-jupyter

查看登录秘钥,返回的 token 值为登录秘钥。

1
2
3
4
5
6
7
8
9
docker exec -it tf-gpu cat /root/.local/share/jupyter/runtime/nbserver-1-open.html

<!DOCTYPE html>
<p>
    This page should redirect you to Jupyter Notebook. If it doesn't,
    <a href="http://0.0.0.0:8888/tree?token={{token}}">click here to go to Jupyter</a>.
</p>

</body>

  • CPU
1
2
mkdir ~/notebooks
docker run --name tf-cpu -d --rm -it -v $(realpath ~/notebooks):/tf/notebooks -p 8882:8888 tensorflow/tensorflow:latest-jupyter

查看登录秘钥,返回的 token 值为登录秘钥。

1
2
3
4
5
6
7
8
9
docker exec -it tf-cpu cat /root/.local/share/jupyter/runtime/nbserver-1-open.html

<!DOCTYPE html>
<p>
    This page should redirect you to Jupyter Notebook. If it doesn't,
    <a href="http://0.0.0.0:8888/tree?token={{token}}">click here to go to Jupyter</a>.
</p>

</body>

3. 参考链接