前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TensorFlow学习笔记:2、TensorFlow超简单入门程序

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

作者头像
程裕强
发布2018-01-02 16:47:56
9000
发布2018-01-02 16:47:56
举报

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 演示程序

代码语言:javascript
复制
[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计算

代码语言:javascript
复制
>>> 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
>>> 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-10-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • TensorFlow学习笔记:2、TensorFlow超简单入门程序
    • 2.1 HelloWorld代码说明
      • 2.2 演示程序
        • 2.3 a+b计算
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档