TensorFlow 笔记
TensorFlow 笔记
AllenOR灵感 发表于6个月前
TensorFlow 笔记
  • 发表于 6个月前
  • 阅读 1
  • 收藏 0
  • 点赞 0
  • 评论 0

新睿云服务器60天免费使用,快来体验!>>>   

1.Tensorflow 数据类型

---------------------------------------------------------------
Data type (dtype)               Description
---------------------------------------------------------------

tf.float32                 32-bit floating point
tf.float64                 64-bit floating point
tf.int8                    8-bit signed integer
tf.int16                   16-bit signed integer
tf.int32                   32-bit signed integer
tf.int64                   64-bit signed integer
tf.uint8                   8-bit unsigned integer
tf.string                  String (as bytes array, not Unicode)
tf.bool                    Boolean
tf.complex64               Complex number, with 32-bit floating point real portion, and 32-bit floating point imaginary portion
tf.qint8                   8-bit signed integer (used in quantized Operations)
tf.qint32                  32-bit signed integer (used in quantized Operations)
tf.quint8                  8-bit unsigned integer (used in quantized Operations)

2.重载符号

TensorFlow重载了一些符号,使得表达更加清晰。

Unary operators

----------------------------------------------------------------------------------------
Operator               Related TensorFlow Operation    
----------------------------------------------------------------------------------------

-x                        tf.neg()                     
~x                        tf.logical_not() 
abs(x)                    tf.abs()

Binary operators

----------------------------------------------------------------------------------
Operator               Related TensorFlow Operation
-----------------------------------------------------------------------------------

x + y                            tf.add()
x - y                            tf.sub()  
x * y                            tf.mul()  
x / y                            (Python 2) tf.div()  
x / y                            (Python 3) tf.truediv()  
x // y                           (Python 3) tf.floordiv()  
x % y                            tf.mod()  
x ** y                           tf.pow()  
x < y                            tf.less()  
x <=    y                        tf.less_equal()  
x > y                            tf.greater()  
x >= y                           tf.greater_equal()  
x & y                            tf.logical_and()  
x | y                            tf.logical_or()  
x ^ y                            tf.logical_xor()

3.图和会话

# 一般我们写程序的时候,都会指定是哪个图
# 得到默认图
default_graph = tf.get_default_graph()
g = tf.Graph()

with g.as_default():
  a = tf.constant(2)
  b = tf.constant(4)
  c = tf.add(a,b)

with default_graph.as_default():
  aa = tf.constant(4)
  bb = tf.constant(8)
  cc = tf.add(aa, bb)

sess = tf.Session(graph = g)
# 这个语句是对的,因为会话里面的图是g
print(sess.run(c))
# 这个语句是错误的,因为只有图g能执行,而图default_graph不行,因为不在会话里
print(sess.run(cc))

  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 6
博文 2139
码字总数 82983
×
AllenOR灵感
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: