TensorFlow学习笔记:2、TensorFlow超简单入门程序

TensorFlow学习笔记:2、TensorFlow超简单入门程序

2.1 HelloWorld代码说明

  • import tensorflow as tf 加载TensorFlow模块
  • hello=tf.constant(“Hello,TensorFlow!”) 定义计算图(此处定义一个常量)
  • session=tf.Session() 获取TensorFlow的session
  • print(session.run(hello)) 通过session,执行计算图

2.2 演示程序

[root@node1 ~]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> hello=tf.constant("Hello,TensorFlow!")
>>> session=tf.Session()
2017-10-14 23:26:49.914154: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 23:26:49.914260: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 23:26:49.914274: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 23:26:49.914284: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print(session.run(hello))
Hello,TensorFlow!
>>> 

2.3 a+b计算

>>> import tensorflow as tf
>>> session=tf.Session()
2017-10-14 11:23:01.914540: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 11:23:01.914572: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 11:23:01.914582: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-10-14 11:23:01.914592: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> x=tf.constant(5)
>>> y=tf.constant(7)
>>> print(session.run(x+y))
12
>>> 

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏吕晟的专栏

机器学习库初探之MXnet

与其他工具相比,MXnet 结合了符号语言和过程语言的编程模型,并试图最大化各自优势,利用统一的执行引擎进行自动多 GPU 并行调度优化。不同的编程模型有各自的...

3821
来自专栏计算机视觉与深度学习基础

Leetcode 130 Surrounded Regions

Given a 2D board containing 'X' and 'O' (the letter O), capture all regions su...

1695
来自专栏量子位

PyTorch 0.2发布:更多NumPy特性,高阶梯度、分布式训练等

李林 编译整理 量子位 报道 | 公众号 QbitAI Facebook的机器学习框架(之一)PyTorch今天发布了新版本:0.2.0。 这一版本引入了Num...

34515
来自专栏应兆康的专栏

100个Numpy练习【5】

翻译:YingJoy 网址: https://www.yingjoy.cn/ 来源: https://github.com/rougier/numpy-100...

49912
来自专栏数据结构与算法

1082 线段树练习 3 区间查询与区间修改

1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description ...

2565
来自专栏大数据挖掘DT机器学习

利用pandas+python制作100G亚马逊用户评论数据词云

我们手里面有一个差不多100G的亚马逊用户在购买商品后留下的评论数据(数据格式为json)。我们需要统计这100G数据中,出现频率最高的100个词语。然后制作一...

2072
来自专栏简书专栏

基于xgboost的风力发电机叶片结冰分类预测

xgboost中文叫做极致梯度提升模型,官方文档链接:https://xgboost.readthedocs.io/en/latest/tutorials/mo...

441
来自专栏数据结构与算法

Day3晚笔记

DEV C++扩展栈空间 ? -Wl,--stack=64000000000 带权二分图匹配 建一个超级源点S,超级汇点T 把左边的点的点权作为权值,连一条S到...

2904
来自专栏AI科技评论

开发 | 用PyTorch还是TensorFlow?斯坦福大学CS博士生带来全面解答

AI 科技评论按:关于深度学习的框架之争一直没有停止过。PyTorch,TensorFlow,Caffe还是Keras ?近日, 斯坦福大学计算机科学博士生Aw...

3396
来自专栏素质云笔记

keras系列︱keras是如何指定显卡且限制显存用量

keras在使用GPU的时候有个特点,就是默认全部占满显存。 若单核GPU也无所谓,若是服务器GPU较多,性能较好,全部占满就太浪费了。 于是乎有以下三...

3369

扫码关注云+社区