使用 np.tile 平铺一批图像中每个图像的 10 张图像

Using np.tile to tile 10 images of each image in a batch of images

取数组:arr = [0, 1, 2]

np.tile(arr,[10,1])
array([[0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2]])
>>> np.tile(arr,[10,2])
array([[0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2]])

与此类似,我想使用 tile 函数创建大小为 10x227x227x3 的图像批次的 10 个副本(该批次已经有 10 张图像))对于我想创建一个图块的每个图像。所以我应该得到 100x227x227x3

但是当我这样做时 M=10):

    images = np.tile(img_batch, [M, 1])

我得到的是 10x227x2270x3,images = np.tile(img_batch, [M]) 也不起作用,并带来大小为 10x227x227x30

的值

我不知道如何获得我需要的瓷砖。欢迎任何建议。

您的 img_batch 有 4 个维度。做 4 号的

np.tile(img_batch, [M, 1, 1, 1])

否则,根据 docs:

,在您的第一种情况下,它将等同于 np.tile(img_batch, [1, 1, M, 1]

If A.ndim > d, reps is promoted to A.ndim by pre-pending 1’s to it. Thus for an A of shape (2, 3, 4, 5), a reps of (2, 2) is treated as (1, 1, 2, 2).