TensorFlow学习笔记之疑问解答(持续更新)

1、tensorflow中一个中括号和两个中括号是什么意思?

b = tf.constant([3,3])
c = tf.constant([[3,3]])
with tf.Session() as sess:
    print(b,c)
    print(sess.run(b))
    print(sess.run(c))

返回结果:

Tensor("Const_7:0", shape=(2,), dtype=int32) Tensor("Const_8:0", shape=(1, 2), dtype=int32)
[3 3]
[[3 3]]

解答:
b是shape=(2, )的一维constant
c是shape=(1, 2)的二维constant

2、TensorFlow的fetch使用时,sess.run([这里op的顺序]),run里面op的顺序是否会有影响?

#Fech
input1 = tf.constant(3.0)
input2 = tf.constant(2.0)
input3 = tf.constant(5.0)

add = tf.add(input2,input3)
mu1 = tf.multiply(input1,add)

with tf.Session() as sess:
    result1 = sess.run([mu1,add])
    result2 = sess.run([add,mu1])
    print(result1,result2)

返回结果:[21.0, 7.0] [7.0, 21.0]
解答:
返回结果只是fetch的顺序不同,不影响结果。

3、TensorFlow中CNN的两种padding方式“SAME”和“VALID”
对于“VALID”,输出的形状计算: new_height=new_width=⌈ (W–F+1) / S ⌉
对于“SAME”,输出的形状计算: new_height=new_width=⌈ W / S ⌉
其中,W为输入的size,F为filter为size,S为步长,⌈⌉为向上取整符号。

4、Tensor 和 numpy array互转
①numpy array 到 Tensor

numpyData = np.zeros((1,10,10,3),dtype=np.float32)
tf.convert_to_tensor(numpyData)

②Tensor到 numpy array

eval()
tf.constant([1,2,3]).eval()

5、ord()函数是chr()函数(对于8位的ASCII字符串)或unichr()函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的ASCII数值,或者Unicode数值,如果所给的Unicode字符超出了你的Python定义范围,则会引发一个TypeError的异常。

猜你喜欢

转载自blog.csdn.net/zw__chen/article/details/79346496