TensorFlow在windows10下的安装

来源:互联网 发布:哈萨克音乐bayge软件 编辑:程序博客网 时间:2024/05/17 16:56

TensorFlow,是google开发的一款神经网络的python外部的结构包,使用TensorFlow可以很快速地学习神经网络。
关于TensorFlow的安装:
下面先介绍下在Windows10系统中通过anaconda安装TensorFlow:
1、首先下载水蟒anaconda下载地址是:https://www.continuum.io/downloads/,选择python3.5版本
这里写图片描述

2、下载完成后选择安装到自己指定的目录,笔者这边安装的目录是D:\ProgramData\Anaconda3;安装完成之后需要配置一下环境变量。
打开:我的电脑->属性->高级系统设置->高级->环境变量中的PATH中修改如图所示:
这里写图片描述
需要注意的一点是:这边的分号;一定要选择英文状态下的分号!
安装完成之后打开控制台窗口,如图所示Anaconda的环境变量配置完毕。
这里写图片描述
输入命令:conda 查看conda 命令是一些基本介绍,我们看到加上create参数:Create a new conda environment from a list of specified,是创建一个conda environment的意思,在接下来安装tensorFlow的时候我们会用到。

packages.
3、下面安装TensorFlow:
首先需要解释一下目前tensorFlow尚且不支持python3.6版本,所以需要通过创建python3.5的环境来安装tensorflow。
下面是具体步骤:
在控制台窗口依次输入:

>conda create -n tensorflow python=3.5>activate tensorflow>pip install --upgrade --ignore-installed https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0-cp35-cp35m-win_amd64.whl

即可完成安装,需要补充的一点是,有时候网络不稳定会出现报错,这很正常,命令重新输入运行即可,直到装好为止。
检验如下:
打开anaconda安装自己需要的一些插件,笔者安装了前面三个,如图:
这里写图片描述
安装完成之后,选择打开spyder,输入下列测试代码:

# -*- coding: utf-8 -*-"""Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly."""import tensorflow as tfimport numpy as np# create datax_data = np.random.rand(100).astype(np.float32)y_data = x_data*0.1 + 0.3### create tensorflow structure start ###Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))biases = tf.Variable(tf.zeros([1]))y = Weights*x_data + biasesloss = tf.reduce_mean(tf.square(y-y_data))optimizer = tf.train.GradientDescentOptimizer(0.5)train = optimizer.minimize(loss)init = tf.initialize_all_variables()### create tensorflow structure end ###sess = tf.Session()sess.run(init)          # Very importantfor step in range(201):    sess.run(train)    if step % 20 == 0:        print(step, sess.run(Weights), sess.run(biases))

结果如图所示:
这里写图片描述

最近tensorFlow已经支持python3.5的pip安装安装命令如下:
Both distributions include pip. To install the CPU-only version of TensorFlow, enter the following command at a command prompt:

>python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl

To install the GPU version of TensorFlow, enter the following command at a command prompt:

>python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.0rc0-cp35-cp35m-win_amd64.whl

执行命令即可安装,效果如下:

这里写图片描述

0 0