代码之家  ›  专栏  ›  技术社区  ›  gorjan

张量流:三维张量与二维矩阵乘法

  •  0
  • gorjan  · 技术社区  · 6 年前

    当将三维张量通过密集层时,我看到了以下实现方式:

    X = np.random.rand(5,4,3).astype(np.float32)
    place = tf.placeholder(shape=[None, None, 3], dtype=tf.float32)
    dense = tf.layers.dense(place, 10)
    

    另一方面,我也看到过:

    X = np.random.rand(5,4,3).astype(np.float32)
    place = tf.placeholder(shape=[None, None, 3], dtype=tf.float32)
    place_reshape = tf.reshape(place, [tf.shape(place)[0] * tf.shape(place)[1], 3])
    dense = tf.layers.dense(place_reshape, 10)
    dense_reshape = tf.reshape(dense, [tf.shape(place)[0], tf.shape(place)[1], 10])
    

    虽然这两种方法本质上应该是相同的,但是我不能用第一种和第二种方法得到相同的结果,即使我同时设置了两个随机种子(为了可读性,我在代码片段中省略了它们)。有人能给我指一个正确的方向,以防我丢失什么东西吗?

    期待您的回答!

    0 回复  |  直到 6 年前