【问题标题】:Tile a tensor from a smaller shape to a bigger one将张量从较小的形状平铺到较大的形状
【发布时间】:2019-07-21 23:04:38
【问题描述】:

我有一个形状为 (1,4,4,1) 的张量,我想重复此操作并将形状增加到 (1,28,28,1)。我想在每个维度上重复一遍。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    您可以使用 tf.tile。这是一个带有一些较小张量的示例:

    a = tf.constant([[[[1],[2]],[[3],[4]]]])
    print(a.shape) # (1, 2, 2, 1)
    b = tf.tile(a, [1,3,3,1])
    print(b.shape) # (1, 6, 6, 1)
    
    with tf.Session() as sess:
        print(sess.run(b))
            # [[[[1] [2] [1] [2] [1] [2]]
            #   [[3] [4] [3] [4] [3] [4]]
            #   [[1] [2] [1] [2] [1] [2]]
            #   [[3] [4] [3] [4] [3] [4]]
            #   [[1] [2] [1] [2] [1] [2]]
            #   [[3] [4] [3] [4] [3] [4]]]]
    

    【讨论】:

    • 非常感谢。我可以为 Keras 中的 conv 层的输出执行此操作吗?例如,我有一个 Input((4,4,1)),然后我想将它平铺到 (28,28,1) 并与形状为 (28,28,1) 的另一层的输出连接。有可能吗?
    • 我在Keras没做过这个,不过好像有一个可以用在Lambda层的tile函数:stackoverflow.com/questions/53250533/…
    • 在 keras 我这样做 wtmN=Kr.layers.Lambda(K.tile,arguments={'n':(1,7,7,1)})(wtm)
    猜你喜欢
    • 2016-12-12
    • 1970-01-01
    • 2019-09-01
    • 2013-04-11
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 2018-12-13
    • 2014-08-03
    相关资源
    最近更新 更多