TensorFlow学习笔记[1]: TensorFlow安装及在Jupyter notebook中用Pythond代码并生成散列点图
2016-10-15 23:13
1186 查看
TensorFlow学习笔记[1]: TensorFlow安装及在Jupyter notebook中用Pythond代码并生成散列点图
作者:雨水/家辉,日期:2016-10-15,CSDN博客:http://blog.csdn.net/gobitan
摘要:现在不掌握点人工智能方面的技术,简单都不好意思出门了。前面写《Google人工智能平台TensorFlow介绍》的时候,对TensorFlow有了初步的认识,最近抽空进行较为深入的学习。这将是一个系列笔记,以《TensorFlow for Machine Intelligence》这本书为主线,将该书的精华摘录下来,同时做相应的练习!本文是本系列的第一篇,主要记录TensorFlow的简单安装及使用Jupyter notebook执行Python代码并生成散列图的过程。
TensorFlow基本知识
与TensorFlow类似的机器学习库还有Theano和Caffe。学习TensorFlow最好具有如下基础知识:导数,微积分,线性代数,程序知识,懂Python和C/C++更好!
DistBelief是TensorFlow的前身,后者是为了克服前者的不足而开发的,于2015年11月开源发布。目前TensorFlow被应用于自然语言处理,人工智能,计算机视觉和预测分析。
什么是Tensor? 简单地说,Tensor就是N维矩阵。TensorFlow 0.8.0版本之后才具有分布式特性。TensorFlow的API主要以Python语言提供,但实际地计算代码是由C++语言写的。TensorFlow能够运行在任何大小设备的系统平台上,这里是一个Android平台运行的例子,https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android。
NumPy is the fundamental package for scientific computing with Python
Jupyter is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
Matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
Matplotlib is a charting library that allows you to create dynamic, custom visualizations in Python.
TensorFlow安装
虽然在《Google人工智能平台TensorFlow介绍》已经介绍过安装,这里为了记录的完整性,给出一个简化版的安装过程。
#安装Jupyter Notebook
#安装matplotlib
#激活tensorflow虚拟环境
#启动 jupyter notebook
坑1:直接按照书中的命令"jupyter notebook"执行,会报socket.error: [Errno 99] Cannot assign requested address错误,就指定IP地址启动。如下:
(tensorflow)$ jupyter notebook --ip=120.25.234.39
坑2:必须以sudo启动,否则后面操作的是会报权限错误
(tensorflow)$ sudo jupyter notebook --ip=120.25.234.xx
注:120.25.234.xx是你的IP地址。
坑3:根据上面的安装,后面会报如下错误:
ImportError: No module named matplotlib.pyplot
解决办法:sudo apt-get install python-matplotlib
Juypyter notebook启动成功后会有类似如下提示:
The Jupyter Notebook is running at: http://120.25.234.XX:8888/
在Jupyter nootebook中用Python代码生成散列点图
可以通过提示的网址在浏览器里进入Jupyter nootebook。在右侧可以创建notebook,在里面可执行如下代码片段:
代码片段,可直接在Jupyter中执行,结果就是一些点散列图
在文档中生成可视化的散列点图,如下所示:
![](https://oscdn.geek-share.com/Uploads/Images/Content/201610/15/31f1b3dcf92e9cc6b6d3ea72baa025f5)
注:本文中提到的《TensorFlow for Machine Intelligence》的英文pdf版已上传到CSDN资源,地址为:http://download.csdn.net/detail/gobitan/9654931
参考资料:
[1] <TensorFlow for Machine Intelligence> A Hands-On Introduction to Learning Algorithms Bleeding Edge Press 2016
[2] http://blog.csdn.net/gobitan/article/details/51712207 Google人工智能平台TensorFlow介绍
作者:雨水/家辉,日期:2016-10-15,CSDN博客:http://blog.csdn.net/gobitan
摘要:现在不掌握点人工智能方面的技术,简单都不好意思出门了。前面写《Google人工智能平台TensorFlow介绍》的时候,对TensorFlow有了初步的认识,最近抽空进行较为深入的学习。这将是一个系列笔记,以《TensorFlow for Machine Intelligence》这本书为主线,将该书的精华摘录下来,同时做相应的练习!本文是本系列的第一篇,主要记录TensorFlow的简单安装及使用Jupyter notebook执行Python代码并生成散列图的过程。
TensorFlow基本知识
与TensorFlow类似的机器学习库还有Theano和Caffe。学习TensorFlow最好具有如下基础知识:导数,微积分,线性代数,程序知识,懂Python和C/C++更好!
DistBelief是TensorFlow的前身,后者是为了克服前者的不足而开发的,于2015年11月开源发布。目前TensorFlow被应用于自然语言处理,人工智能,计算机视觉和预测分析。
什么是Tensor? 简单地说,Tensor就是N维矩阵。TensorFlow 0.8.0版本之后才具有分布式特性。TensorFlow的API主要以Python语言提供,但实际地计算代码是由C++语言写的。TensorFlow能够运行在任何大小设备的系统平台上,这里是一个Android平台运行的例子,https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android。
NumPy is the fundamental package for scientific computing with Python
Jupyter is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
Matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms.
Matplotlib is a charting library that allows you to create dynamic, custom visualizations in Python.
TensorFlow安装
虽然在《Google人工智能平台TensorFlow介绍》已经介绍过安装,这里为了记录的完整性,给出一个简化版的安装过程。
$ sudo apt-get install python-pip python-dev python-virtualenv $ virtualenv --system-site-packages ~/tensorflow $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0rc0-cp27-no ne-linux_x86_64.whl $ sudo pip install --upgrade $TF_BINARY_URL
#安装Jupyter Notebook
$ sudo python2 -m pip install ipykernel $ sudo python2 -m ipykernel install $ sudo apt-get install build-essential $ sudo pip install jupyter
#安装matplotlib
$ sudo apt-get build-dep python-matplotlib python-tk
#激活tensorflow虚拟环境
$ source tensorflow/bin/activate #如下这步必不可少(书中没有),否则会报ImportError: No module named matplotlib.pyplot $ sudo apt-get install python-matplotlib (tensorflow)$ mkdir tf-notebooks (tensorflow)$ cd tf-notebooks
#启动 jupyter notebook
(tensorflow)$ jupyter notebook
坑1:直接按照书中的命令"jupyter notebook"执行,会报socket.error: [Errno 99] Cannot assign requested address错误,就指定IP地址启动。如下:
(tensorflow)$ jupyter notebook --ip=120.25.234.39
坑2:必须以sudo启动,否则后面操作的是会报权限错误
(tensorflow)$ sudo jupyter notebook --ip=120.25.234.xx
注:120.25.234.xx是你的IP地址。
坑3:根据上面的安装,后面会报如下错误:
ImportError: No module named matplotlib.pyplot
解决办法:sudo apt-get install python-matplotlib
Juypyter notebook启动成功后会有类似如下提示:
The Jupyter Notebook is running at: http://120.25.234.XX:8888/
在Jupyter nootebook中用Python代码生成散列点图
可以通过提示的网址在浏览器里进入Jupyter nootebook。在右侧可以创建notebook,在里面可执行如下代码片段:
代码片段,可直接在Jupyter中执行,结果就是一些点散列图
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt #表示直接在浏览器中显示matplotlib图表 %matplotlib inline a = tf.random_normal([2,20]) #定义2x20的随机数矩阵 sess = tf.Session() #启动一个tensorflow会话 out = sess.run(a) # 用在sess会话里执行a,结果放out里 x, y = out plt.scatter(x, y) #用pyplot创建一系列散列点,坐标为x和y plt.show()
在文档中生成可视化的散列点图,如下所示:
注:本文中提到的《TensorFlow for Machine Intelligence》的英文pdf版已上传到CSDN资源,地址为:http://download.csdn.net/detail/gobitan/9654931
参考资料:
[1] <TensorFlow for Machine Intelligence> A Hands-On Introduction to Learning Algorithms Bleeding Edge Press 2016
[2] http://blog.csdn.net/gobitan/article/details/51712207 Google人工智能平台TensorFlow介绍
相关文章推荐
- Python开发笔记之一——安装Jupyter Notebook
- 学习Python的做笔记神器——Jupyter Notebook
- 基于Python安装TensorFlow、库安装和Jupyter Notebook
- ubuntu系统下安装anaconda2并配置tensorflow环境及jupyter notebook工具远程登陆来开发用于深度学习环境
- TensorFlow学习笔记8——python代码格式化工具yapf的安装及使用
- Jupyter Notebook通过pip安装python模块
- TensorFlow学习笔记7——Win7下Spyder运行python代码出现UnicodeEncodeError问题的解决
- Python安装 Anaconda 以及jupyter notebook配置
- Python,Jupyter Notebook,IPython快速安装教程
- 在Jupyter Notebook里面写Python代码和数学公式
- 在Jupyter notebook和spyder上用python做数据挖掘,安装使用简介和常见错误
- Python Jupyter Notebook 中的错误异常与代码调试
- python︱Anaconda安装、简介(安装报错问题解决、Jupyter Notebook)
- Mac下安装python以及jupyter notebook
- windows安装python,jupyter notebook
- 在jupyter notebook中同时安装python2和python3
- Python,Jupyter Notebook,IPython快速安装教程
- jupyter notebook 安装多个版本kernel(python2 和python3)
- 跟我一起学python第二讲 开发工具Jupyter Notebook安装和远程访问设置
- Python2.7版本下安装jupyter notebook