Tensorflow简介无需多言,摘抄一段百度百科:
TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经网络算法库DistBelief [1] 。
Tensorflow拥有多层级结构,可部署于各类服务器、PC终端和网页并支持GPU和TPU高性能数值计算,被广泛应用于谷歌内部的产品开发和各领域的科学研究 [1-2] 。
TensorFlow由谷歌人工智能团队谷歌大脑(Google Brain)开发和维护,拥有包括TensorFlow Hub、TensorFlow Lite、TensorFlow Research Cloud在内的多个项目以及各类应用程序接口(Application Programming Interface, API) [2] 。自2015年11月9日起,TensorFlow依据阿帕奇授权协议(Apache 2.0 open source license)开放源代码 [2] 。
Tensorflow本身支持多种语言接口,包括Java,C++,Python和Javascript。本文将仅针对Python语言作介绍。要搭建Tensorflow的Python环境,首先需要创建一个安装了Tensorflow库的Python虚拟环境。推荐使用Anaconda(https://www.anaconda.com/distribution/)。
Anaconda
安装完成以后的界面如上所示。
在下拉列表中创建一个新的虚拟环境,在右侧的搜索框中可以选择安装相应的库,包括numpy,scipy,tensorflow,keras等
安装完成以后,打开Python的IDE如PyCharm,在Preferences -> Project Interpreter中,添加新的解释器,在Base Interpreter中选择刚才创建的anaconda的虚拟环境,这个编译器中已经包含了Tensorflow的库
下面代码用于测试:
import tensorflow as tf
a = tf.constant(2)
b = tf.constant(3)
c = tf.multiply(a, b)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
d = c.eval()
print(d)
console:
/Users/wujz/envs/tensorflow-py36/bin/python /Users/wujz/Learning/MachineLearning/TensorFlow/regression/test.py
1.12.0
6
测试成功