您的位置:首页 > 其它

Windows上安装Tensorflow

2017-07-26 14:51 148 查看
1,TensorFlow只支持64位平台

2,下载python 3.5.X (必须是64位的),地址如下:
https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe https://www.python.org/ftp/python/3.5.2/python-3.5.2-embed-amd64.zip[/code] 
3,安装python,并验证python和pip
C:\Users\Administrator>python -V
Python 3.5.2

C:\Users\Administrator>pip3 -V
pip3 8.1.1 from d:\program files\python35\lib\site-packages (python 3.5)


4,安装TensorFlow(only cpu)
pip3 install --upgrade tensorflow


5,TensorFlow的hello world
C:\Users\Administrator>python

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow as tf
>>> hello = tf.constant('Hello tensorflow1')
>>> session = tf.Session()
>>> print(session.run(hello))

b'Hello tensorflow1'

看到输出b'Hello tensorflow1'即证明TensorFlow环境安装完成.


6,如果你是java开发的话,可能想尝试下java API,结果很让人失望,太慢了,世界末日了,代码如下,自己去享受一把:
public String tf() throws Exception{
final String value = "Hello tensorflow version :  "  + TensorFlow.version();

System.out.println(value);

//将数据转为tensor
Tensor tensor = Tensor.create(value.getBytes("UTF-8"));

//构造一个图对象
Graph graph = new Graph();
graph.opBuilder("Const","myConst").setAttr("dtype",tensor.dataType())
.setAttr("value",tensor).build();
//创建一个Session
Session session = new Session(graph);
graph.close();
//计算输出结果
Tensor result = session.runner().fetch("myConst").run().get(0);
System.out.println(result);
return new String(result.bytesValue(),"UTF-8");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: