2019-02-13:tf.layers.dense

dense函数相当于matmul,这个已经经过试验验证

import tensorflowas tf

import numpyas np

a = np.array([[1, 2], [2, 3]])

factor = np.array([[1, 1], [1, 1]])

factor_tensor = tf.convert_to_tensor(value=factor, dtype=tf.float32, name="factor_tensor")

a_tensor = tf.convert_to_tensor(value=a, dtype=tf.float32, name="a_tensor")

b = tf.layers.dense(inputs=a_tensor, units=2, kernel_initializer=tf.constant_initializer(value=1),

                    bias_initializer=tf.constant_initializer(value=2))

c = tf.matmul(a=a_tensor, b=factor_tensor, transpose_b=True)

with tf.Session()as sess:

sess.run(tf.global_variables_initializer())

print(sess.run(b))

print(sess.run(c))

你可能感兴趣的:(2019-02-13:tf.layers.dense)