1

I have a tensor with shape (1,4,4,1) and I want to repeat this and increase the shape to (1,28,28,1). I want to repeat it in each dimension.

karel
  • 5,489
  • 46
  • 45
  • 50
david
  • 1,255
  • 4
  • 13
  • 26

1 Answers1

1

You can use tf.tile. Here is an example with some smaller tensors:

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]]]]
tomkot
  • 926
  • 5
  • 7
  • Thank you very much. can I do this for the output of conv layer in Keras? for example, I have an Input((4,4,1)) and then I want to tile it to (28,28,1) and concatenate with the output of another layer with shape (28,28,1). is it possible? – david Feb 28 '19 at 15:01
  • I have never done this in Keras, but it seems that there is a tile function that can be used in a Lambda layer: https://stackoverflow.com/questions/53250533/how-to-use-tile-function-in-keras – tomkot Feb 28 '19 at 15:28
  • 1
    in keras I do this wtmN=Kr.layers.Lambda(K.tile,arguments={'n':(1,7,7,1)})(wtm) – david Feb 28 '19 at 20:20