TensorFLow学习(一)---原生Windows安装TensorFlow,进行MNIST机器学习
2017-04-09 09:59
423 查看
2015年11月9日,Google发布人工智能系统TensorFlow并宣布开源。
【TensorFlow】是 Google 多年以来内部的机器学习系统。如今,Google 正在将此系统成为开源系统,并将此系统的参数公布给业界工程师、学者和拥有大量编程能力的技术人员。
近期开始尝试对TensorFlow进行学习,因为习惯了windows系统和anaconda、spyder的python开发环境,以下教程基于以上。主要材料来源于:TensorFlow官方文档。
https://www.continuum.io/downloads/
anaconda里面集成了很多关于python科学计算的第三方库,并且安装方便。
【2】构建tensorflow虚拟环境:conda create –name tensorflow python=3.5
【3】在虚拟环境中安装spyder:conda install -n tensorflow spyder
【4】启动虚拟环境:activate tensorflow
【5】在虚拟环境安装tensorflow包:
【TensorFlow】是 Google 多年以来内部的机器学习系统。如今,Google 正在将此系统成为开源系统,并将此系统的参数公布给业界工程师、学者和拥有大量编程能力的技术人员。
近期开始尝试对TensorFlow进行学习,因为习惯了windows系统和anaconda、spyder的python开发环境,以下教程基于以上。主要材料来源于:TensorFlow官方文档。
第一步:安装anaconda3
在官网上下载并安装Python科学计算发行版anaconda3https://www.continuum.io/downloads/
anaconda里面集成了很多关于python科学计算的第三方库,并且安装方便。
第二步:构建tensorflow虚拟环境
【1】打开cmd命令窗口【2】构建tensorflow虚拟环境:conda create –name tensorflow python=3.5
【3】在虚拟环境中安装spyder:conda install -n tensorflow spyder
【4】启动虚拟环境:activate tensorflow
【5】在虚拟环境安装tensorflow包:
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl[/code]
【6】关闭虚拟环境:deactivate tensorflow第三步:测试TensorFlow
【1】打开cmd命令窗口
【2】activate tensorflow
【3】启动python编译器:python
【4】输入以下代码,查看结果,等于32则正常import tensorflow as tf sess = tf.Session() a = tf.constant(10) b = tf.constant(22) print(sess.run(a + b)) 32第四步:
【1】MNIST数据集的官网是Yann LeCun’s website。下面提供了一份python源代码用于自动下载和安装这个数据集。将下面地址下载的py文件放在工作地址wd中
https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/examples/tutorials/mnist/input_data.py
【2】执行以下代码,查看结果:import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data", one_hot=True) #读取mnist文件 #设定参数 x = tf.placeholder(tf.float32, [None, 784]) W = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) #建立模型 y = tf.nn.softmax(tf.matmul(x,W) + b) #实际值 y_ = tf.placeholder("float", [None,1 ade0 0]) #定义cost cross_entropy = -tf.reduce_sum(y_*tf.log(y)) #设定训练算法 train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) #初始化变量 init = tf.global_variables_initializer() #启动模型 sess = tf.Session() sess.run(init) #施行训练 for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) #建立评估模型 correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) #布尔值转换成浮点数,然后取平均值 accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) #计算所学习到的模型在测试数据集上面的正确率 print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
相关文章推荐
- windows平台下人工智能平台TensorFlow安装--(学习笔记)
- TensorFlow学习笔记--安装配置-windows
- windows深度学习入门(1)在windows10上安装TensorFlow
- 【Tensorflow学习历程】1. windows 8 下的tensorflow 安装
- 进行docker 安装并搭建tensorflow 框架用于以后tensorflow 测试学习
- 【深度学习】windows下安装TensorFlow
- windows下tensorflow的安装与学习(基于anaconda的python3.5)
- 【深度学习】windows下使用anaconda安装TensorFlow
- TensorFlow学习笔记--windows系统安装配置
- [TensorFlow 学习笔记-01]Windows下TensorFlow(Only CPU)安装
- 深度学习框架TensorFlow学习(七)-----在Windows下的安装Tensorflow
- tensorflow学习记录(一):在windows下的安装
- 在windows 7下安装unbuntu16.04 虚拟机进行tensorflow 的编译安装。
- Windows驱动程序开发学习笔记(一) - 下载并安装WDK
- 从零开始MDT2010学习手记(七) 结合WDS进行新机网络部署Windows 7
- 【PHP学习笔记】Windows 下Memcache安装配置
- Windows下使用NodeJS和npm安装UglifyJS对JavaScript进行压缩或美化
- Thrift 学习笔记2——Windows环境下Thrift的安装、编译以及测试
- Solr 1.4.1学习笔记之“Windows下的安装”
- Git学习笔记一:Windows安装篇