码迷,mamicode.com
首页 > 其他好文 > 详细

TensorFlow(1):使用docker镜像搭建TensorFlow环境

时间:2018-03-26 21:30:49      阅读:588      评论:0      收藏:0      [点我收藏+]

标签:word   down   手册   add   book   界面   opera   编辑   大数   

欢迎关注大数据和人工智能技术文章发布的微信公众号:清研学堂,在这里你可以学到夜白(作者笔名)精心整理的笔记,让我们每天进步一点点,让优秀成为一种习惯!

1,关于TensorFlow


TensorFlow 随着AlphaGo的胜利也火了起来。 
google又一次成为大家膜拜的大神了。google大神在引导这机器学习的方向。 
同时docker 也是一个非常好的工具,大大的方便了开发环境的构建,之前需要配置安装。 
看各种文档,现在只要一个 pull 一个 run 就可以把环境弄好了。 
同时如果有写地方需要个性化定制,直接在docker的镜像上面再加一层补丁就好了。 
自己的需求就能满足了,同时还可以将这个通用的方法分享出去。

2,下载TensorFlow images


使用hub.docker.com的镜像

docker pull tensorflow/tensorflow:latest

使用daocloud 的镜像,在国内用速度还是挺快的,如果docker.io的镜像慢,可以用daocloud的。 
这个速度非常的快。一样用的。版本也挺新的。

docker pull daocloud.io/daocloud/tensorflow:latest 

3,启动镜像


启动命令,设置端口,同时配置volume 数据卷,用于永久保存数据。加上 –rm 在停止的时候删除镜像。

sudo mkdir -p /data/tensorflow/notebooks
docker run -it --rm --name myts -v /data/tensorflow/notebooks:/notebooks -p 8888:8888 daocloud.io/daocloud/tensorflow:latest

启动的时候并不是daemon 模式的,而是前台模式,同时显示了运行的日志。

W 06:48:13.425 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 06:48:13.432 NotebookApp] Serving notebooks from local directory: /notebooks
[I 06:48:13.432 NotebookApp] 0 active kernels 
[I 06:48:13.432 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=2031705799dc7a5d58bc51b1f406d8771f0fdf3086b95642
[I 06:48:13.433 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 06:48:13.433 NotebookApp] 

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8888/?token=2031705799dc7a5d58bc51b1f406d8771f0fdf3086b95642

打开浏览器就可以直接看到界面了。 
技术分享图片

同时可以编辑内容: 
技术分享图片

写第一个 hello world: 
技术分享图片

import tensorflow as tf
a = tf.constant(10)
b = tf.constant(32)

with tf.Session():
    c = tf.add(a,b)
    print(c)
    print(c.eval())

其他的使用参考中文手册: 
https://github.com/jikexueyuanwiki/tensorflow-zh 
里面有pdf 可以下载使用。

还有一个超级炫酷吊炸天的playground : 
http://playground.tensorflow.org/ 
技术分享图片

5,打个补丁


vi run_jupyter.sh

#!/usr/bin/env bash
jupyter notebook --no-browser --NotebookApp.token=‘token1234‘ > /notebooks/jupyter-notebook.log 

然后重新打一个docker镜像。 
vi Dockerfile

FROM daocloud.io/daocloud/tensorflow:latest
RUN rm -f /run_jupyter.sh
COPY run_jupyter.sh /run_jupyter.sh
ENTRYPOINT ["/run_jupyter.sh"]

这样就固定token了。

docker build -t mytf:1.0 .
docker run -it --rm --name myts -v /data/tensorflow/notebooks:/notebooks -p 8888:8888 -d mytf:1.0

技术分享图片

然后就可以 -d 参数,将docker 运行放到后台。然后就可以使用 docker exec -it xxx bash 登录进去查看系统的状况了。

4,总结


本文的原文连接是: http://blog.csdn.net/freewebsys/article/details/70237003 未经博主允许不得转载。 
博主地址是:http://blog.csdn.net/freewebsys

docker 真的是非常好的技术,能够快速的搭建好环境,省去了繁琐的安装配置过程。 
最后使用参数将环境跑起来,同时也可以根据自己的需求,给镜像增加新的功能,就像是盖房子。 
一层一层的盖。所有的层,构成了一个整体的房子。 
同时对于 TensorFlow 来说是一个程序员必须的技能了。就像是 lucence一样,其实大家都不太了解那个索引算法的。 
但是还是可以创建出一个索引分词来。 
TensorFlow 也是一样的。当做一个工具来使用就好了,具体的算法也不太精通。 
有一个说法,数据量上去了,用大数据优化,比算法优化要效果好。

 

TensorFlow(1):使用docker镜像搭建TensorFlow环境

标签:word   down   手册   add   book   界面   opera   编辑   大数   

原文地址:https://www.cnblogs.com/lijinze-tsinghua/p/8653811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!