收藏:①极市开发DeepLearning ②Git使用

Tensorflow的认识

1、基本概念(Tensorflow)

  • 使用图(graphs)来表示计算任务 n
  • 在被称之为会话(Session)的上下文(context)中执行图 n
  • 使用tensor表示数据 n
  • 通过变量(Variable)维护状态 n
  • 使用feed和fetch可以为任意的操作赋值或者从其中获取数据

 

 

  Tensorflow是一个编程系统,使用图(graphs)来表示计算任务,图(graphs)中的节点称之为op (operation),一个op获得0个或多个Tensor,执行计算,产生0个或多个Tensor。Tensor 看作是 一个 n 维的数组或列表。图必须在会话(Session)里被启动。

下面是一个简单的TF(tensorflow)程序:

 1 __author__ = "WSX"
 2 import tensorflow as tf
 3 
 4 m1 = tf.constant([[3,3]])   #创建常量OP
 5 m2 = tf.constant([[1],[1]])
 6 product = tf.matmul(m1,m2)  #创建矩阵乘法的OP
 7 
 8 print("product:",product)  #tensor类型
 9 
10 
11 #开始定义会话
12 sess = tf.Session()
13 result = sess.run(product)
14 
15 print("""
16 result:%s
17 result_type:%s
18 """%(result ,type(result)))
19 sess.close()
20 
21 # with tf.Session() as sess:
22 #     sess.run(product)

 

posted @ 2018-09-20 12:19  WSX_1994  阅读(180)  评论(0编辑  收藏  举报