dense函數(shù)相當(dāng)于matmul,這個(gè)已經(jīng)經(jīng)過試驗(yàn)驗(yàn)證
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))