1 TensorFlow
TensorFlow是一个使用数据流图(data flow graphs)进行数值计算的的开源软件库。图的节点代表数学计 算,图的边代表与之对应的多维数组(tensor)。这个思路正好与我设计的一个系统相反。tf灵活的架构使你用 单一API就能在台式机、服务器或移动设备上的多个CPU/GPU上进行计算。虽然tf最初是由Google的机器智 能研究机构 Google Brain Team 项目的研究人员和工程师为机器学习和深度神经网络为研究目标开发的,但该 系统可以很好用于广泛的领域。
2 R中调用tensorflow
R语言包tensorflow提供的对完整tensorflow API的访问。
R语言中的tensorflow package是通过tf的一个Python modules集合来构建和执行tensorflow graphs的。
使用tensorflow需要理解: • 用graphs来表示计算 • 对图的执行是在Session中 • 用tensors来表示数据 • 状态存储在Variables • 通过feeds和fetchs实现输入输出
3 在GNU/Linux上安装
假设已经安装了R和Python。 安装tensorflow,在shell里执行(我不懂python): pip install --upgrade pip pip install tensorflow 在R中安装tensorflow: install.packages("tensorflow", repos = "http://cran.rstudio.com/")
4 简单的例子
更多例子可以看Github
library(tensorflow) sess = tf$Session() hello <- tf$constant("Hello, TensorFlow!") sess$run(hello) a <- tf$constant(10L) b <- tf$constant(32L) sess$run(a + b) sess$close()
5 参考 https://rstudio.github.io/tensorflow/