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 条评论
登录 后参与评论

相关文章

来自专栏Petrichor的专栏

pytorch: tensor类型的构建与相互转换

其中,torch.Tensor、torch.rand、torch.randn 均默认生成 torch.FloatTensor型 :

1166
来自专栏简书专栏

基于tensorflow+RNN的MNIST数据集手写数字分类

tensorflow是谷歌google的深度学习框架,tensor中文叫做张量,flow叫做流。 RNN是recurrent neural network的简...

763
来自专栏深度学习之tensorflow实战篇

tensorflow(一)windows 10 python3.6安装tensorflow1.4与基本概念解读

一.安装 目前用了tensorflow、deeplearning4j两个深度学习框架, tensorflow 之前一直支持到python 3.5,目前以更...

3754
来自专栏null的专栏

数据结构和算法——用动态规划求解最短路径问题

一、动态规划求解问题的思路     在《算法导论》上,动态规划的求解过程主要分为如下的四步: 描述最优解的结构 递归定义最优解的值 按自底向上的方式计算最优解的...

3535
来自专栏人工智能LeadAI

TensorFlow官方教程翻译:导入数据

需要注意的是,如下教程的tf.data的模块需要将tensorflow升级到1.4的版本,才可以支持,低于1.4的版本的导入数据教程,见之前的翻译教程,戳这里(...

6846
来自专栏大数据学习笔记

TensorFlow学习笔记:3、TensorFlow基本概念

TensorFlow学习笔记:3、TensorFlow基本概念 3.1 计算图与operation Tensor(张量)意味着N维数组,Flow(流)意味着基于...

22210
来自专栏我和未来有约会

[Silverlight动画]转向行为 - 2D向量

转向行为已经被各种语言实现过多次了,其最底层是用向量来描述的(也是最常见的实现方式)。 概括的看,一个向量由两部分组成:一个方向和一个大小。比如,一个运动中对象...

1796
来自专栏PPV课数据科学社区

使用R语言进行异常检测

本文结合R语言,展示了异常检测的案例,主要内容如下: (1)单变量的异常检测 (2)使用LOF(local outlier factor,局部异常因子)进行异常...

2926
来自专栏hrscy

Unity 基础 - Vector3

Vector 是向量,矢量的意思,向量既有大小,又有方向,Verctor3 就是三维向量,一个三维向量会有三个分量,分别是 x,y,z,在 Unity 中每一个...

722
来自专栏机器学习算法与Python学习

Torch7基本教程2

上一篇博文Torch7深度学习教程1详细的讲述了Torch7的安装过程,本篇博文主要是讲述一下Torch7中的一些基本运算的语法,与Python的基本语法类似,...

3566

扫码关注云+社区