import tensorflow as tf
a = tf.constant((1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0), dtype=tf.float32, shape=[4, 2], name='a')
aa = tf.reshape(a, shape=[-1, 4])
w = tf.ones(shape=[4, 2], dtype=tf.float32, name=None)
b = tf.ones(shape=[2], dtype=tf.float32, name=None)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(a))
'''
[[1. 2.]
[3. 4.]
[5. 6.]
[7. 8.]]
'''
print(sess.run(aa))
'''
[[1. 2. 3. 4.]
[5. 6. 7. 8.]]
'''
print(sess.run(w))
'''
[[1. 1.]
[1. 1.]
[1. 1.]
[1. 1.]]
'''
print(sess.run(b)) # [1. 1.]
print(b.get_shape()) # (2,) tensorflow类型数据获取数据形状
step = sess.run(tf.matmul(aa, w)+b)
print(step)
'''
[[11. 11.]
[27. 27.]]
'''
print(step.shape) # (2, 2) numpy类型数据获取数据形状
c = tf.argmax(step, axis=1)
print(sess.run(c)) # [0 0]
tensorflow查看形状XXX.get_shape()、numpy查看形状XXX.shape tf.matmul(a, w)+b详细解释(CNN全连接相关的)
最新推荐文章于 2023-03-13 12:51:32 发布