【深度学习笔记】(二)Hello, Tensorflow!
2017-11-27 18:50
651 查看
【深度学习笔记】(二)Hello, Tensorflow!
一、安装
官方安装的方式很多种,本文采用Docker方式。Docker的深入使用文案很长很多,但我们都不需要,我们的主要目的还是Tensorflow,所以只需要基本的使用即可。PS:打开Tensorflow官网是需要翻墙的,所以上面的一些链接不能翻墙的情况下是打不开的,然鹅!Docker不需要翻墙就能打开,所以用Docker来安装Tensorflow就是为了绕墙而走。1、Docker安装
既然不用翻墙,首先就是点我下载安装包,打开页面看到很多开发平台的版本,选择匹配自己开发平台的包下载安装即可,安装的过程就是一直点“下一步”。。。over。安装成功后,会有两个入口:
第一个既然看不清名称就不用官他,也可以看得清也不要管他,因为我们只需要用第二个:Kitmatic,我们仅用用Kitmatic来操作Docker来提供Tensorfow的,不需要要学习第一个命令行的操作方式。
2、Kitmatic安装Tensorflow环境
点击第1步中的第二个图标启动Kitmatic;点击左上角的”NEW”按钮:进入下图,在输入框中输入Tensorflow搜索,在Docker Hub搜索中选择一个,一般是第一个,点击“CREATE”按钮下载安装。
其他Jupyter Notebook、Tensorboard都可以在这里找到下载安装。
二、Hello, Tensorflow
1、编程步骤:
定义数据定义计算图与变量
定义会话
进行计算
2、基于MNIST数据集的手写数字识别
这是很多教科书上的入门例子,但是没有说明其中代码依赖导致运行不起来。所以首先作为Tensorflow的入门例子,应该是包括在Tensorflow代码里的,先要把它clone下来:git clone https://github.com/tensorflow/tensorflow
这时候可能因为权限问题无法拉下来,先去fork一份到自己名下就行了,或者直接打包下载。
接下来就能把代码跑起来了,写一遍感受一下:
# 1、load data set from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) # 2、see data set: # train - test - validation # train data set # print(mnist.train.images.shape,mnist.train.labels.shape) # test data set # print(mnist.test.images.shape,mnist.test.labels.shape) # validation data set # print(mnist.validation.images.shape,mnist.validation.labels.shape) # 3、开启tensorflow session import tensorflow as tf sess = tf.InteractiveSession() # 4、define softmax regression # x x = tf.placeholder(tf.float32,[None,784]) # W W = tf.Variable(tf.zeros([784,10])) # b b = tf.Variable(tf.zeros(10)) # y y = tf.nn.softmax(tf.matmul(x,W) + b) # y_ y_ = tf.placeholder(tf.float32,[None,10]) # loss cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y),reduction_indices=[1])) # SGD train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) # init tf.global_variables_initializer().run() # 5、trainning starts for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) train_step.run({x:batch_xs, y_:batch_ys}) # trainning ends # correct predictiong correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1)) # accuracy accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32)) # evalue print(accuracy.eval({x:mnist.test.images,y_:mnist.test.labels}))
三、参考
https://www.tensorflow.orghttps://github.com/tensorflow/tensorflow
https://www.docker.com/
http://jupyter.org/
Tensorflow实战.黄文坚
相关文章推荐
- 【深度学习笔记】(二)Hello, Tensorflow!
- 深度学习笔记 (二) 在TensorFlow上训练一个多层卷积神经网络
- [翻译]斯坦福CS20SI:基于Tensorflow的深度学习研究课程笔记,Lecture note 1: Introduction to TensorFlow
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
- TensorFlow深度学习笔记 Stochastic Optimization
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
- TensorFlow 深度学习笔记 从线性分类器到深度神经网络
- TensorFlow深度学习笔记 从线性分类器到深度神经网络
- 深度学习笔记——深度学习框架TensorFlow(五)[TensorFlow大规模线性模型教程]
- RNN入门详解及TensorFlow源码实现--深度学习笔记
- 深度学习笔记——深度学习框架TensorFlow之MLP(十四)
- TensorFlow深度学习笔记 实现与优化深度神经网络
- TensorFlow 深度学习笔记 TensorFlow实现与优化深度神经网络
- TensorFlow 深度学习笔记 从线性分类器到深度神经网络
- 深度学习笔记——深度学习框架TensorFlow(十二)
- 学习笔记TF045:人工智能、深度学习、TensorFlow、比赛、公司
- TensorFlow 深度学习笔记 逻辑回归 实践篇
- TensorFlow 深度学习笔记 卷积神经网络
- TensorFlow笔记1:深度学习基本概念
- [翻译]斯坦福CS 20SI:基于Tensorflow的深度学习研究课程笔记,Lecture note 2: TensorFlow Ops