TensorFlow 笔记
TensorFlow 笔记
AllenOR灵感 发表于8个月前
TensorFlow 笔记
• 发表于 8个月前
• 阅读 3
• 收藏 0
• 评论 0

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.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)

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

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

×